Search in sources :

Example 81 with MosaicId

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);
}
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 82 with MosaicId

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);
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 83 with MosaicId

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());
}
Also used : Address(io.nem.symbol.sdk.model.account.Address) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ArrayList(java.util.ArrayList) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) BinarySerializationImpl(io.nem.symbol.sdk.infrastructure.BinarySerializationImpl) Test(org.junit.jupiter.api.Test)

Example 84 with MosaicId

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);
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Mosaic(io.nem.symbol.sdk.model.mosaic.Mosaic) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 85 with MosaicId

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());
}
Also used : MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) SecretLockEntryDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.SecretLockEntryDTO)

Aggregations

MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)138 Test (org.junit.jupiter.api.Test)92 Address (io.nem.symbol.sdk.model.account.Address)53 BigInteger (java.math.BigInteger)53 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 EnumSource (org.junit.jupiter.params.provider.EnumSource)23 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)19 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)18 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)17 Account (io.nem.symbol.sdk.model.account.Account)16 MosaicInfo (io.nem.symbol.sdk.model.mosaic.MosaicInfo)15 ArrayList (java.util.ArrayList)13 MosaicRestrictionSearchCriteria (io.nem.symbol.sdk.api.MosaicRestrictionSearchCriteria)12 RestrictionMosaicRepository (io.nem.symbol.sdk.api.RestrictionMosaicRepository)10 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)10 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)10 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)7 Currency (io.nem.symbol.sdk.model.mosaic.Currency)7 MosaicNames (io.nem.symbol.sdk.model.mosaic.MosaicNames)7 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)7