use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method createATransferTransactionViaStaticConstructorSetMaxFee.
@Test
void createATransferTransactionViaStaticConstructorSetMaxFee() {
Duration epochAdjustment = Duration.ofSeconds(100);
long feeMultiplier = 10;
TransactionFactory<TransferTransaction> factory = TransferTransactionFactory.create(networkType, Deadline.create(epochAdjustment), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.emptyList()).message(new PlainMessage("")).calculateMaxFeeFromMultiplier(feeMultiplier);
TransferTransaction transaction = factory.build();
assertEquals(networkType, transaction.getNetworkType());
assertEquals(1, (int) transaction.getVersion());
assertTrue(LocalDateTime.now().isBefore(transaction.getDeadline().getLocalDateTime(epochAdjustment)));
assertEquals(BigInteger.valueOf(1610), transaction.getMaxFee());
assertEquals(new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), transaction.getRecipient());
assertEquals(0, transaction.getMosaics().size());
assertNotNull(transaction.getMessage());
assertEquals(161, factory.getSize());
assertEquals(BigInteger.valueOf(transaction.getSize()).multiply(BigInteger.valueOf(feeMultiplier)), transaction.getMaxFee());
assertEquals(transaction.getSize(), factory.getSize());
}
use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serializationNamespaceRecipient.
@Test
@DisplayName("Serialization-public-namespace-recipient")
void serializationNamespaceRecipient() {
String expected = "C4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001905441000000000000000001000000000000009151776168D24257D80000000000000000000000000000001400010000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
NamespaceId recipient = NamespaceId.createFromName("nem.owner");
Assertions.assertEquals("D85742D268617751", recipient.getIdAsHex());
Assertions.assertEquals("9151776168D24257D8000000000000000000000000000000", recipient.encoded(networkType));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), recipient, Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message 漢字")).build();
Assertions.assertEquals(recipient.encoded(networkType), transaction.getRecipient().encoded(networkType));
assertSerialization(expected, transaction);
}
use of io.nem.symbol.sdk.model.message.PlainMessage in project nem2-sdk-java by nemtech.
the class ListenerIntegrationTest method announceStandaloneTransferTransaction.
private SignedTransaction announceStandaloneTransferTransaction(RepositoryType type, Address recipient) {
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(getNetworkCurrency().createAbsolute(BigInteger.valueOf(10000L)))).message(new PlainMessage("test-message")).maxFee(maxFee).build();
SignedTransaction signedTransaction = this.account.sign(transferTransaction, getGenerationHash());
System.out.println("Announcing transaction " + signedTransaction.getHash());
get(getTransactionRepository(type).announce(signedTransaction));
System.out.println("Transaction " + signedTransaction.getHash() + " Announced");
return signedTransaction;
}
use of io.nem.symbol.sdk.model.message.PlainMessage 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.message.PlainMessage 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);
}
Aggregations