Search in sources :

Example 6 with PublicAccount

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

the class AggregateTransactionCosignatureTest method createAnAggregateCosignatureViaConstructor.

@Test
void createAnAggregateCosignatureViaConstructor() {
    AggregateTransactionCosignature aggregateTransactionCosignature = new AggregateTransactionCosignature("signature", new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", NetworkType.MIJIN_TEST));
    assertEquals("signature", aggregateTransactionCosignature.getSignature());
    assertEquals(new PublicAccount("9A49366406ACA952B88BADF5F1E9BE6CE4968141035A60BE503273EA65456B24", NetworkType.MIJIN_TEST), aggregateTransactionCosignature.getSigner());
}
Also used : PublicAccount(io.nem.sdk.model.account.PublicAccount) Test(org.junit.jupiter.api.Test)

Example 7 with PublicAccount

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

the class AggregateTransactionTest method shouldCreateAggregateTransactionAndSignWithMultipleCosignatories.

@Test
void shouldCreateAggregateTransactionAndSignWithMultipleCosignatories() {
    TransferTransaction transferTx = TransferTransaction.create(new FakeDeadline(), new Address("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", NetworkType.MIJIN_TEST), Arrays.asList(), new PlainMessage("test-message"), NetworkType.MIJIN_TEST);
    AggregateTransaction aggregateTx = AggregateTransaction.createComplete(new FakeDeadline(), Collections.singletonList(transferTx.toAggregate(new PublicAccount("B694186EE4AB0558CA4AFCFDD43B42114AE71094F5A1FC4A913FE9971CACD21D", NetworkType.MIJIN_TEST))), NetworkType.MIJIN_TEST);
    Account cosignatoryAccount = new Account("2a2b1f5d366a5dd5dc56c3c757cf4fe6c66e2787087692cf329d7a49a594658b", NetworkType.MIJIN_TEST);
    // TODO bug with private key
    Account cosignatoryAccount2 = new Account("b8afae6f4ad13a1b8aad047b488e0738a437c7389d4ff30c359ac068910c1d59", NetworkType.MIJIN_TEST);
    SignedTransaction signedTransaction = cosignatoryAccount.signTransactionWithCosignatories(aggregateTx, Arrays.asList(cosignatoryAccount2));
    assertEquals("2d010000", signedTransaction.getPayload().substring(0, 8));
    assertEquals("5100000051000000", signedTransaction.getPayload().substring(240, 256));
// assertEquals("039054419050B9837EFAB4BBE8A4B9BB32D812F9885C00D8FC1650E1420D000000746573742D6D65737361676568B3FBB18729C1FDE225C57F8CE080FA828F0067E451A3FD81FA628842B0B763", signedTransaction.getPayload().substring(320, 474));
}
Also used : PublicAccount(io.nem.sdk.model.account.PublicAccount) Account(io.nem.sdk.model.account.Account) Address(io.nem.sdk.model.account.Address) PublicAccount(io.nem.sdk.model.account.PublicAccount) Test(org.junit.jupiter.api.Test)

Example 8 with PublicAccount

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

the class AggregateTransactionTest method serialization.

@Test
@DisplayName("Serialization")
void serialization() {
    // Generated at nem2-library-js/test/transactions/RegisterNamespaceTransaction.spec.js
    byte[] expected = new byte[] { (byte) 209, 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, 65, 65, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 85, 0, 0, 0, 85, 0, 0, 0, (byte) 132, 107, 68, 57, 21, 69, 121, (byte) 165, (byte) 144, 59, 20, 89, (byte) 201, (byte) 207, 105, (byte) 203, (byte) 129, 83, (byte) 246, (byte) 208, 17, 10, 122, 14, (byte) 214, 29, (byte) 226, (byte) 154, (byte) 228, (byte) 129, 11, (byte) 242, 3, (byte) 144, 84, 65, (byte) 144, 80, (byte) 185, (byte) 131, 126, (byte) 250, (byte) 180, (byte) 187, (byte) 232, (byte) 164, (byte) 185, (byte) 187, 50, (byte) 216, 18, (byte) 249, (byte) 136, 92, 0, (byte) 216, (byte) 252, 22, 80, (byte) 225, 66, 1, 0, 1, 0, 41, (byte) 207, 95, (byte) 217, 65, (byte) 173, 37, (byte) 213, (byte) 128, (byte) 150, (byte) 152, 0, 0, 0, 0, 0 };
    TransferTransaction transferTx = TransferTransaction.create(new FakeDeadline(), new Address("SBILTA367K2LX2FEXG5TFWAS7GEFYAGY7QLFBYKC", NetworkType.MIJIN_TEST), Collections.singletonList(new Mosaic(XEM.MOSAICID, BigInteger.valueOf(10000000))), PlainMessage.Empty, NetworkType.MIJIN_TEST);
    AggregateTransaction aggregateTx = AggregateTransaction.createComplete(new FakeDeadline(), Collections.singletonList(transferTx.toAggregate(new PublicAccount("846B4439154579A5903B1459C9CF69CB8153F6D0110A7A0ED61DE29AE4810BF2", NetworkType.MIJIN_TEST))), NetworkType.MIJIN_TEST);
    byte[] actual = aggregateTx.generateBytes();
    assertArrayEquals(expected, actual);
}
Also used : Address(io.nem.sdk.model.account.Address) PublicAccount(io.nem.sdk.model.account.PublicAccount) Mosaic(io.nem.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 9 with PublicAccount

use of io.nem.sdk.model.account.PublicAccount 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 10 with PublicAccount

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

the class Listener method open.

/**
 * @return a {@link CompletableFuture} that resolves when the websocket connection is opened
 */
public CompletableFuture<Void> open() {
    HttpClient httpClient = Vertx.vertx().createHttpClient();
    CompletableFuture<Void> future = new CompletableFuture<>();
    if (this.webSocket != null) {
        return CompletableFuture.completedFuture(null);
    }
    RequestOptions requestOptions = new RequestOptions();
    requestOptions.setHost(this.url.getHost());
    requestOptions.setPort(this.url.getPort());
    requestOptions.setURI("/ws");
    httpClient.websocket(requestOptions, webSocket -> {
        this.webSocket = webSocket;
        webSocket.handler(handler -> {
            JsonObject message = handler.toJsonObject();
            if (message.containsKey("uid")) {
                this.UID = message.getString("uid");
                future.complete(null);
            } else if (message.containsKey("transaction")) {
                this.messageSubject.onNext(new ListenerMessage(ListenerChannel.rawValueOf(message.getJsonObject("meta").getString("channelName")), new TransactionMapping().apply(message)));
            } else if (message.containsKey("block")) {
                final JsonObject meta = message.getJsonObject("meta");
                final JsonObject block = message.getJsonObject("block");
                int rawNetworkType = (int) Long.parseLong(Integer.toHexString(block.getInteger("version")).substring(0, 2), 16);
                final NetworkType networkType;
                if (rawNetworkType == NetworkType.MIJIN_TEST.getValue())
                    networkType = NetworkType.MIJIN_TEST;
                else if (rawNetworkType == NetworkType.MIJIN.getValue())
                    networkType = NetworkType.MIJIN;
                else if (rawNetworkType == NetworkType.MAIN_NET.getValue())
                    networkType = NetworkType.MAIN_NET;
                else
                    networkType = NetworkType.TEST_NET;
                final int version = (int) Long.parseLong(Integer.toHexString(block.getInteger("version")).substring(2, 4), 16);
                this.messageSubject.onNext(new ListenerMessage(ListenerChannel.BLOCK, new BlockInfo(meta.getString("hash"), meta.getString("generationHash"), Optional.empty(), Optional.empty(), block.getString("signature"), new PublicAccount(block.getString("signer"), networkType), networkType, version, block.getInteger("type"), extractBigInteger(block.getJsonArray("height")), extractBigInteger(block.getJsonArray("timestamp")), extractBigInteger(block.getJsonArray("difficulty")), block.getString("previousBlockHash"), block.getString("blockTransactionsHash"))));
            } else if (message.containsKey("status")) {
                this.messageSubject.onNext(new ListenerMessage(ListenerChannel.STATUS, new TransactionStatusError(message.getString("hash"), message.getString("status"), new Deadline(extractBigInteger(message.getJsonArray("deadline"))))));
            } else if (message.containsKey("meta")) {
                this.messageSubject.onNext(new ListenerMessage(ListenerChannel.rawValueOf(message.getJsonObject("meta").getString("channelName")), message.getJsonObject("meta").getString("hash")));
            } else if (message.containsKey("parentHash")) {
                this.messageSubject.onNext(new ListenerMessage(ListenerChannel.COSIGNATURE, new CosignatureSignedTransaction(message.getString("parenthash"), message.getString("signature"), message.getString("signer"))));
            }
        });
    });
    return future;
}
Also used : RequestOptions(io.vertx.core.http.RequestOptions) JsonObject(io.vertx.core.json.JsonObject) CompletableFuture(java.util.concurrent.CompletableFuture) NetworkType(io.nem.sdk.model.blockchain.NetworkType) BlockInfo(io.nem.sdk.model.blockchain.BlockInfo) HttpClient(io.vertx.core.http.HttpClient) PublicAccount(io.nem.sdk.model.account.PublicAccount)

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