use of io.nem.symbol.sdk.model.mosaic.MosaicId 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.MosaicId in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serialization.
@Test
@DisplayName("Serialization-public")
void serialization() {
String expected = "D400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F200000000019054410000000000000000010000000000000090F36CA680C35D630662A0C38DC89D4978D10B511B3D241A1400020000000000671305C6390B00002C01000000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
Mosaic mosaicId1 = new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100));
Mosaic mosaicId2 = new Mosaic(new MosaicId(new BigInteger("12342763262823")), BigInteger.valueOf(300));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), Arrays.asList(mosaicId1, mosaicId2)).message(new PlainMessage("Some Message 漢字")).signer(account.getPublicAccount()).build();
assertSerialization(expected, transaction);
String embeddedExpected = "84000000000000002134E47AEE6F2392A5B3D1238CD7714EABEB739361B7CCF24BAE127F10DF17F2000000000190544190F36CA680C35D630662A0C38DC89D4978D10B511B3D241A1400020000000000671305C6390B00002C01000000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
assertEmbeddedSerialization(embeddedExpected, transaction);
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method mosaicArrayToBeSortedHex.
@Test
void mosaicArrayToBeSortedHex() {
ArrayList<Mosaic> mosaics = new ArrayList<>();
mosaics.add(new Mosaic(new MosaicId("D525AD41D95FCF29"), BigInteger.valueOf(1)));
mosaics.add(new Mosaic(new MosaicId("77A1969932D987D7"), BigInteger.valueOf(2)));
mosaics.add(new Mosaic(new MosaicId("67F2B76F28BD36BA"), BigInteger.valueOf(3)));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), new Address("SDZWZJUAYNOWGBTCUDBY3SE5JF4NCC2RDM6SIGQ", networkType), mosaics).message(new PlainMessage("")).build();
assertEquals("D525AD41D95FCF29", mosaics.get(0).getId().getIdAsHex().toUpperCase());
assertEquals("77A1969932D987D7", mosaics.get(1).getId().getIdAsHex().toUpperCase());
assertEquals("67F2B76F28BD36BA", mosaics.get(2).getId().getIdAsHex().toUpperCase());
TransferTransaction deserialized = (TransferTransaction) new BinarySerializationImpl().deserialize(transaction.serialize());
assertEquals(mosaics.get(2).getId(), deserialized.getMosaics().get(0).getId());
assertEquals(mosaics.get(1).getId(), deserialized.getMosaics().get(1).getId());
assertEquals(mosaics.get(0).getId(), deserialized.getMosaics().get(2).getId());
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class TransferTransactionTest method serializationNamespaceRecipient.
@Test
@DisplayName("Serialization-public-namespace-recipient")
void serializationNamespaceRecipient() {
String expected = "C4000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001905441000000000000000001000000000000009151776168D24257D80000000000000000000000000000001400010000000000672B0000CE560000640000000000000000536F6D65204D65737361676520E6BCA2E5AD97";
NamespaceId recipient = NamespaceId.createFromName("nem.owner");
Assertions.assertEquals("D85742D268617751", recipient.getIdAsHex());
Assertions.assertEquals("9151776168D24257D8000000000000000000000000000000", recipient.encoded(networkType));
TransferTransaction transaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), recipient, Collections.singletonList(new Mosaic(new MosaicId(new BigInteger("95442763262823")), BigInteger.valueOf(100)))).message(new PlainMessage("Some Message 漢字")).build();
Assertions.assertEquals(recipient.encoded(networkType), transaction.getRecipient().encoded(networkType));
assertSerialization(expected, transaction);
}
use of io.nem.symbol.sdk.model.mosaic.MosaicId in project nem2-sdk-java by nemtech.
the class SecretLockRepositoryOkHttpImpl method toSecretLockInfo.
private SecretLockInfo toSecretLockInfo(SecretLockInfoDTO dto) {
SecretLockEntryDTO lock = dto.getLock();
MosaicId mosaicId = MapperUtils.toMosaicId(lock.getMosaicId());
return new SecretLockInfo(dto.getId(), ObjectUtils.defaultIfNull(dto.getLock().getVersion(), 1), MapperUtils.toAddress(lock.getOwnerAddress()), mosaicId, lock.getAmount(), lock.getEndHeight(), LockStatus.rawValueOf(lock.getStatus().getValue().byteValue()), LockHashAlgorithm.rawValueOf(lock.getHashAlgorithm().getValue()), lock.getSecret(), MapperUtils.toAddress(lock.getRecipientAddress()), lock.getCompositeHash());
}
Aggregations