Search in sources :

Example 26 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class MapperUtilsTest method toUnresolvedAddressFromNamespace.

@Test
void toUnresolvedAddressFromNamespace() {
    Assertions.assertNull(MapperUtils.toUnresolvedAddress(null));
    NamespaceId namespaceId = NamespaceId.createFromName("some.name");
    Assertions.assertEquals("91D9E338F78767ED95000000000000000000000000000000", namespaceId.encoded(networkType));
    Assertions.assertEquals(namespaceId.encoded(networkType), MapperUtils.toUnresolvedAddress(namespaceId.encoded(networkType)).encoded(networkType));
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Test(org.junit.jupiter.api.Test)

Example 27 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class NamespaceRepositoryOkHttpImpl method getNamespaceNames.

@Override
public Observable<List<NamespaceName>> getNamespaceNames(List<NamespaceId> namespaceIds) {
    NamespaceIds ids = new NamespaceIds().namespaceIds(namespaceIds.stream().map(NamespaceId::getIdAsHex).collect(Collectors.toList()));
    Callable<List<NamespaceNameDTO>> callback = () -> getClient().getNamespacesNames(ids);
    return exceptionHandling(call(callback).flatMapIterable(item -> item).map(this::toNamespaceName).toList().toObservable());
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) NamespaceIds(io.nem.symbol.sdk.openapi.okhttp_gson.model.NamespaceIds) MapperUtils.toNamespaceId(io.nem.symbol.core.utils.MapperUtils.toNamespaceId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 28 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class AddressAliasTransactionMapper method createFactory.

@Override
protected AddressAliasTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AddressAliasTransactionDTO transaction) {
    NamespaceId namespaceId = MapperUtils.toNamespaceId(transaction.getNamespaceId());
    AliasAction aliasAction = AliasAction.rawValueOf(transaction.getAliasAction().getValue().byteValue());
    return AddressAliasTransactionFactory.create(networkType, deadline, aliasAction, namespaceId, MapperUtils.toAddress(transaction.getAddress()));
}
Also used : AliasAction(io.nem.symbol.sdk.model.namespace.AliasAction) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId)

Example 29 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class TransferTransactionTest method serializeNamespaceTransaction.

@Test
void serializeNamespaceTransaction() {
    NamespaceId namespaceId = NamespaceId.createFromName("testaccount2");
    Assertions.assertEquals("E7CA7E22727DDD88", namespaceId.getIdAsHex());
    TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), namespaceId, Collections.singletonList(Currency.CAT_CURRENCY.createAbsolute(BigInteger.ONE))).message(new PlainMessage("test-message")).build();
    byte[] payload = transaction.serialize();
    String payloadHex = ConvertUtils.toHex(payload);
    TransferTransaction newTransaction = (TransferTransaction) new BinarySerializationImpl().deserialize(payload);
    String newPayloadHex = ConvertUtils.toHex(newTransaction.serialize());
    Assertions.assertEquals(transaction.getRecipient().encoded(networkType), newTransaction.getRecipient().encoded(networkType));
    Assertions.assertEquals(payloadHex, newPayloadHex);
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Example 30 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class NamespaceMetadataTransactionMapper method createFactory.

@Override
protected NamespaceMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, NamespaceMetadataTransactionDTO transaction) {
    UnresolvedAddress targetAddress = MapperUtils.toUnresolvedAddress(transaction.getTargetAddress());
    Integer valueSizeDelta = transaction.getValueSizeDelta();
    BigInteger scopedMetaDataKey = MapperUtils.fromHexToBigInteger(transaction.getScopedMetadataKey());
    byte[] value = ConvertUtils.fromHexToBytes(transaction.getValue());
    NamespaceId targetNamespace = MapperUtils.toNamespaceId(transaction.getTargetNamespaceId());
    NamespaceMetadataTransactionFactory factory = NamespaceMetadataTransactionFactory.create(networkType, deadline, targetAddress, targetNamespace, scopedMetaDataKey, value);
    factory.valueSizeDelta(valueSizeDelta);
    Long valueSize = transaction.getValueSize();
    if (valueSize != null) {
        factory.valueSize(valueSize);
    }
    return factory;
}
Also used : BigInteger(java.math.BigInteger) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory)

Aggregations

NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)70 Test (org.junit.jupiter.api.Test)37 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)18 BigInteger (java.math.BigInteger)17 Account (io.nem.symbol.sdk.model.account.Account)15 Address (io.nem.symbol.sdk.model.account.Address)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)10 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)9 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)8 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)7 Observable (io.reactivex.Observable)7 List (java.util.List)7 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)6 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 ArrayList (java.util.ArrayList)6