use of io.nem.sdk.model.mosaic.MosaicId 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);
}
use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class AccountTest method shouldSignTransaction.
@Test
void shouldSignTransaction() {
Account account = new Account("787225aaff3d2c71f4ffa32d4f19ec4922f3cd869747f267378f81f8e3fcb12d", NetworkType.MIJIN_TEST);
TransferTransaction transferTransaction = TransferTransaction.create(new FakeDeadline(), new Address("SDUP5PLHDXKBX3UU5Q52LAY4WYEKGEWC6IB3VBFM", NetworkType.MIJIN_TEST), Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100))), PlainMessage.Empty, NetworkType.MIJIN_TEST);
SignedTransaction signedTransaction = account.sign(transferTransaction);
assertEquals("A5000000773891AD01DD4CDF6E3A55C186C673E256D7DF9D471846F1943CC3529E4E02B38B9AF3F8D13784645FF5FAAFA94A321B94933C673D12DE60E4BC05ABA56F750E1026D70E1954775749C6811084D6450A3184D977383F0E4282CD47118AF37755039054410000000000000000010000000000000090E8FEBD671DD41BEE94EC3BA5831CB608A312C2F203BA84AC01000100672B0000CE5600006400000000000000", signedTransaction.getPayload());
assertEquals("350AE56BC97DB805E2098AB2C596FA4C6B37EF974BF24DFD61CD9F77C7687424", signedTransaction.getHash());
}
use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class MosaicSupplyChangeTransactionTest method createAMosaicSupplyChangeTransactionViaConstructor.
@Test
void createAMosaicSupplyChangeTransactionViaConstructor() {
MosaicSupplyChangeTransaction mosaicSupplyChangeTx = MosaicSupplyChangeTransaction.create(new Deadline(2, ChronoUnit.HOURS), new MosaicId(new BigInteger("6300565133566699912")), MosaicSupplyType.INCREASE, BigInteger.valueOf(10), NetworkType.MIJIN_TEST);
assertEquals(NetworkType.MIJIN_TEST, mosaicSupplyChangeTx.getNetworkType());
assertTrue(2 == mosaicSupplyChangeTx.getVersion());
assertTrue(LocalDateTime.now().isBefore(mosaicSupplyChangeTx.getDeadline().getLocalDateTime()));
assertEquals(BigInteger.valueOf(0), mosaicSupplyChangeTx.getFee());
assertEquals(new BigInteger("6300565133566699912"), mosaicSupplyChangeTx.getMosaicId().getId());
assertEquals(MosaicSupplyType.INCREASE, mosaicSupplyChangeTx.getMosaicSupplyType());
assertEquals(BigInteger.valueOf(10), mosaicSupplyChangeTx.getDelta());
}
use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serialization.
@Test
@DisplayName("Serialization")
void serialization() {
// Generated at nem2-library-js/test/transactions/TransferTransaction.spec.js
byte[] expected = new byte[] { (byte) 165, 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, 3, (byte) 144, 84, 65, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, (byte) 144, (byte) 232, (byte) 254, (byte) 189, (byte) 103, (byte) 29, (byte) 212, (byte) 27, (byte) 238, (byte) 148, (byte) 236, (byte) 59, (byte) 165, (byte) 131, (byte) 28, (byte) 182, (byte) 8, (byte) 163, (byte) 18, (byte) 194, (byte) 242, (byte) 3, (byte) 186, (byte) 132, (byte) 172, 1, 0, 1, 0, 103, 43, 0, 0, (byte) 206, 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.generateBytes();
assertArrayEquals(expected, actual);
}
use of io.nem.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class MosaicHttp method getMosaics.
@Override
public Observable<List<MosaicInfo>> getMosaics(List<MosaicId> mosaicIds) {
JsonObject requestBody = new JsonObject();
requestBody.put("mosaicIds", mosaicIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url + "/mosaic").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<MosaicInfoDTO>>readValue(json.toString(), new TypeReference<List<MosaicInfoDTO>>() {
})).flatMapIterable(item -> item).map(mosaicInfoDTO -> new MosaicInfo(mosaicInfoDTO.getMeta().isActive(), mosaicInfoDTO.getMeta().getIndex(), mosaicInfoDTO.getMeta().getId(), new NamespaceId(mosaicInfoDTO.getMosaic().getNamespaceId().extractIntArray()), new MosaicId(mosaicInfoDTO.getMosaic().getMosaicId().extractIntArray()), mosaicInfoDTO.getMosaic().getSupply().extractIntArray(), mosaicInfoDTO.getMosaic().getHeight().extractIntArray(), new PublicAccount(mosaicInfoDTO.getMosaic().getOwner(), networkType), extractMosaicProperties(mosaicInfoDTO.getMosaic().getProperties()))).toList().toObservable());
}
Aggregations