Search in sources :

Example 11 with Mosaic

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());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 12 with Mosaic

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;
}
Also used : TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) ArrayList(java.util.ArrayList) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) UnresolvedMosaic(io.nem.symbol.sdk.openapi.okhttp_gson.model.UnresolvedMosaic)

Example 13 with Mosaic

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);
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Duration(java.time.Duration) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic)

Example 14 with Mosaic

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);
}
Also used : KeyPair(io.nem.symbol.core.crypto.KeyPair) Message(io.nem.symbol.sdk.model.message.Message) EncryptedMessage(io.nem.symbol.sdk.model.message.EncryptedMessage) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) PersistentHarvestingDelegationMessage(io.nem.symbol.sdk.model.message.PersistentHarvestingDelegationMessage) Currency(io.nem.symbol.sdk.model.mosaic.Currency) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 15 with Mosaic

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();
    }
}
Also used : Listener(io.nem.symbol.sdk.api.Listener) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Currency(io.nem.symbol.sdk.model.mosaic.Currency) ArrayList(java.util.ArrayList) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic)

Aggregations

Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)35 Test (org.junit.jupiter.api.Test)26 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)24 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)19 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)18 BigInteger (java.math.BigInteger)18 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)15 Address (io.nem.symbol.sdk.model.account.Address)12 ArrayList (java.util.ArrayList)12 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)6 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)6 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)5 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)5 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)4 Account (io.nem.symbol.sdk.model.account.Account)4 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)4 Currency (io.nem.symbol.sdk.model.mosaic.Currency)4 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)4