Search in sources :

Example 1 with SignedTransaction

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

the class TransactionServiceTest method announce.

@Test
void announce() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), Address.generateRandom(networkType), Collections.emptyList()).build();
    SignedTransaction signedTransaction = transferTransaction.signWith(account, "abc");
    TransactionAnnounceResponse transactionAnnounceResponse = new TransactionAnnounceResponse("Some Message");
    Mockito.when(transactionRepositoryMock.announce(Mockito.eq(signedTransaction))).thenReturn(Observable.just(transactionAnnounceResponse));
    Mockito.when(listener.confirmedOrError(Mockito.eq(account.getAddress()), Mockito.eq(signedTransaction.getHash()))).thenReturn(Observable.just(transferTransaction));
    Observable<Transaction> announcedTransaction = service.announce(listener, signedTransaction);
    Assertions.assertEquals(transferTransaction, announcedTransaction.toFuture().get());
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) MosaicAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 2 with SignedTransaction

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

the class AccountTest method shouldSignTransaction.

@Test
void shouldSignTransaction() {
    Account account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", NetworkType.MIJIN_TEST);
    TransferTransaction transferTransaction = TransferTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", NetworkType.MIJIN_TEST), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
    SignedTransaction signedTransaction = account.sign(transferTransaction, generationHash);
    String payload = signedTransaction.getPayload();
    assertEquals("B10000000000000013193EF4F0D94DE26249D196A0575944877D5572CE13B80E4E8380FA34F9F54FF936F96162473857546F7B624A6248D8F7B3D0142DC85BBB06EB7BFEE125880B2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000", payload);
    assertEquals("58D649ABF9A26AFB3F070E26F157920DAB6423415B4344108B93EDD80DE330E5", signedTransaction.getHash());
}
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) BigInteger(java.math.BigInteger) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 3 with SignedTransaction

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

the class VertxAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.

@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
    Address address = Address.generateRandom(networkType);
    TransferTransaction transferTx = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
    AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", networkType)))).build();
    Account cosignatoryAccount = Account.generateNewAccount(this.networkType);
    Account cosignatoryAccount2 = Account.generateNewAccount(this.networkType);
    Account cosignatoryAccount3 = Account.generateNewAccount(this.networkType);
    SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2, cosignatoryAccount3), generationHash);
    BinarySerialization serialization = BinarySerializationImpl.INSTANCE;
    AggregateTransaction deserialized = (AggregateTransaction) serialization.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    Assertions.assertEquals(2, deserialized.getCosignatures().size());
    Assertions.assertEquals(cosignatoryAccount2.getPublicAccount(), deserialized.getCosignatures().get(0).getSigner());
    Assertions.assertEquals(cosignatoryAccount3.getPublicAccount(), deserialized.getCosignatures().get(1).getSigner());
}
Also used : BinarySerialization(io.nem.symbol.sdk.api.BinarySerialization) Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with SignedTransaction

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

the class MultisignIntegrationTest method shouldReturnCosignatureAddedViaListener2.

@Disabled
@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnCosignatureAddedViaListener2(RepositoryType type) {
    Listener listener = getListener(type);
    RepositoryFactory repositoryFactory = getRepositoryFactory(type);
    TransactionRepository transactionRepository = repositoryFactory.createTransactionRepository();
    SignedTransaction signedAggregatedTx = createSignedAggregatedBondTransaction(multisigAccount, cosignAccount1, account2.getAddress());
    Object finalObject = get(createHashLockTransactionAndAnnounce(type, signedAggregatedTx, cosignAccount1).flatMap(t -> {
        System.out.println("hash lock finished");
        TransactionServiceImpl transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
        return transactionService.announceAggregateBonded(listener, signedAggregatedTx).flatMap(a -> {
            System.out.println("Aggregate bonded finished");
            return repositoryFactory.createTransactionRepository().search(new TransactionSearchCriteria(TransactionGroup.PARTIAL).signerPublicKey(cosignAccount1.getPublicAccount().getPublicKey())).flatMap((page) -> {
                List<Transaction> transactions = page.getData();
                System.out.println("partialTransactions " + transactions.size());
                AggregateTransaction transactionToCosign = (AggregateTransaction) transactions.get(0);
                CosignatureTransaction cosignatureTransaction = CosignatureTransaction.create(transactionToCosign);
                CosignatureSignedTransaction cosignatureSignedTransaction = cosignAccount2.signCosignatureTransaction(cosignatureTransaction);
                return transactionRepository.announceAggregateBondedCosignature(cosignatureSignedTransaction).flatMap(r -> {
                    System.out.println("announceAggregateBondedCosignature " + r);
                    return listener.cosignatureAdded(cosignAccount1.getAddress());
                });
            });
        });
    }));
    System.out.println(finalObject.getClass());
    Assertions.assertNull(finalObject);
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) Account(io.nem.symbol.sdk.model.account.Account) EnumSource(org.junit.jupiter.params.provider.EnumSource) Disabled(org.junit.jupiter.api.Disabled) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) TestInstance(org.junit.jupiter.api.TestInstance) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Listener(io.nem.symbol.sdk.api.Listener) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) MultisigAccountModificationTransactionFactory(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransactionFactory) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions(org.junit.jupiter.api.Assertions) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Listener(io.nem.symbol.sdk.api.Listener) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) List(java.util.List) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Disabled(org.junit.jupiter.api.Disabled)

Example 5 with SignedTransaction

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

the class MultisignIntegrationTest method createHashLockTransactionAndAnnounce.

private Observable<Transaction> createHashLockTransactionAndAnnounce(RepositoryType type, SignedTransaction signedAggregatedTransaction, Account signer) {
    HashLockTransaction hasLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(10000), signedAggregatedTransaction).maxFee(maxFee).build();
    SignedTransaction signedLockFundsTransaction = signer.sign(hasLockTransaction, getGenerationHash());
    TransactionServiceImpl transactionService = new TransactionServiceImpl(getRepositoryFactory(type));
    return transactionService.announce(getListener(type), signedLockFundsTransaction);
}
Also used : HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

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