Search in sources :

Example 11 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class SecretProofTransactionMapping method apply.

@Override
public TransferTransaction apply(JsonObject input) {
    TransactionInfo transactionInfo = this.createTransactionInfo(input.getJsonObject("meta"));
    JsonObject transaction = input.getJsonObject("transaction");
    Deadline deadline = new Deadline(extractBigInteger(transaction.getJsonArray("deadline")));
    List<Mosaic> mosaics = new ArrayList<>();
    if (transaction.getJsonArray("mosaics") != null) {
        mosaics = transaction.getJsonArray("mosaics").stream().map(item -> (JsonObject) item).map(mosaic -> new Mosaic(new MosaicId(extractBigInteger(mosaic.getJsonArray("id"))), extractBigInteger(mosaic.getJsonArray("amount")))).collect(Collectors.toList());
    }
    Message message = PlainMessage.Empty;
    if (transaction.getJsonObject("message") != null) {
        try {
            message = new PlainMessage(new String(Hex.decode(transaction.getJsonObject("message").getString("payload")), "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            message = new PlainMessage(transaction.getJsonObject("message").getString("payload"));
        }
    }
    return new TransferTransaction(extractNetworkType(transaction.getInteger("version")), extractTransactionVersion(transaction.getInteger("version")), deadline, extractBigInteger(transaction.getJsonArray("fee")), Address.createFromEncoded(transaction.getString("recipient")), mosaics, message, transaction.getString("signature"), new PublicAccount(transaction.getString("signer"), extractNetworkType(transaction.getInteger("version"))), transactionInfo);
}
Also used : Mosaic(io.nem.sdk.model.mosaic.Mosaic) NamespaceType(io.nem.sdk.model.namespace.NamespaceType) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) io.nem.sdk.model.transaction(io.nem.sdk.model.transaction) Hex(org.bouncycastle.util.encoders.Hex) ArrayList(java.util.ArrayList) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) Function(io.reactivex.functions.Function) Address(io.nem.sdk.model.account.Address) MosaicProperties(io.nem.sdk.model.mosaic.MosaicProperties) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) JsonObject(io.vertx.core.json.JsonObject) BigInteger(java.math.BigInteger) MosaicId(io.nem.sdk.model.mosaic.MosaicId) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Collections(java.util.Collections) MosaicSupplyType(io.nem.sdk.model.mosaic.MosaicSupplyType) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MosaicId(io.nem.sdk.model.mosaic.MosaicId) PublicAccount(io.nem.sdk.model.account.PublicAccount) Mosaic(io.nem.sdk.model.mosaic.Mosaic)

Example 12 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class MosaicInfoTest method shouldReturnIsSupplyMutableWhenIsMutable.

@Test
void shouldReturnIsSupplyMutableWhenIsMutable() {
    MosaicProperties mosaicProperties = new MosaicProperties(true, true, true, 3, BigInteger.valueOf(10));
    MosaicInfo mosaicInfo = new MosaicInfo(true, 0, "5A3CD9B09CD1E8000159249B", new NamespaceId(new BigInteger("-8884663987180930485")), new MosaicId(new BigInteger("-3087871471161192663")), new BigInteger("100"), new BigInteger("0"), new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.MIJIN_TEST), mosaicProperties);
    assertTrue(mosaicInfo.isSupplyMutable());
}
Also used : PublicAccount(io.nem.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 13 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class MosaicInfoTest method shouldReturnIsTransferableWhenItsTransferable.

@Test
void shouldReturnIsTransferableWhenItsTransferable() {
    MosaicProperties mosaicProperties = new MosaicProperties(true, true, true, 3, BigInteger.valueOf(10));
    MosaicInfo mosaicInfo = new MosaicInfo(true, 0, "5A3CD9B09CD1E8000159249B", new NamespaceId(new BigInteger("-8884663987180930485")), new MosaicId(new BigInteger("-3087871471161192663")), new BigInteger("100"), new BigInteger("0"), new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.MIJIN_TEST), mosaicProperties);
    assertTrue(mosaicInfo.isTransferable());
}
Also used : PublicAccount(io.nem.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 14 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class MosaicInfoTest method createAMosaicInfoViaConstructor.

@Test
void createAMosaicInfoViaConstructor() {
    MosaicProperties mosaicProperties = new MosaicProperties(true, true, true, 3, BigInteger.valueOf(10));
    NamespaceId namespaceId = new NamespaceId(new BigInteger("-8884663987180930485"));
    MosaicId mosaicId = new MosaicId(new BigInteger("-3087871471161192663"));
    MosaicInfo mosaicInfo = new MosaicInfo(true, 0, "5A3CD9B09CD1E8000159249B", namespaceId, mosaicId, new BigInteger("100"), new BigInteger("0"), new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.MIJIN_TEST), mosaicProperties);
    assertEquals(true, mosaicInfo.isActive());
    assertTrue(mosaicInfo.getIndex() == 0);
    assertEquals("5A3CD9B09CD1E8000159249B", mosaicInfo.getMetaId());
    assertEquals(namespaceId, mosaicInfo.getNamespaceId());
    assertEquals(mosaicId, mosaicInfo.getMosaicId());
    assertEquals(new BigInteger("100"), mosaicInfo.getSupply());
    assertEquals(new BigInteger("0"), mosaicInfo.getHeight());
    assertEquals(new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.MIJIN_TEST), mosaicInfo.getOwner());
    assertTrue(mosaicInfo.isSupplyMutable());
    assertTrue(mosaicInfo.isTransferable());
    assertTrue(mosaicInfo.isLevyMutable());
    assertEquals(3, mosaicInfo.getDivisibility());
    assertEquals(BigInteger.valueOf(10), mosaicInfo.getDuration());
}
Also used : PublicAccount(io.nem.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 15 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount in project nem2-sdk-java by nemtech.

the class NamespaceInfoTest method createANamespaceInfoViaConstructor.

@Test
void createANamespaceInfoViaConstructor() {
    NamespaceId namespaceId = new NamespaceId(new BigInteger("-8884663987180930485"));
    NamespaceInfo namespaceInfo = new NamespaceInfo(true, 0, "5A3CD9B09CD1E8000159249B", NamespaceType.RootNamespace, 1, Arrays.asList(namespaceId), new NamespaceId(new BigInteger("0")), new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.MIJIN_TEST), new BigInteger("1"), new BigInteger("-1"));
    assertEquals(true, namespaceInfo.isActive());
    assertTrue(namespaceInfo.getIndex() == 0);
    assertEquals("5A3CD9B09CD1E8000159249B", namespaceInfo.getMetaId());
    assertTrue(namespaceInfo.getType() == NamespaceType.RootNamespace);
    assertTrue(namespaceInfo.getDepth() == 1);
    assertEquals(namespaceId, namespaceInfo.getLevels().get(0));
    Assertions.assertEquals(new PublicAccount("B4F12E7C9F6946091E2CB8B6D3A12B50D17CCBBF646386EA27CE2946A7423DCF", NetworkType.MIJIN_TEST), namespaceInfo.getOwner());
    assertEquals(new BigInteger("1"), namespaceInfo.getStartHeight());
    assertEquals(new BigInteger("-1"), namespaceInfo.getEndHeight());
}
Also used : PublicAccount(io.nem.sdk.model.account.PublicAccount) BigInteger(java.math.BigInteger) Test(org.junit.jupiter.api.Test)

Aggregations

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