Search in sources :

Example 6 with TransactionStatusError

use of io.nem.symbol.sdk.model.transaction.TransactionStatusError 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 7 with TransactionStatusError

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

the class ListenerIntegrationTest method shouldReturnTransactionStatusGivenAddedViaListener.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void shouldReturnTransactionStatusGivenAddedViaListener(RepositoryType type) {
    Listener listener = getListener(type);
    SignedTransaction signedTransaction = this.announceStandaloneTransferTransactionWithInsufficientBalance(type);
    TransactionStatusError transactionHash = get(listener.status(this.account.getAddress(), signedTransaction.getHash()).take(1));
    assertEquals(signedTransaction.getHash(), transactionHash.getHash());
}
Also used : TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) Listener(io.nem.symbol.sdk.api.Listener) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

TransactionStatusError (io.nem.symbol.sdk.model.transaction.TransactionStatusError)7 ListenerSubscribeMessage (io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage)4 Account (io.nem.symbol.sdk.model.account.Account)4 HashMap (java.util.HashMap)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 Test (org.junit.jupiter.api.Test)4 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 JsonObject (com.google.gson.JsonObject)2 CosignatureSignedTransaction (io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction)2 Listener (io.nem.symbol.sdk.api.Listener)1 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)1 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)1 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)1 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)1 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)1 BigInteger (java.math.BigInteger)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1