Search in sources :

Example 11 with Address

use of io.nem.sdk.model.account.Address 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);
}
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) DisplayName(org.junit.jupiter.api.DisplayName)

Example 12 with Address

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

the class E2ETest method CosignatureTransaction.

@Test
void CosignatureTransaction() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransaction.create(new Deadline(2, HOURS), new Address("SDRDGFTDLLCB67D4HPGIMIHPNSRYRJRT7DOBGWZY", NetworkType.MIJIN_TEST), Collections.singletonList(XEM.createAbsolute(BigInteger.valueOf(1))), PlainMessage.create("test-message"), NetworkType.MIJIN_TEST);
    AggregateTransaction aggregateTransaction = AggregateTransaction.createComplete(new Deadline(2, HOURS), Collections.singletonList(transferTransaction.toAggregate(this.multisigAccount.getPublicAccount())), NetworkType.MIJIN_TEST);
    SignedTransaction signedTransaction = this.cosignatoryAccount.sign(aggregateTransaction);
    LockFundsTransaction lockFundsTransaction = LockFundsTransaction.create(new Deadline(2, HOURS), XEM.createRelative(BigInteger.valueOf(10)), BigInteger.valueOf(100), signedTransaction, NetworkType.MIJIN_TEST);
    SignedTransaction lockFundsSignedTransaction = this.cosignatoryAccount.sign(lockFundsTransaction);
    transactionHttp.announce(lockFundsSignedTransaction).toFuture().get();
    listener.confirmed(this.cosignatoryAccount.getAddress()).take(1).toFuture().get();
    transactionHttp.announceAggregateBonded(signedTransaction).toFuture().get();
    this.validateAggregateBondedTransactionAnnounceCorrectly(this.cosignatoryAccount.getAddress(), signedTransaction.getHash());
    CosignatureTransaction cosignatureTransaction = CosignatureTransaction.create(aggregateTransaction);
    CosignatureSignedTransaction cosignatureSignedTransaction = this.cosignatoryAccount2.signCosignatureTransaction(cosignatureTransaction);
    transactionHttp.announceAggregateBondedCosignature(cosignatureSignedTransaction).toFuture().get();
    this.validateAggregateBondedCosignatureTransactionAnnounceCorrectly(this.cosignatoryAccount.getAddress(), cosignatureSignedTransaction.getParentHash());
}
Also used : Address(io.nem.sdk.model.account.Address) Test(org.junit.jupiter.api.Test)

Example 13 with Address

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

the class ListenerTest method announceStandaloneTransferTransactionWithInsufficientBalance.

private SignedTransaction announceStandaloneTransferTransactionWithInsufficientBalance() throws ExecutionException, InterruptedException {
    TransferTransaction transferTransaction = TransferTransaction.create(new Deadline(2, HOURS), new Address("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", NetworkType.MIJIN_TEST), Arrays.asList(XEM.createRelative(new BigInteger("100000000000"))), PlainMessage.create("test-message"), NetworkType.MIJIN_TEST);
    SignedTransaction signedTransaction = this.account.sign(transferTransaction);
    transactionHttp.announce(signedTransaction).toFuture().get();
    return signedTransaction;
}
Also used : Address(io.nem.sdk.model.account.Address) BigInteger(java.math.BigInteger)

Example 14 with Address

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

the class NamespaceHttp method getNamespacesFromAccounts.

private Observable<List<NamespaceInfo>> getNamespacesFromAccounts(List<Address> addresses, Optional<QueryParams> queryParams) {
    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 + "/account/namespaces" + (queryParams.isPresent() ? queryParams.get().toUrl() : "")).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<NamespaceInfoDTO>>readValue(json.toString(), new TypeReference<List<NamespaceInfoDTO>>() {
    })).flatMapIterable(item -> item).map(namespaceInfoDTO -> new NamespaceInfo(namespaceInfoDTO.getMeta().isActive(), namespaceInfoDTO.getMeta().getIndex(), namespaceInfoDTO.getMeta().getId(), NamespaceType.rawValueOf(namespaceInfoDTO.getNamespace().getType()), namespaceInfoDTO.getNamespace().getDepth(), extractLevels(namespaceInfoDTO), new NamespaceId(namespaceInfoDTO.getNamespace().getParentId().extractIntArray()), new PublicAccount(namespaceInfoDTO.getNamespace().getOwner(), networkType), namespaceInfoDTO.getNamespace().getStartHeight().extractIntArray(), namespaceInfoDTO.getNamespace().getEndHeight().extractIntArray())).toList().toObservable());
}
Also used : NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) NamespaceType(io.nem.sdk.model.namespace.NamespaceType) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Address(io.nem.sdk.model.account.Address) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NetworkType(io.nem.sdk.model.blockchain.NetworkType) PublicAccount(io.nem.sdk.model.account.PublicAccount) JsonObject(io.vertx.core.json.JsonObject) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) ArrayList(java.util.ArrayList) List(java.util.List) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo)

Aggregations

Address (io.nem.sdk.model.account.Address)14 Test (org.junit.jupiter.api.Test)10 PublicAccount (io.nem.sdk.model.account.PublicAccount)5 Mosaic (io.nem.sdk.model.mosaic.Mosaic)4 BigInteger (java.math.BigInteger)4 MosaicId (io.nem.sdk.model.mosaic.MosaicId)3 DisplayName (org.junit.jupiter.api.DisplayName)3 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 Account (io.nem.sdk.model.account.Account)1 NetworkType (io.nem.sdk.model.blockchain.NetworkType)1 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)1 NamespaceInfo (io.nem.sdk.model.namespace.NamespaceInfo)1 NamespaceName (io.nem.sdk.model.namespace.NamespaceName)1 NamespaceType (io.nem.sdk.model.namespace.NamespaceType)1 UInt64 (io.nem.sdk.model.transaction.UInt64)1 Observable (io.reactivex.Observable)1 JsonObject (io.vertx.core.json.JsonObject)1 HttpResponse (io.vertx.reactivex.ext.web.client.HttpResponse)1 BodyCodec (io.vertx.reactivex.ext.web.codec.BodyCodec)1 MalformedURLException (java.net.MalformedURLException)1