Search in sources :

Example 46 with SignedTransaction

use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.

the class RepositoryFactoryConfigurationExamplesIntegrationTest method appDoSomeStuff.

public void appDoSomeStuff(RepositoryFactory repositoryFactory) throws ExecutionException, InterruptedException {
    // The application logic is exactly the same regardless of how the repository
    // factory was
    // set
    // Note: if rest is used, these values are cached form rest
    Currency currency = repositoryFactory.getNetworkCurrency().toFuture().get();
    String generationHash = repositoryFactory.getGenerationHash().toFuture().get();
    NetworkType networkType = repositoryFactory.getNetworkType().toFuture().get();
    Account sender = Account.generateNewAccount(networkType);
    Account recipient = Account.generateNewAccount(networkType);
    Duration epochAdjustment = repositoryFactory.getEpochAdjustment().toFuture().get();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, Deadline.create(epochAdjustment), recipient.getAddress(), Collections.singletonList(currency.createRelative(BigInteger.TEN))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = transferTransaction.signWith(sender, generationHash);
// Announce or store somewhere....
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Currency(io.nem.symbol.sdk.model.mosaic.Currency) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction)

Example 47 with SignedTransaction

use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.

the class MultisigAccountOperationsIntegrationTest method cosignatureTransactionOnSign.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void cosignatureTransactionOnSign(RepositoryType type) {
    Account multisigAccount = helper().getMultisigAccount(type).getLeft();
    Account cosignatoryAccount = config().getCosignatoryAccount();
    Address recipient = getRecipient();
    TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
    SignedTransaction signedTransaction = cosignatoryAccount.sign(aggregateTransaction, getGenerationHash());
    TransactionFactory<HashLockTransaction> hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), signedTransaction).maxFee(maxFee);
    SignedTransaction signedHashLockTransaction = hashLockTransaction.build().signWith(cosignatoryAccount, getGenerationHash());
    AggregateTransaction finalTransaction = getTransactionOrFail(getTransactionService(type).announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedTransaction), aggregateTransaction);
    Assertions.assertNotNull(finalTransaction);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 48 with SignedTransaction

use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.

the class TransactionServiceTest method announceAggregateBonded.

@Test
void announceAggregateBonded() throws ExecutionException, InterruptedException {
    TransferTransaction transaction1 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message")).signer(account.getPublicAccount()).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.create(TransactionType.AGGREGATE_BONDED, networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transaction1), Collections.emptyList()).build();
    String generationHash = "abc";
    SignedTransaction aggregateSignedTransaction = aggregateTransaction.signWith(account, generationHash);
    TransactionAnnounceResponse aggregateTransactionAnnounceResponse = new TransactionAnnounceResponse("Aggregate Some Message");
    Mockito.when(transactionRepositoryMock.announceAggregateBonded(Mockito.eq(aggregateSignedTransaction))).thenReturn(Observable.just(aggregateTransactionAnnounceResponse));
    Mockito.when(listener.aggregateBondedAddedOrError(Mockito.eq(account.getAddress()), Mockito.eq(aggregateSignedTransaction.getHash()))).thenReturn(Observable.just(aggregateTransaction));
    Observable<AggregateTransaction> announcedTransaction = service.announceAggregateBonded(listener, aggregateSignedTransaction);
    Assertions.assertEquals(aggregateTransaction, announcedTransaction.toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 49 with SignedTransaction

use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatuTrueMultipleNormalAccount.

/*
   * ACT Alice: account1 Bob: account4 An escrow contract is signed by all the participants
   * (normal accounts) Given Alice defined the following escrow contract: | sender | recipient |
   * type | data | | Alice | Bob | send-an-asset | 1 concert.ticket | | Bob | Alice |
   * send-an-asset | 20 euros | And Bob signs the contract And Alice signs the contract Then the
   * contract should appear as complete
   */
@Test
void shouldReturnCorrectIsCompleteStatuTrueMultipleNormalAccount() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account1.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    TransferTransaction transferTransaction2 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account4.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction.toAggregate(account4.getPublicAccount()), transferTransaction2.toAggregate(account1.getPublicAccount()))).build();
    SignedTransaction signedTransaction1 = aggregateTransaction.signWith(account1, generationHash);
    Assertions.assertFalse(service.isComplete(signedTransaction1).toFuture().get());
    SignedTransaction signedTransaction2 = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account4), generationHash);
    Assertions.assertTrue(service.isComplete(signedTransaction2).toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 50 with SignedTransaction

use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.

the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusTRUEMultisigSingleLevel.

/*
   * ACT - Multisig single level Alice (account1): initiate an transfer to Bob Bob (multisig3): is
   * a 2/2 multisig account (account2 && account3)
   */
@Test
void shouldReturnCorrectIsCompleteStatusTRUEMultisigSingleLevel() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account4.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTransaction.toAggregate(multisig3.getPublicAccount()))).build();
    SignedTransaction signedTransactionNoCosignatures = account2.sign(aggregateTransaction, generationHash);
    SignedTransaction signedTransaction1 = account2.signTransactionGivenSignatures(aggregateTransaction, Collections.singletonList(account3.signCosignatureTransaction(signedTransactionNoCosignatures.getHash())), generationHash);
    SignedTransaction signedTransaction2 = account2.signTransactionWithCosignatories(aggregateTransaction, Collections.singletonList(account3), generationHash);
    Assertions.assertEquals(signedTransaction1.getPayload(), signedTransaction2.getPayload());
    Assertions.assertEquals(signedTransaction1.getHash(), signedTransaction2.getHash());
    Assertions.assertEquals(signedTransaction1.getSigner(), signedTransaction2.getSigner());
    Assertions.assertEquals(signedTransaction1.getType(), signedTransaction2.getType());
    Assertions.assertTrue(service.isComplete(signedTransaction1).toFuture().get());
    Assertions.assertTrue(service.isComplete(signedTransaction2).toFuture().get());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)57 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)40 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)40 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)31 Test (org.junit.jupiter.api.Test)24 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)21 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)20 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 EnumSource (org.junit.jupiter.params.provider.EnumSource)20 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)18 Account (io.nem.symbol.sdk.model.account.Account)17 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)16 Listener (io.nem.symbol.sdk.api.Listener)12 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)12 BigInteger (java.math.BigInteger)11 Address (io.nem.symbol.sdk.model.account.Address)10 TransactionService (io.nem.symbol.sdk.api.TransactionService)8 AggregateTransactionService (io.nem.symbol.sdk.api.AggregateTransactionService)7 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)7 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)6