Search in sources :

Example 1 with MosaicId

use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class MosaicDefinitionTransaction method create.

/**
 * Create a mosaic creation transaction object.
 *
 * @param deadline         The deadline to include the transaction.
 * @param mosaicName       The mosaic name ex: xem.
 * @param namespaceName    The namespace where mosaic will be included ex: nem.
 * @param mosaicProperties The mosaic properties.
 * @param networkType      The network type.
 * @return {@link MosaicDefinitionTransaction}
 */
public static MosaicDefinitionTransaction create(Deadline deadline, String mosaicName, String namespaceName, MosaicProperties mosaicProperties, NetworkType networkType) {
    Validate.notNull(mosaicName, "MosaicName must not be null");
    Validate.notNull(namespaceName, "NamespaceName must not be null");
    return new MosaicDefinitionTransaction(networkType, 2, deadline, BigInteger.valueOf(0), mosaicName, new NamespaceId(namespaceName), new MosaicId(IdGenerator.generateMosaicId(namespaceName, mosaicName)), mosaicProperties);
}
Also used : MosaicId(io.nem.sdk.model.mosaic.MosaicId) NamespaceId(io.nem.sdk.model.namespace.NamespaceId)

Example 2 with MosaicId

use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class MosaicSupplyChangeTransactionTest method serialization.

@Test
@DisplayName("Serialization")
void serialization() {
    // Generated at nem2-library-js/test/transactions/MosaicSupplyChangeTransaction.spec.js
    byte[] expected = new byte[] { (byte) 137, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, (byte) 144, 77, 66, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, (byte) 136, 105, 116, 110, (byte) 155, 26, 112, 87, 1, 10, 0, 0, 0, 0, 0, 0, 0 };
    MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransaction.create(new FakeDeadline(), new MosaicId(new BigInteger("6300565133566699912")), MosaicSupplyType.INCREASE, BigInteger.valueOf(10), NetworkType.MIJIN_TEST);
    byte[] actual = mosaicSupplyChangeTransaction.generateBytes();
    assertArrayEquals(expected, actual);
}
Also used : MosaicId(io.nem.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with MosaicId

use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method toAggregate.

@Test
@DisplayName("To aggregate")
void toAggregate() {
    byte[] expected = new byte[] { 85, 0, 0, 0, -102, 73, 54, 100, 6, -84, -87, 82, -72, -117, -83, -11, -15, -23, -66, 108, -28, -106, -127, 65, 3, 90, 96, -66, 80, 50, 115, -22, 101, 69, 107, 36, 3, -112, 84, 65, -112, -24, -2, -67, 103, 29, -44, 27, -18, -108, -20, 59, -91, -125, 28, -74, 8, -93, 18, -62, -14, 3, -70, -124, -84, 1, 0, 1, 0, 103, 43, 0, 0, -50, 86, 0, 0, 100, 0, 0, 0, 0, 0, 0, 0 };
    TransferTransaction transferTransaction = TransferTransaction.create(new FakeDeadline(), new Address("SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM", NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100))), PlainMessage.Empty, NetworkType.MIJIN_TEST);
    byte[] actual = transferTransaction.toAggregate(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", NetworkType.MIJIN_TEST)).toAggregateTransactionBytes();
    assertArrayEquals(expected, actual);
}
Also used : Address(io.nem.sdk.model.account.Address) MosaicId(io.nem.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Mosaic(io.nem.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with MosaicId

use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method serializeAndSignTransaction.

@Test
void serializeAndSignTransaction() {
    TransferTransaction transferTransaction = TransferTransaction.create(new FakeDeadline(), new Address("SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM", NetworkType.MIJIN_TEST), Arrays.asList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100))), PlainMessage.Empty, NetworkType.MIJIN_TEST);
    SignedTransaction signedTransaction = transferTransaction.signWith(account);
    assertEquals("A5000000773891AD01DD4CDF6E3A55C186C673E256D7DF9D471846F1943CC3529E4E02B38B9AF3F8D13784645FF5FAAFA94A321B94933C673D12DE60E4BC05ABA56F750E1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755039054410000000000000000010000000000000090E8FEBD671DD41BEE94EC3BA5831CB608A312C2F203BA84AC01000100672B0000CE5600006400000000000000", signedTransaction.getPayload());
    assertEquals("350AE56BC97DB805E2098AB2C596FA4C6B37EF974BF24DFD61CD9F77C7687424", signedTransaction.getHash());
}
Also used : Address(io.nem.sdk.model.account.Address) MosaicId(io.nem.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Mosaic(io.nem.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test)

Example 5 with MosaicId

use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.

the class AccountHttp method getAccountsInfo.

@Override
public Observable<List<AccountInfo>> getAccountsInfo(List<Address> addresses) {
    JsonObject requestBody = new JsonObject();
    requestBody.put("addresses", addresses.stream().map(address -> address.plain()).collect(Collectors.toList()));
    Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
    return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url.toString()).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<AccountInfoDTO>>readValue(json.toString(), new TypeReference<List<AccountInfoDTO>>() {
    })).flatMapIterable(item -> item).map(AccountInfoDTO::getAccount).map(accountDTO -> new AccountInfo(Address.createFromRawAddress(accountDTO.getAddressEncoded()), accountDTO.getAddressHeight().extractIntArray(), accountDTO.getPublicKey(), accountDTO.getPublicKeyHeight().extractIntArray(), accountDTO.getImportance().extractIntArray(), accountDTO.getImportanceHeight().extractIntArray(), accountDTO.getMosaics().stream().map(mosaicDTO -> new Mosaic(new MosaicId(mosaicDTO.getId().extractIntArray()), mosaicDTO.getAmount().extractIntArray())).collect(Collectors.toList()))).toList().toObservable());
}
Also used : Mosaic(io.nem.sdk.model.mosaic.Mosaic) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) AggregateTransaction(io.nem.sdk.model.transaction.AggregateTransaction) HashMap(java.util.HashMap) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Function(io.reactivex.functions.Function) io.nem.sdk.model.account(io.nem.sdk.model.account) Map(java.util.Map) Optional(java.util.Optional) Transaction(io.nem.sdk.model.transaction.Transaction) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MosaicId(io.nem.sdk.model.mosaic.MosaicId) NetworkType(io.nem.sdk.model.blockchain.NetworkType) MosaicId(io.nem.sdk.model.mosaic.MosaicId) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Mosaic(io.nem.sdk.model.mosaic.Mosaic)

Aggregations

MosaicId (io.nem.sdk.model.mosaic.MosaicId)11 BigInteger (java.math.BigInteger)7 Mosaic (io.nem.sdk.model.mosaic.Mosaic)6 Test (org.junit.jupiter.api.Test)6 Address (io.nem.sdk.model.account.Address)4 PublicAccount (io.nem.sdk.model.account.PublicAccount)4 NetworkType (io.nem.sdk.model.blockchain.NetworkType)4 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)4 JsonObject (io.vertx.core.json.JsonObject)4 List (java.util.List)4 Optional (java.util.Optional)4 Collectors (java.util.stream.Collectors)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 MosaicProperties (io.nem.sdk.model.mosaic.MosaicProperties)3 Observable (io.reactivex.Observable)3 HttpResponse (io.vertx.reactivex.ext.web.client.HttpResponse)3 BodyCodec (io.vertx.reactivex.ext.web.codec.BodyCodec)3 MalformedURLException (java.net.MalformedURLException)3 DisplayName (org.junit.jupiter.api.DisplayName)3 MosaicInfo (io.nem.sdk.model.mosaic.MosaicInfo)2