use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serializeAndSignTransaction.
@Test
void serializeAndSignTransaction() {
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("")).build();
SignedTransaction signedTransaction = transaction.signWith(account, generationHash);
String payload = signedTransaction.getPayload();
assertEquals("B10000000000000013193EF4F0D94DE26249D196A0575944877D5572CE13B80E4E8380FA34F9F54FF936F96162473857546F7B624A6248D8F7B3D0142DC85BBB06EB7BFEE125880B2134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A0100010000000000672B0000CE560000640000000000000000", payload);
assertEquals("58D649ABF9A26AFB3F070E26F157920DAB6423415B4344108B93EDD80DE330E5", signedTransaction.getHash());
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionMapper method createFactory.
@Override
protected TransactionFactory<TransferTransaction> createFactory(NetworkType networkType, Deadline deadline, TransferTransactionDTO transaction) {
List<Mosaic> mosaics = new ArrayList<>();
if (transaction.getMosaics() != null) {
mosaics = transaction.getMosaics().stream().map(mosaic -> new Mosaic(toUnresolvedMosaicId(mosaic.getId()), mosaic.getAmount())).collect(Collectors.toList());
}
TransferTransactionFactory transferTransactionFactory = TransferTransactionFactory.create(networkType, deadline, MapperUtils.toUnresolvedAddress(transaction.getRecipientAddress()), mosaics);
Message.createFromHexPayload(transaction.getMessage()).ifPresent(transferTransactionFactory::message);
return transferTransactionFactory;
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TestnetTester method sendMosaics.
private static void sendMosaics(RepositoryFactory repositoryFactory) throws Exception {
NetworkType networkType = repositoryFactory.getNetworkType().blockingFirst();
Account account = Account.createFromPrivateKey(PRIVATE_KEY, networkType);
Account recipient = Account.generateNewAccount(networkType);
Mosaic mosaic = repositoryFactory.getNetworkCurrency().blockingFirst().createAbsolute(1);
System.out.println(account.getAddress().plain());
Duration duration = repositoryFactory.getEpochAdjustment().blockingFirst();
Deadline deadline = Deadline.create(duration);
TransferTransaction transaction = TransferTransactionFactory.create(networkType, deadline, recipient.getAddress(), Collections.singletonList(mosaic)).maxFee(MAX_FEE).build();
announceTransaction(repositoryFactory, account, transaction);
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method standaloneTransferTransactionEncryptedMessage.
@ParameterizedTest
@EnumSource(RepositoryType.class)
public void standaloneTransferTransactionEncryptedMessage(RepositoryType type) throws Exception {
this.helper().sendMosaicFromNemesis(type, getRecipient(), false);
String namespaceName = "standaloneTransferTransactionEncryptedMessagealias".toLowerCase();
NamespaceId recipient = setAddressAlias(type, getRecipient(), namespaceName);
System.out.println(recipient.getIdAsHex());
Assertions.assertEquals("9960629109A48AFBC0000000000000000000000000000000", recipient.encoded(getNetworkType()));
String message = "E2ETest:standaloneTransferTransaction:message 漢字";
KeyPair senderKeyPair = KeyPair.random();
KeyPair recipientKeyPair = KeyPair.random();
Message encryptedMessage = EncryptedMessage.create(message, senderKeyPair.getPrivateKey(), recipientKeyPair.getPublicKey());
Currency networkCurrency = getNetworkCurrency();
Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(10202020));
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(encryptedMessage).maxFee(maxFee).build();
TransferTransaction processed = announceAndValidate(type, signerAccount, transferTransaction);
assertTransferTransactions(transferTransaction, processed);
assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, processed);
TransferTransaction restTransaction = (TransferTransaction) get(getRepositoryFactory(type).createTransactionRepository().getTransaction(TransactionGroup.CONFIRMED, processed.getTransactionInfo().get().getHash().get()));
assertTransferTransactions(transferTransaction, restTransaction);
assertEncryptedMessageTransaction(message, senderKeyPair, recipientKeyPair, restTransaction);
}
use of io.nem.symbol.sdk.model.mosaic.Mosaic in project nem2-sdk-java by nemtech.
the class TransferTransactionIntegrationTest method basicTransfer.
private List<String> basicTransfer(RepositoryType type, UnresolvedAddress recipient, String s, int i, List<String> expected, boolean includeAliases, UnresolvedAddress... listenTo) throws InterruptedException, ExecutionException {
List<String> messages = new ArrayList<>();
Listener listener = listen(type, messages, includeAliases, listenTo);
sleep(1000);
try {
String message = s;
Currency networkCurrency = getNetworkCurrency();
Mosaic mosaic = new Mosaic(networkCurrency.getNamespaceId().get(), BigInteger.valueOf(i));
TransferTransaction transferTransaction = TransferTransactionFactory.create(getNetworkType(), getDeadline(), recipient, Collections.singletonList(mosaic)).message(new PlainMessage(message)).maxFee(maxFee).build();
TransferTransaction processed = announceAggregateAndValidate(type, transferTransaction, signerAccount).getKey();
Assertions.assertEquals(message, processed.getMessage().get().getText());
sleep(1000);
Assertions.assertEquals(expected, messages);
return messages;
} finally {
listener.close();
}
}
Aggregations