Search in sources :

Example 6 with CosignatureSignedTransaction

use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.

the class ListenerVertxTest method cosignatureAdded.

@Test
public void cosignatureAdded() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    ListenerChannel consignature = ListenerChannel.COSIGNATURE;
    NetworkType networkType = NETWORK_TYPE;
    Cosignature cosignature = new Cosignature().parentHash("aParentHash").signature("aSignature").version(BigInteger.ONE).signerPublicKey(Account.generateNewAccount(networkType).getPublicKey());
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(cosignature, ObjectNode.class);
    Address address = Address.createFromPublicKey(cosignature.getSignerPublicKey(), networkType);
    String channelName = consignature.toString();
    List<CosignatureSignedTransaction> transactions = new ArrayList<>();
    listener.cosignatureAdded(address).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, consignature.toString() + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(cosignature.getSignerPublicKey(), transactions.get(0).getSigner().getPublicKey().toHex());
    Assertions.assertEquals(cosignature.getParentHash(), transactions.get(0).getParentHash());
    Assertions.assertEquals(cosignature.getSignature(), transactions.get(0).getSignature());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
Also used : CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ListenerChannel(io.nem.symbol.sdk.infrastructure.ListenerChannel) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) ArrayList(java.util.ArrayList) Cosignature(io.nem.symbol.sdk.openapi.vertx.model.Cosignature) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 7 with CosignatureSignedTransaction

use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.

the class TransactionRepositoryOkHttpImplTest method announceAggregateBondedCosignature.

@Test
public void announceAggregateBondedCosignature() throws Exception {
    Account signer = Account.generateNewAccount(networkType);
    BigInteger version = AggregateTransactionCosignature.DEFAULT_VERSION;
    CosignatureSignedTransaction signedTransaction = new CosignatureSignedTransaction(version, "aParentHash", "aSignature", signer.getPublicAccount());
    AnnounceTransactionInfoDTO announceTransactionInfoDTO = new AnnounceTransactionInfoDTO();
    announceTransactionInfoDTO.setMessage("SomeMessage");
    ArgumentCaptor<Object> parameter = mockRemoteCall(announceTransactionInfoDTO);
    TransactionAnnounceResponse response = repository.announceAggregateBondedCosignature(signedTransaction).toFuture().get();
    Assertions.assertNotNull(response);
    Assertions.assertEquals(announceTransactionInfoDTO.getMessage(), announceTransactionInfoDTO.getMessage());
    Cosignature cosignature = (Cosignature) parameter.getValue();
    Assertions.assertEquals(signedTransaction.getParentHash(), cosignature.getParentHash());
    Assertions.assertEquals(signedTransaction.getSignature(), cosignature.getSignature());
    Assertions.assertEquals(signedTransaction.getSigner().getPublicKey().toHex(), cosignature.getSignerPublicKey());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) BigInteger(java.math.BigInteger) AnnounceTransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AnnounceTransactionInfoDTO) TransactionAnnounceResponse(io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse) Cosignature(io.nem.symbol.sdk.openapi.okhttp_gson.model.Cosignature) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) Test(org.junit.jupiter.api.Test)

Example 8 with CosignatureSignedTransaction

use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.

the class ListenerBase method createListenerMessage.

/**
 * It create the ListenerMessage for the message subject.
 *
 * @param wsPayload the generic json with the wsPayload.
 */
