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.");
}
}
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());
}
Aggregations