Search in sources :

Example 16 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress 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 17 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class MosaicMetadataTransactionMapper method createFactory.

@Override
protected MosaicMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, MosaicMetadataTransactionDTO transaction) {
    UnresolvedAddress targetAddress = toUnresolvedAddress(transaction.getTargetAddress());
    Integer valueSizeDelta = transaction.getValueSizeDelta();
    BigInteger scopedMetaDataKey = MapperUtils.fromHexToBigInteger(transaction.getScopedMetadataKey());
    byte[] value = ConvertUtils.fromHexToBytes(transaction.getValue());
    UnresolvedMosaicId targetMosaic = MapperUtils.toUnresolvedMosaicId(transaction.getTargetMosaicId());
    MosaicMetadataTransactionFactory factory = MosaicMetadataTransactionFactory.create(networkType, deadline, targetAddress, targetMosaic, 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) MapperUtils.toUnresolvedAddress(io.nem.symbol.core.utils.MapperUtils.toUnresolvedAddress) BigInteger(java.math.BigInteger) MosaicMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 18 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress 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)

Example 19 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class SerializationUtils method fromUnresolvedAddressToByteBuffer.

/**
 * It serializes a {@link UnresolvedAddress} to an hex catbuffer understand.
 *
 * @param unresolvedAddress the {@link Address} or {@link NamespaceId} to be serialized.
 * @param networkType the network type to customize the {@link NamespaceId} serialization
 * @return the serialized {@link UnresolvedAddress} as {@link ByteBuffer}.
 */
public static ByteBuffer fromUnresolvedAddressToByteBuffer(UnresolvedAddress unresolvedAddress, NetworkType networkType) {
    Validate.notNull(unresolvedAddress, "unresolvedAddress must not be null");
    if (unresolvedAddress instanceof NamespaceId) {
        final ByteBuffer namespaceIdAlias = ByteBuffer.allocate(24);
        NamespaceId namespaceId = (NamespaceId) unresolvedAddress;
        final byte firstByte = (byte) (networkType.getValue() | 0x01);
        namespaceIdAlias.order(ByteOrder.LITTLE_ENDIAN);
        namespaceIdAlias.put(firstByte);
        namespaceIdAlias.putLong(namespaceId.getIdAsLong());
        return ByteBuffer.wrap(namespaceIdAlias.array());
    }
    if (unresolvedAddress instanceof Address) {
        return fromAddressToByteBuffer((Address) unresolvedAddress);
    }
    throw new IllegalArgumentException("Unexpected UnresolvedAddress type " + unresolvedAddress.getClass());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) ByteBuffer(java.nio.ByteBuffer)

Example 20 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class AccountAddressRestrictionTransactionMapper method createFactory.

@Override
protected AccountAddressRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountAddressRestrictionTransactionDTO transaction) {
    AccountAddressRestrictionFlags restrictionFlags = AccountAddressRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
    List<UnresolvedAddress> restrictionAdditions = transaction.getRestrictionAdditions().stream().map(MapperUtils::toUnresolvedAddress).collect(Collectors.toList());
    List<UnresolvedAddress> restrictionDeletions = transaction.getRestrictionDeletions().stream().map(MapperUtils::toUnresolvedAddress).collect(Collectors.toList());
    return AccountAddressRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, restrictionAdditions, restrictionDeletions);
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) AccountAddressRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionFlags)

Aggregations

UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)35 BigInteger (java.math.BigInteger)13 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)11 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)11 Test (org.junit.jupiter.api.Test)11 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)10 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)10 Address (io.nem.symbol.sdk.model.account.Address)8 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)8 ArrayList (java.util.ArrayList)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Account (io.nem.symbol.sdk.model.account.Account)7 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)7 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)7 Observable (io.reactivex.Observable)7 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)6 Listener (io.nem.symbol.sdk.api.Listener)5 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)5 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)5