Search in sources :

Example 1 with MosaicAddressRestrictionTransactionFactory

use of io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransactionFactory 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

AliasService (io.nem.symbol.sdk.api.AliasService)1 MosaicRestrictionPaginationStreamer (io.nem.symbol.sdk.api.MosaicRestrictionPaginationStreamer)1 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)1 MosaicRestrictionTransactionService (io.nem.symbol.sdk.api.MosaicRestrictionTransactionService)1 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)1 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)1 Address (io.nem.symbol.sdk.model.account.Address)1 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)1 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)1 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)1 MosaicGlobalRestrictionItem (io.nem.symbol.sdk.model.restriction.MosaicGlobalRestrictionItem)1 MosaicRestrictionEntryType (io.nem.symbol.sdk.model.restriction.MosaicRestrictionEntryType)1 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)1 MosaicAddressRestrictionTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicAddressRestrictionTransactionFactory)1 MosaicGlobalRestrictionTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory)1 MosaicRestrictionType (io.nem.symbol.sdk.model.transaction.MosaicRestrictionType)1 Observable (io.reactivex.Observable)1 BigInteger (java.math.BigInteger)1 Duration (java.time.Duration)1