use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class Config method loadNemesisAccountsFromBootstrap.
private static List<Account> loadNemesisAccountsFromBootstrap(NetworkType networkType, File generatedAddresses) {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
if (!generatedAddresses.exists()) {
System.out.println("Generated addresses could not be found in " + generatedAddresses.getAbsolutePath() + " Nemesis address must bue added manually");
return Collections.emptyList();
}
List<Map<String, String>> bootstrapAddresses;
List<Map<String, List<Map<String, String>>>> mosaics = (List<Map<String, List<Map<String, String>>>>) mapper.readValue(generatedAddresses, Map.class).get("mosaics");
bootstrapAddresses = mosaics.get(0).get("accounts");
return bootstrapAddresses.stream().map(m -> Account.createFromPrivateKey(m.get("privateKey"), networkType)).collect(Collectors.toList());
} catch (Exception e) {
throw new IllegalStateException("Nemesis account could not be loaded from Bootstrap: " + ExceptionUtils.getMessage(e), e);
}
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class CreatingAnEscrowContractWithAggregateBondedTransactionIntegrationTest method executeTransfer.
@Test
@Disabled
void executeTransfer() {
Account ticketDistributorAccount = this.config().getTestAccount();
Account aliceAccount = this.config().getTestAccount2();
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
MosaicId mosaicId = createMosaic(ticketDistributorAccount, type, BigInteger.ZERO, null);
TransferTransaction aliceToTicketDistributorTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), ticketDistributorAccount.getAddress(), Collections.singletonList(getNetworkCurrency().createRelative(BigInteger.valueOf(100)))).message(new PlainMessage("send 100 cat.currency to distributor")).maxFee(maxFee).build();
TransferTransaction ticketDistributorToAliceTx = TransferTransactionFactory.create(getNetworkType(), getDeadline(), aliceAccount.getAddress(), Collections.singletonList(new Mosaic(mosaicId, BigInteger.ONE))).message(new PlainMessage("send 1 museum ticket to alice")).maxFee(maxFee).build();
/* end block 01 */
/* start block 02 */
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Arrays.asList(aliceToTicketDistributorTx.toAggregate(aliceAccount.getPublicAccount()), ticketDistributorToAliceTx.toAggregate(ticketDistributorAccount.getPublicAccount()))).maxFee(maxFee).build();
String networkGenerationHash = getGenerationHash();
SignedTransaction signedTransaction = aliceAccount.sign(aggregateTransaction, networkGenerationHash);
System.out.println("Aggregate Transaction Hash: " + signedTransaction.getHash());
/* end block 02 */
/* start block 03 */
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), getNetworkCurrency().createRelative(BigInteger.TEN), BigInteger.valueOf(480), signedTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = aliceAccount.sign(hashLockTransaction, networkGenerationHash);
System.out.println("Hash Transaction Hash: " + hashLockTransaction.getHash());
TransactionService transactionService = getTransactionService(type);
Transaction transaction = get(transactionService.announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedTransaction));
Assertions.assertNotNull(transaction);
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class ListenerStatusIntegrationTest method sendTransactionsNewListener.
@Test
void sendTransactionsNewListener() throws ExecutionException, InterruptedException {
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
Account account1 = config().getNemesisAccount1();
Account account2 = Account.generateNewAccount(getNetworkType());
Account account3 = Account.generateNewAccount(getNetworkType());
createListener(type).unconfirmedRemoved(account1.getAddress()).subscribe(a -> {
System.out.println(">>>> account 1 " + a);
});
createListener(type).unconfirmedRemoved(account2.getAddress()).subscribe(a -> {
System.out.println(">>>> account 2 " + a);
});
createListener(type).unconfirmedRemoved(account3.getAddress()).subscribe(a -> {
System.out.println(">>>> account 3 " + a);
});
// IT prints:
// >>>> account 1
// B742A00E5F7D8381F78EBE8CE47023C6298FB1802CDB3861CA0C05286DE0EE63
// >>>> account 2
// B742A00E5F7D8381F78EBE8CE47023C6298FB1802CDB3861CA0C05286DE0EE63
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account2.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
announceAndValidate(type, account1, transferTransaction);
sleep(1000);
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class ListenerStatusIntegrationTest method statusListener.
@Test
void statusListener() throws ExecutionException, InterruptedException {
RepositoryType type = DEFAULT_REPOSITORY_TYPE;
Account account1 = Account.generateNewAccount(getNetworkType());
Account account2 = Account.generateNewAccount(getNetworkType());
Account account3 = Account.generateNewAccount(getNetworkType());
createListener(type).status(account1.getAddress()).subscribe(a -> {
System.out.println(">>>> account 1 " + a.getAddress() + " " + a.getHash() + " " + a.getStatus());
});
createListener(type).status(account2.getAddress()).subscribe(a -> {
System.out.println(">>>> account 2 " + a.getAddress() + " " + a.getHash() + " " + a.getStatus());
});
createListener(type).status(account3.getAddress()).subscribe(a -> {
System.out.println(">>>> account 3 " + a.getAddress() + " " + a.getHash() + " " + a.getStatus());
});
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), account2.getAddress(), Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(1)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
announceAndValidate(type, account1, transferTransaction);
}
use of io.nem.symbol.sdk.model.account.Account in project nem2-sdk-java by nemtech.
the class AccountRepositoryIntegrationTest method unconfirmedTransactions.
@ParameterizedTest
@EnumSource(RepositoryType.class)
void unconfirmedTransactions(RepositoryType type) {
Account testAccount = this.config().getDefaultAccount();
TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
PublicAccount publicAccount = this.helper().getTestAccount(type).getLeft().getPublicAccount();
List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.UNCONFIRMED).signerPublicKey(publicAccount.getPublicKey()))).getData();
System.out.println(transactions.size());
transactions.forEach(transaction -> assertTransaction(transaction, testAccount.getAddress()));
}
Aggregations