use of io.nem.symbol.sdk.model.transaction.SignedTransaction 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();
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class OkHttpAggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.
@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
Address address = Address.generateRandom(networkType);
TransferTransaction transferTx = TransferTransactionFactory.create(networkType, deadline, address, Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTx = AggregateTransactionFactory.createComplete(networkType, deadline, 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());
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class AggregateTransactionServiceIntegrationTest method isTransferFromMultisigNotComplete.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void isTransferFromMultisigNotComplete(RepositoryType type) {
Account multisigAccount = helper().getMultisigAccount(type).getLeft();
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), getRecipient(), Collections.emptyList()).message(new PlainMessage("")).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transferTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Collections.singletonList(config().getTestAccount()), getGenerationHash());
AggregateTransactionService aggregateTransactionService = new AggregateTransactionServiceImpl(getRepositoryFactory(type));
Assertions.assertFalse(get(aggregateTransactionService.isComplete(signedAggregateTransaction)));
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class HashLockTransactionIntegrationTest method standaloneLockFundsTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void standaloneLockFundsTransaction(RepositoryType type) {
BigInteger duration = BigInteger.valueOf(10000);
TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneLockFundsTransaction"));
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(factory.build().toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedTransaction = this.account.sign(aggregateTransaction, getGenerationHash());
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), duration, signedTransaction).maxFee(maxFee).build();
announceAndValidate(type, this.account, hashLockTransaction);
announceAndValidate(type, this.account, aggregateTransaction);
}
use of io.nem.symbol.sdk.model.transaction.SignedTransaction in project nem2-sdk-java by nemtech.
the class HashLockTransactionIntegrationTest method aggregateLockFundsTransaction.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void aggregateLockFundsTransaction(RepositoryType type) {
BigInteger duration = BigInteger.valueOf(1000);
TransferTransactionFactory factory = TransferTransactionFactory.create(getNetworkType(), getDeadline(), this.account.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("E2ETest:standaloneLockFundsTransaction"));
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(factory.build().toAggregate(account.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedTransaction = this.account.sign(aggregateTransaction, getGenerationHash());
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.valueOf(10)), duration, signedTransaction).maxFee(maxFee).build();
announceAggregateAndValidate(type, hashLockTransaction, this.account);
announceAndValidate(type, this.account, aggregateTransaction);
}
Aggregations