Search in sources :

Example 6 with UnresolvedMosaicId

use of io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId 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 7 with UnresolvedMosaicId

use of io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId in project nem2-sdk-java by nemtech.

the class MosaicMetadataTransactionMapper method createFactory.

@Override
protected MosaicMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, MosaicMetadataTransactionDTO transaction) {
    UnresolvedAddress targetAccount = MapperUtils.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, targetAccount, 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) BigInteger(java.math.BigInteger) MosaicMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 8 with UnresolvedMosaicId

use of io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId in project nem2-sdk-java by nemtech.

the class AccountRestrictionIntegrationTest method sendAccountRestrictionMosaic.

private void sendAccountRestrictionMosaic(RepositoryType type, UnresolvedMosaicId unresolvedMosaicId, boolean add, AccountMosaicRestrictionFlags accountRestrictionFlags) {
    List<UnresolvedMosaicId> additions = add ? Collections.singletonList(unresolvedMosaicId) : Collections.emptyList();
    List<UnresolvedMosaicId> deletions = !add ? Collections.singletonList(unresolvedMosaicId) : Collections.emptyList();
    AccountMosaicRestrictionTransaction transaction = AccountMosaicRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), accountRestrictionFlags, additions, deletions).maxFee(maxFee).build();
    AccountMosaicRestrictionTransaction processedTransaction = announceAndValidate(type, testAccount, transaction);
    Assertions.assertEquals(accountRestrictionFlags, processedTransaction.getRestrictionFlags());
    Assertions.assertEquals(additions, processedTransaction.getRestrictionAdditions());
    Assertions.assertEquals(deletions, processedTransaction.getRestrictionDeletions());
}
Also used : AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 9 with UnresolvedMosaicId

use of io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId in project nem2-sdk-java by nemtech.

the class ResolutionStatement method serialize.

/**
 * Serializes the statement using the catuffer builders
 *
 * @param networkType the network type.
 * @return the serialized content.
 */
private byte[] serialize(NetworkType networkType) {
    ReceiptType type = this.resolutionType == ResolutionType.ADDRESS ? ReceiptType.ADDRESS_ALIAS_RESOLUTION : ReceiptType.MOSAIC_ALIAS_RESOLUTION;
    ReceiptTypeDto recipientTypeDto = ReceiptTypeDto.rawValueOf((short) type.getValue());
    short version = (short) ReceiptVersion.RESOLUTION_STATEMENT.getValue();
    Serializer serializer = this.resolutionType == ResolutionType.ADDRESS ? AddressResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedAddress((UnresolvedAddress) this.unresolved, networkType), this.resolutionEntries.stream().map((entry) -> AddressResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toAddressDto((Address) entry.getResolved()))).collect(Collectors.toList())) : MosaicResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedMosaicIdDto((UnresolvedMosaicId) this.unresolved), this.resolutionEntries.stream().map((entry) -> MosaicResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toMosaicIdDto((MosaicId) entry.getResolved()))).collect(Collectors.toList()));
    return serializer.serialize();
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicResolutionStatementBuilder(io.nem.symbol.catapult.builders.MosaicResolutionStatementBuilder) Hashes(io.nem.symbol.core.crypto.Hashes) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptSourceBuilder(io.nem.symbol.catapult.builders.ReceiptSourceBuilder) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Collectors(java.util.stream.Collectors) Stored(io.nem.symbol.sdk.model.Stored) AddressResolutionStatementBuilder(io.nem.symbol.catapult.builders.AddressResolutionStatementBuilder) MosaicResolutionEntryBuilder(io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder) Serializer(io.nem.symbol.catapult.builders.Serializer) List(java.util.List) AddressResolutionEntryBuilder(io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) SerializationUtils(io.nem.symbol.sdk.infrastructure.SerializationUtils) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Serializer(io.nem.symbol.catapult.builders.Serializer)

Aggregations

UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)9 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)4 BigInteger (java.math.BigInteger)4 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)3 Address (io.nem.symbol.sdk.model.account.Address)2 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)2 AccountMosaicRestrictionFlags (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags)2 MosaicMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory)2 Optional (java.util.Optional)2 AddressResolutionEntryBuilder (io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder)1 AddressResolutionStatementBuilder (io.nem.symbol.catapult.builders.AddressResolutionStatementBuilder)1 MosaicResolutionEntryBuilder (io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder)1 MosaicResolutionStatementBuilder (io.nem.symbol.catapult.builders.MosaicResolutionStatementBuilder)1 ReceiptSourceBuilder (io.nem.symbol.catapult.builders.ReceiptSourceBuilder)1 ReceiptTypeDto (io.nem.symbol.catapult.builders.ReceiptTypeDto)1 Serializer (io.nem.symbol.catapult.builders.Serializer)1 Hashes (io.nem.symbol.core.crypto.Hashes)1 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 MapperUtils.toUnresolvedAddress (io.nem.symbol.core.utils.MapperUtils.toUnresolvedAddress)1 AliasService (io.nem.symbol.sdk.api.AliasService)1