Search in sources :

Example 1 with AccountMetadataTransactionFactory

use of io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory in project nem2-sdk-java by nemtech.

the class AccountMetadataTransactionMapper method createFactory.

@Override
protected AccountMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountMetadataTransactionDTO transaction) {
    UnresolvedAddress targetAddress = toUnresolvedAddress(transaction.getTargetAddress());
    Integer valueSizeDelta = transaction.getValueSizeDelta();
    BigInteger scopedMetaDataKey = MapperUtils.fromHexToBigInteger(transaction.getScopedMetadataKey());
    byte[] value = ConvertUtils.fromHexToBytes(transaction.getValue());
    AccountMetadataTransactionFactory factory = AccountMetadataTransactionFactory.create(networkType, deadline, targetAddress, scopedMetaDataKey, value);
    factory.valueSizeDelta(valueSizeDelta);
    Long valueSize = transaction.getValueSize();
    if (valueSize != null) {
        factory.valueSize(valueSize);
    }
    return factory;
}
Also used : BigInteger(java.math.BigInteger) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) MapperUtils.toUnresolvedAddress(io.nem.symbol.core.utils.MapperUtils.toUnresolvedAddress) BigInteger(java.math.BigInteger) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory)

Example 2 with AccountMetadataTransactionFactory

use of io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory in project nem2-sdk-java by nemtech.

the class MetadataTransactionServiceTest method shouldCreateAccountMetadataTransactionFactory.

@Test
void shouldCreateAccountMetadataTransactionFactory() throws Exception {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String oldValue = "The original Message";
    String newValue = "the new Message";
    Metadata metadata = new Metadata("someId", 1, "compositeHash", sourceAddress, targetAccount.getAddress(), metadataKey, MetadataType.ACCOUNT, StringEncoder.getBytes(oldValue), null);
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetAddress(targetAccount.getAddress()).metadataType(MetadataType.ACCOUNT);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
    AccountMetadataTransactionFactory result = service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress).toFuture().get();
    Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
    Assertions.assertNotEquals(oldValue, StringEncoder.getString(result.getValue()));
    Assertions.assertNotEquals(newValue, StringEncoder.getString(result.getValue()));
    Assertions.assertEquals(StringEncoder.getBytes(newValue).length - StringEncoder.getBytes(oldValue).length, result.getValueSizeDelta());
    Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
    Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory) Page(io.nem.symbol.sdk.api.Page) Test(org.junit.jupiter.api.Test)

Example 3 with AccountMetadataTransactionFactory

use of io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory in project nem2-sdk-java by nemtech.

the class MetadataTransactionServiceTest method shouldCreateAccountMetadataTransactionFactoryWhenNotFound.

@Test
void shouldCreateAccountMetadataTransactionFactoryWhenNotFound() throws Exception {
    BigInteger metadataKey = BigInteger.valueOf(10);
    String newValue = "the new Message";
    MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetAddress(targetAccount.getAddress()).metadataType(MetadataType.ACCOUNT);
    Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.emptyList())));
    AccountMetadataTransactionFactory result = service.createAccountMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress).toFuture().get();
    Assertions.assertEquals(metadataKey, result.getScopedMetadataKey());
    Assertions.assertArrayEquals(StringEncoder.getBytes(newValue), result.getValue());
    Assertions.assertEquals(StringEncoder.getBytes(newValue).length, result.getValueSizeDelta());
    Assertions.assertEquals(targetAccount.getAddress(), result.getTargetAddress());
    Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) BigInteger(java.math.BigInteger) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory) Page(io.nem.symbol.sdk.api.Page) Test(org.junit.jupiter.api.Test)

Example 4 with AccountMetadataTransactionFactory

use of io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory in project nem2-sdk-java by nemtech.

the class AccountMetadataTransactionMapper method createFactory.

@Override
protected AccountMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountMetadataTransactionDTO transaction) {
    UnresolvedAddress targetAddress = MapperUtils.toUnresolvedAddress(transaction.getTargetAddress());
    Integer valueSizeDelta = transaction.getValueSizeDelta();
    BigInteger scopedMetaDataKey = MapperUtils.fromHexToBigInteger(transaction.getScopedMetadataKey());
    byte[] value = ConvertUtils.fromHexToBytes(transaction.getValue());
    AccountMetadataTransactionFactory factory = AccountMetadataTransactionFactory.create(networkType, deadline, targetAddress, scopedMetaDataKey, value);
    factory.valueSizeDelta(valueSizeDelta);
    Long valueSize = transaction.getValueSize();
    if (valueSize != null) {
        factory.valueSize(valueSize);
    }
    return factory;
}
Also used : BigInteger(java.math.BigInteger) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) BigInteger(java.math.BigInteger) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory)

Aggregations

AccountMetadataTransactionFactory (io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory)4 BigInteger (java.math.BigInteger)4 MetadataSearchCriteria (io.nem.symbol.sdk.api.MetadataSearchCriteria)2 Page (io.nem.symbol.sdk.api.Page)2 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)2 Test (org.junit.jupiter.api.Test)2 MapperUtils.toUnresolvedAddress (io.nem.symbol.core.utils.MapperUtils.toUnresolvedAddress)1 Metadata (io.nem.symbol.sdk.model.metadata.Metadata)1