use of io.nem.symbol.sdk.model.network.NetworkType 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())));
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class AbstractTransactionMapper method createFactory.
protected final TransactionFactory<T> createFactory(TransactionInfo transactionInfo, Object transactionDto) {
D transaction = getJsonHelper().convert(transactionDto, transactionDtoClass);
TransactionDTO transactionDTO = getJsonHelper().convert(transactionDto, TransactionDTO.class);
NetworkType networkType = NetworkType.rawValueOf(transactionDTO.getNetwork().getValue());
Deadline deadline = transactionDTO.getDeadline() != null ? new Deadline(transactionDTO.getDeadline()) : new Deadline(BigInteger.ZERO);
TransactionFactory<T> factory = createFactory(networkType, deadline, transaction);
factory.version(transactionDTO.getVersion());
if (transactionDTO.getSignerPublicKey() != null) {
factory.signer(PublicAccount.createFromPublicKey(transactionDTO.getSignerPublicKey(), networkType));
}
if (transactionDTO.getSignature() != null) {
factory.signature(transactionDTO.getSignature());
}
if (transactionDTO.getMaxFee() != null) {
factory.maxFee(transactionDTO.getMaxFee());
}
if (transactionDTO.getSize() != null) {
factory.size(transactionDTO.getSize());
}
if (transactionInfo != null) {
factory.transactionInfo(transactionInfo);
}
if (factory.getType() != getTransactionType()) {
throw new IllegalStateException("Expected transaction to be " + getTransactionType() + " but got " + factory.getType());
}
return factory;
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class MapperUtilsTest method toUnresolvedAddress.
@Test
void toUnresolvedAddress() {
NetworkType networkType = NetworkType.TEST_NET;
System.out.println(networkType.getValue());
String hex = "9960629109A48AFBC0000000000000000000000000000000";
UnresolvedAddress value = MapperUtils.toUnresolvedAddress(hex);
Assertions.assertEquals("C0FB8AA409916260", ((NamespaceId) value).getIdAsHex());
Assertions.assertEquals(hex, ((NamespaceId) value).encoded(networkType));
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class BinarySerializationImpl method toTransactionFactory.
/**
* It converts a {@link TransactionBuilder} to a {@link Transaction}
*
* @param builder the builder
* @return the {@link Transaction} model.
*/
private TransactionFactory<?> toTransactionFactory(TransactionBuilder builder) {
TransactionType transactionType = TransactionType.rawValueOf(SerializationUtils.shortToUnsignedInt(builder.getType().getValue()));
NetworkType networkType = NetworkType.rawValueOf(SerializationUtils.byteToUnsignedInt(builder.getNetwork().getValue()));
Deadline deadline = new Deadline(SerializationUtils.toUnsignedBigInteger(builder.getDeadline().getTimestamp()));
TransactionFactory<?> factory = resolveSerializer(transactionType, builder.getVersion()).fromBodyBuilder(networkType, deadline, builder.getBody());
factory.version(SerializationUtils.byteToUnsignedInt(builder.getVersion()));
factory.maxFee(SerializationUtils.toUnsignedBigInteger(builder.getFee()));
if (!areAllZeros(builder.getSignature().getSignature().array())) {
factory.signature(SerializationUtils.toHexString(builder.getSignature().getSignature()));
}
if (!areAllZeros(builder.getSignerPublicKey().getKey().array())) {
factory.signer(SerializationUtils.toPublicAccount(builder.getSignerPublicKey(), networkType));
}
return factory;
}
use of io.nem.symbol.sdk.model.network.NetworkType in project nem2-sdk-java by nemtech.
the class MosaicRestrictionTransactionServiceImpl method createMosaicAddressRestrictionTransactionFactory.
@Override
public Observable<MosaicAddressRestrictionTransactionFactory> createMosaicAddressRestrictionTransactionFactory(UnresolvedMosaicId unresolvedMosaicId, BigInteger restrictionKey, UnresolvedAddress unresolvedTargetAddress, BigInteger restrictionValue) {
return Observable.combineLatest(networkTypeObservable, epochAdjustmentObservable, aliasService.resolveMosaicId(unresolvedMosaicId), aliasService.resolveAddress(unresolvedTargetAddress), (networkType, epochAdjustment, mosaicId, targetAddress) -> getGlobalRestrictionEntry(mosaicId, restrictionKey).flatMap(optional -> {
if (!optional.isPresent()) {
return Observable.error(new IllegalArgumentException("Global restriction is not valid for RestrictionKey: " + restrictionKey));
}
return getCurrentMosaicAddressRestrictionValue(mosaicId, targetAddress, restrictionKey).map(optionalValue -> {
MosaicAddressRestrictionTransactionFactory factory = MosaicAddressRestrictionTransactionFactory.create(networkType, Deadline.create(epochAdjustment), unresolvedMosaicId, restrictionKey, unresolvedTargetAddress, restrictionValue);
optionalValue.ifPresent(factory::previousRestrictionValue);
return factory;
});
})).flatMap(f -> f);
}
Aggregations