Search in sources :

Example 16 with NetworkType

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())));
}
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 17 with NetworkType

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;
}
Also used : TransactionDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionDTO) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline)

Example 18 with NetworkType

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));
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Test(org.junit.jupiter.api.Test)

Example 19 with 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;
}
Also used : TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline)

Example 20 with NetworkType

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);
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) RestrictionMosaicRepository(io.nem.symbol.sdk.api.RestrictionMosaicRepository) MosaicRestrictionTransactionService(io.nem.symbol.sdk.api.MosaicRestrictionTransactionService) MosaicRestrictionEntryType(io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType) MosaicRestrictionPaginationStreamer(io.nem.symbol.sdk.api.MosaicRestrictionPaginationStreamer) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MosaicRestrictionSearchCriteria(io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) MosaicGlobalRestrictionItem(io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem) MosaicRestrictionType(io.nem.symbol.sdk.model.transaction.MosaicRestrictionType) Duration(java.time.Duration) MosaicAddressRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransactionFactory) AliasService(io.nem.symbol.sdk.api.AliasService) Optional(java.util.Optional) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) MosaicGlobalRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory) MosaicAddressRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransactionFactory)

Aggregations

NetworkType (io.nem.symbol.sdk.model.network.NetworkType)31 Test (org.junit.jupiter.api.Test)13 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)11 BigInteger (java.math.BigInteger)10 Address (io.nem.symbol.sdk.model.account.Address)9 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)7 Account (io.nem.symbol.sdk.model.account.Account)5 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)5 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)5 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)5 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)5 Duration (java.time.Duration)5 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)4 List (java.util.List)4 Collectors (java.util.stream.Collectors)4 BinarySerializationImpl (io.nem.symbol.sdk.infrastructure.BinarySerializationImpl)3 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)3 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)3 Optional (java.util.Optional)3 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)2