Search in sources :

Example 26 with Transaction

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

the class TransactionRepositoryIntegrationTest method getTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void getTransaction(RepositoryType type) {
    Transaction transaction = get(getTransactionRepository(type).getTransaction(TransactionGroup.CONFIRMED, transactionHash));
    assertEquals(TransactionType.TRANSFER, transaction.getType());
    assertEquals(transactionHash, transaction.getTransactionInfo().get().getHash().get());
}
Also used : TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 27 with Transaction

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

the class ListenerIntegrationTest method shouldReturnConfirmedTransactionAddressSignerViaListener.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnConfirmedTransactionAddressSignerViaListener(RepositoryType type) {
    Listener listener = getListener(type);
    SignedTransaction signedTransaction = this.announceStandaloneTransferTransaction(type, this.getRecipient());
    Observable<Transaction> confirmed = listener.confirmed(this.account.getAddress(), signedTransaction.getHash());
    Transaction transaction = get(confirmed.take(1));
    assertEquals(signedTransaction.getHash(), transaction.getTransactionInfo().get().getHash().get());
}
Also used : Listener(io.nem.symbol.sdk.api.Listener) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) 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)

Example 28 with Transaction

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

the class AggregateTransactionServiceImpl method isComplete.

@Override
public Observable<Boolean> isComplete(SignedTransaction signedTransaction) {
    Validate.notNull(signedTransaction, "signedTransaction is required");
    Validate.isTrue(signedTransaction.getType() == TransactionType.AGGREGATE_COMPLETE, "signedTransaction type must be AGGREGATE_COMPLETE");
    AggregateTransaction transaction = (AggregateTransaction) BinarySerializationImpl.INSTANCE.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    /*
     * Include both initiator & cosigners
     */
    Set<Address> signers = transaction.getCosignatures().stream().map(AggregateTransactionCosignature::getSigner).map(PublicAccount::getAddress).collect(Collectors.toSet());
    signers.add(signedTransaction.getSigner().getAddress());
    return Observable.fromIterable(transaction.getInnerTransactions()).flatMap(innerTransaction -> multisigRepository.getMultisigAccountInfo(innerTransaction.getSigner().orElseThrow(IllegalArgumentException::new).getAddress()).flatMap(multisigAccountInfo -> multisigAccountInfo.getMinRemoval() != 0 && multisigAccountInfo.getMinApproval() != 0 ? multisigRepository.getMultisigAccountGraphInfo(multisigAccountInfo.getAccountAddress()).map(graphInfo -> validateCosignatories(graphInfo, signers, innerTransaction)) : Observable.just(signers.stream().anyMatch(s -> s.equals(multisigAccountInfo.getAccountAddress()))))).all(v -> v).toObservable();
}
Also used : MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) Set(java.util.Set) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Collectors(java.util.stream.Collectors) MultisigAccountGraphInfo(io.nem.symbol.sdk.model.account.MultisigAccountGraphInfo) HashSet(java.util.HashSet) List(java.util.List) Stream(java.util.stream.Stream) Validate(org.apache.commons.lang3.Validate) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TreeMap(java.util.TreeMap) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Map(java.util.Map) NetworkRepository(io.nem.symbol.sdk.api.NetworkRepository) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) Observable(io.reactivex.Observable) Address(io.nem.symbol.sdk.model.account.Address) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AggregateTransactionService(io.nem.symbol.sdk.api.AggregateTransactionService) Address(io.nem.symbol.sdk.model.account.Address) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction)

Example 29 with Transaction

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

the class ListenerOkHttpTest method confirmAndGetError.

@Test
public void confirmAndGetError() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    String channelName = ListenerChannel.CONFIRMED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    listener.confirmed(address).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 30 with Transaction

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

the class ListenerOkHttpTest method aggregateBondedAddedHash.

@Test
public void aggregateBondedAddedHash() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, JsonObject.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), networkType);
    String channelName = ListenerChannel.AGGREGATE_BONDED_ADDED.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    listener.aggregateBondedAddedOrError(address, getHash(transactionInfo)).doOnError(exceptions::add).forEach(transactions::add);
    String topic = channelName + "/" + address.plain();
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, topic)));
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
    handle(transactionInfoDtoJsonObject, topic);
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Aggregations

Transaction (io.nem.symbol.sdk.model.transaction.Transaction)125 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)107 Test (org.junit.jupiter.api.Test)78 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)70 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)65 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)60 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)58 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)58 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)57 MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)57 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)57 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)55 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)55 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)55 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)55 SecretProofTransaction (io.nem.symbol.sdk.model.transaction.SecretProofTransaction)55 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)54 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)54 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)54 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)54