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);
}
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;
}
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());
}
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();
}
Aggregations