Search in sources :

Example 1 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class ListenerIntegrationTest method getAllMultisigAddressesAndAliasesWhenBasic.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAllMultisigAddressesAndAliasesWhenBasic(RepositoryType type) {
    Account testAccount = this.helper().getTestAccount(type).getKey();
    Set<NamespaceId> cosignatoryAccount1aliases = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Collections.singletonList(testAccount.getAddress()))).stream().flatMap(a -> a.getNames().stream().map(NamespaceName::getNamespaceId)).collect(Collectors.toSet());
    Listener listener = getRepositoryFactory(type).createListener();
    final Set<UnresolvedAddress> unresolvedAddresses = get(listener.getAllMultisigAddressesAndAliases(testAccount.getAddress()));
    final Set<UnresolvedAddress> expectedAddresees = Sets.newSet(testAccount.getAddress());
    expectedAddresees.addAll(cosignatoryAccount1aliases);
    Assertions.assertEquals(expectedAddresees, unresolvedAddresses);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) Account(io.nem.symbol.sdk.model.account.Account) CompletableFuture(java.util.concurrent.CompletableFuture) EnumSource(org.junit.jupiter.params.provider.EnumSource) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) Disabled(org.junit.jupiter.api.Disabled) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) TestInstance(org.junit.jupiter.api.TestInstance) Sets(org.mockito.internal.util.collections.Sets) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Pair(org.apache.commons.lang3.tuple.Pair) TransactionService(io.nem.symbol.sdk.api.TransactionService) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Listener(io.nem.symbol.sdk.api.Listener) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Set(java.util.Set) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Account(io.nem.symbol.sdk.model.account.Account) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Listener(io.nem.symbol.sdk.api.Listener) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 2 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class MultisigRepositoryIntegrationTest method getMultisigAccountInfo.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMultisigAccountInfo(RepositoryType type) {
    Account multisigAccount = helper().getMultisigAccount(type).getLeft();
    Account cosignatoryAccount = config().getCosignatoryAccount();
    Account cosignatory2Account = config().getCosignatory2Account();
    System.out.println(multisigAccount.getAddress().plain());
    MultisigAccountInfo multisigAccountInfo = get(getRepositoryFactory(type).createMultisigRepository().getMultisigAccountInfo(multisigAccount.getAddress()));
    Set<UnresolvedAddress> cosignatoriesSet = new HashSet<>(multisigAccountInfo.getCosignatoryAddresses());
    Assertions.assertEquals(Sets.newSet(cosignatoryAccount.getAddress(), cosignatory2Account.getAddress()), cosignatoriesSet);
    Assertions.assertTrue(multisigAccountInfo.isMultisig());
    assertEquals(multisigAccount.getAddress(), multisigAccountInfo.getAccountAddress());
    Assertions.assertEquals(1, multisigAccountInfo.getMinApproval());
    Assertions.assertEquals(1, multisigAccountInfo.getMinRemoval());
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) HashSet(java.util.HashSet) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 3 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class ListenerBase method toStatus.

private TransactionStatusError toStatus(Object message, String channelParams) {
    UnresolvedAddress unresolvedAddress = getUnresolvedAddress(channelParams);
    String hash = jsonHelper.getString(message, "hash");
    String code = jsonHelper.getString(message, "code");
    Deadline deadline = new Deadline(new BigInteger(jsonHelper.getString(message, "deadline")));
    return (new TransactionStatusError(unresolvedAddress, hash, code, deadline));
}
Also used : TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) BigInteger(java.math.BigInteger)

Example 4 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class NamespaceMetadataTransactionMapper method createFactory.

@Override
protected NamespaceMetadataTransactionFactory createFactory(NetworkType networkType, Deadline deadline, NamespaceMetadataTransactionDTO transaction) {
    UnresolvedAddress targetAddress = MapperUtils.toUnresolvedAddress(transaction.getTargetAddress());
    Integer valueSizeDelta = transaction.getValueSizeDelta();
    BigInteger scopedMetaDataKey = MapperUtils.fromHexToBigInteger(transaction.getScopedMetadataKey());
    byte[] value = ConvertUtils.fromHexToBytes(transaction.getValue());
    NamespaceId targetNamespace = MapperUtils.toNamespaceId(transaction.getTargetNamespaceId());
    NamespaceMetadataTransactionFactory factory = NamespaceMetadataTransactionFactory.create(networkType, deadline, targetAddress, targetNamespace, 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) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory)

Example 5 with UnresolvedAddress

use of io.nem.symbol.sdk.model.account.UnresolvedAddress in project nem2-sdk-java by nemtech.

the class ListenerIntegrationTest method getAllMultisigAddressesAndAliasesWhenCosign.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAllMultisigAddressesAndAliasesWhenCosign(RepositoryType type) {
    final MultisigAccountInfo multisigAccountInfo = get(getRepositoryFactory(type).createMultisigRepository().getMultisigAccountInfo(this.multisigAccount.getAddress()));
    Assertions.assertEquals(Arrays.asList(this.cosignatoryAccount.getAddress(), this.cosignatoryAccount2.getAddress()), multisigAccountInfo.getCosignatoryAddresses());
    Set<NamespaceId> aliases = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Arrays.asList(cosignatoryAccount.getAddress()))).stream().flatMap(a -> a.getNames().stream().map(n -> n.getNamespaceId())).collect(Collectors.toSet());
    Listener listener = getRepositoryFactory(type).createListener();
    final Set<UnresolvedAddress> unresolvedAddresses = get(listener.getAllMultisigAddressesAndAliases(this.cosignatoryAccount.getAddress()));
    final Set<UnresolvedAddress> expectedAddresees = Sets.newSet(this.cosignatoryAccount.getAddress());
    expectedAddresees.addAll(aliases);
    Assertions.assertEquals(expectedAddresees, unresolvedAddresses);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) Account(io.nem.symbol.sdk.model.account.Account) CompletableFuture(java.util.concurrent.CompletableFuture) EnumSource(org.junit.jupiter.params.provider.EnumSource) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) Disabled(org.junit.jupiter.api.Disabled) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) TestInstance(org.junit.jupiter.api.TestInstance) Sets(org.mockito.internal.util.collections.Sets) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Pair(org.apache.commons.lang3.tuple.Pair) TransactionService(io.nem.symbol.sdk.api.TransactionService) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Listener(io.nem.symbol.sdk.api.Listener) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Set(java.util.Set) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Listener(io.nem.symbol.sdk.api.Listener) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)35 BigInteger (java.math.BigInteger)13 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)11 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)11 Test (org.junit.jupiter.api.Test)11 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)10 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)10 Address (io.nem.symbol.sdk.model.account.Address)8 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)8 ArrayList (java.util.ArrayList)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Account (io.nem.symbol.sdk.model.account.Account)7 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)7 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)7 Observable (io.reactivex.Observable)7 MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)6 EnumSource (org.junit.jupiter.params.provider.EnumSource)6 Listener (io.nem.symbol.sdk.api.Listener)5 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)5 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)5