use of io.nem.symbol.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.
the class TransactionRepositoryIntegrationTest method setup.
@BeforeAll
void setup() {
RepositoryType type = RepositoryType.VERTX;
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
Address recipient = getRecipient();
String message = "someMessage";
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage(message)).maxFee(maxFee).build();
TransferTransaction processed = announceAndValidate(type, config().getDefaultAccount(), transferTransaction);
Assertions.assertEquals(message, processed.getMessage().get().getText());
PublicAccount account = config().getDefaultAccount().getPublicAccount();
List<Transaction> allTransactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).order(OrderBy.DESC).signerPublicKey(account.getPublicKey()))).getData();
List<Transaction> transactions = allTransactions.stream().filter(t -> t.getType() == TransactionType.TRANSFER).collect(Collectors.toList());
Assertions.assertTrue(allTransactions.size() > 0);
Assertions.assertTrue(transactions.size() > 0);
transactionHash = transactions.get(0).getTransactionInfo().get().getHash().get();
}
use of io.nem.symbol.sdk.model.account.PublicAccount 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.account.PublicAccount in project nem2-sdk-java by nemtech.
the class TransactionRepositoryOkHttpImplTest method searchTransactions.
@Test
public void searchTransactions() throws Exception {
BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
TransactionInfoDTO transferTransactionDTO = loadTransactionInfoDTO("standaloneTransferTransaction.json", TransactionInfoDTO.class);
PublicAccount publicAccount = Account.generateNewAccount(networkType).getPublicAccount();
mockRemoteCall(toPage(transferTransactionDTO));
Page<Transaction> transactions = repository.search(new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).signerPublicKey(publicAccount.getPublicKey())).toFuture().get();
Assertions.assertEquals(TransactionType.TRANSFER, transactions.getData().get(0).getType());
Assertions.assertEquals(TransactionGroup.UNCONFIRMED, transactions.getData().get(0).getGroup().get());
Assertions.assertEquals(1, transactions.getData().size());
Assertions.assertEquals(1, transactions.getPageNumber());
Assertions.assertEquals(2, transactions.getPageSize());
}
use of io.nem.symbol.sdk.model.account.PublicAccount 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.account.PublicAccount in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method outgoingTransactions.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void outgoingTransactions(RepositoryType type) {
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
PublicAccount recipient = this.helper().getTestAccount(type).getLeft().getPublicAccount();
List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).transactionTypes(Collections.singletonList(TransactionType.TRANSFER)).recipientAddress(recipient.getAddress()))).getData();
System.out.println(transactions.size());
transactions.forEach(transaction -> {
assertTransaction(transaction, null);
TransferTransaction transferTransaction = (TransferTransaction) transaction;
Assertions.assertEquals(recipient.getAddress(), transferTransaction.getRecipient());
});
}
Aggregations