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