private Observable<ListenerMessage<?>> createListenerMessage(Object wsPayload) {
    String topic = jsonHelper.getString(wsPayload, "topic");
    Validate.notNull(topic, "Topic must be included in the WebSocket payload!");
    ListenerChannel channel = ListenerChannel.rawValueOf(StringUtils.substringBefore(topic, "/"));
    String channelParams = StringUtils.substringAfter(topic, "/");
    Object message = jsonHelper.getObject(wsPayload, "data");
    Validate.notNull(message, "Data must be included in the WebSocket payload!");
    switch(channel) {
        case CONFIRMED_ADDED:
        case UNCONFIRMED_ADDED:
        case AGGREGATE_BONDED_ADDED:
            final Transaction transaction = toTransaction(toGroup(channel), message);
            final String transactionHash = transaction.getTransactionInfo().get().getHash().get();
            return Observable.just(new ListenerMessage<>(topic, channel, channelParams, transaction, transactionHash));
        case BLOCK:
            return Observable.just(new ListenerMessage<>(topic, channel, channelParams, toBlockInfo(message), null));
        case FINALIZED_BLOCK:
            return Observable.just(new ListenerMessage<>(topic, channel, channelParams, toFinalizedBlock(message), null));
        case STATUS:
            final TransactionStatusError status = toStatus(message, channelParams);
            return Observable.just(new ListenerMessage<>(topic, channel, channelParams, status, status.getHash()));
        case COSIGNATURE:
            return networkTypeObservable.map(networkType -> {
                final CosignatureSignedTransaction cosignature = toCosignatureSignedTransaction(message, networkType);
                return new ListenerMessage<>(topic, channel, channelParams, cosignature, cosignature.getParentHash());
            });
        case AGGREGATE_BONDED_REMOVED:
        case UNCONFIRMED_REMOVED:
            final String hash = jsonHelper.getString(message, "meta", "hash");
            return Observable.just(new ListenerMessage<>(topic, channel, channelParams, hash, hash));
        default:
            throw new IllegalArgumentException("Channel " + channel + "is not supported.");
    }
}
Also used : TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)

Example 9 with CosignatureSignedTransaction

use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.

the class ListenerOkHttpTest method cosignatureAdded.

@Test
public void cosignatureAdded() throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    Cosignature cosignature = new Cosignature().parentHash("aParentHash").signature("aSignature").version(BigInteger.ONE).signerPublicKey(Account.generateNewAccount(networkType).getPublicKey());
    JsonObject transactionInfoDtoJsonObject = jsonHelper.convert(cosignature, JsonObject.class);
    Address address = Address.createFromPublicKey(cosignature.getSignerPublicKey(), networkType);
    String channelName = ListenerChannel.COSIGNATURE.toString();
    List<CosignatureSignedTransaction> transactions = new ArrayList<>();
    listener.cosignatureAdded(address).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(cosignature.getSignerPublicKey(), transactions.get(0).getSigner().getPublicKey().toHex());
    Assertions.assertEquals(cosignature.getParentHash(), transactions.get(0).getParentHash());
    Assertions.assertEquals(cosignature.getSignature(), transactions.get(0).getSignature());
    Mockito.verify(webSocketMock).send(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
}
Also used : CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Address(io.nem.symbol.sdk.model.account.Address) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Cosignature(io.nem.symbol.sdk.openapi.okhttp_gson.model.Cosignature) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Test(org.junit.jupiter.api.Test)

Example 10 with CosignatureSignedTransaction

use of io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction in project nem2-sdk-java by nemtech.

the class ListenerIntegrationTest method announceCosignatureTransaction.

private CosignatureSignedTransaction announceCosignatureTransaction(AggregateTransaction transactionToCosign, RepositoryType type) {
    CosignatureTransaction cosignatureTransaction = new CosignatureTransaction(transactionToCosign);
    CosignatureSignedTransaction cosignatureSignedTransaction = this.cosignatoryAccount2.signCosignatureTransaction(cosignatureTransaction);
    get(getRepositoryFactory(type).createTransactionRepository().announceAggregateBondedCosignature(cosignatureSignedTransaction));
    return cosignatureSignedTransaction;
}
Also used : CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction)

Aggregations

CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)11 Test (org.junit.jupiter.api.Test)6 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)5 CosignatureTransaction (io.nem.symbol.sdk.model.transaction.CosignatureTransaction)5 Account (io.nem.symbol.sdk.model.account.Account)3 Address (io.nem.symbol.sdk.model.account.Address)3 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)3 BigInteger (java.math.BigInteger)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 Listener (io.nem.symbol.sdk.api.Listener)2 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)2 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)2 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)2 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)2 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)2 AggregateTransactionCosignature (io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)2 TransactionAnnounceResponse (io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse)2 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)2