Search in sources :

Example 1 with MultisigAccountInfo

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

the class AggregateTransactionServiceImpl method isComplete.

@Override
public Observable<Boolean> isComplete(SignedTransaction signedTransaction) {
    Validate.notNull(signedTransaction, "signedTransaction is required");
    Validate.isTrue(signedTransaction.getType() == TransactionType.AGGREGATE_COMPLETE, "signedTransaction type must be AGGREGATE_COMPLETE");
    AggregateTransaction transaction = (AggregateTransaction) BinarySerializationImpl.INSTANCE.deserialize(ConvertUtils.fromHexToBytes(signedTransaction.getPayload()));
    /*
     * Include both initiator & cosigners
     */
    Set<Address> signers = transaction.getCosignatures().stream().map(AggregateTransactionCosignature::getSigner).map(PublicAccount::getAddress).collect(Collectors.toSet());
    signers.add(signedTransaction.getSigner().getAddress());
    return Observable.fromIterable(transaction.getInnerTransactions()).flatMap(innerTransaction -> multisigRepository.getMultisigAccountInfo(innerTransaction.getSigner().orElseThrow(IllegalArgumentException::new).getAddress()).flatMap(multisigAccountInfo -> multisigAccountInfo.getMinRemoval() != 0 && multisigAccountInfo.getMinApproval() != 0 ? multisigRepository.getMultisigAccountGraphInfo(multisigAccountInfo.getAccountAddress()).map(graphInfo -> validateCosignatories(graphInfo, signers, innerTransaction)) : Observable.just(signers.stream().anyMatch(s -> s.equals(multisigAccountInfo.getAccountAddress()))))).all(v -> v).toObservable();
}
Also used : MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) Set(java.util.Set) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) Collectors(java.util.stream.Collectors) MultisigAccountGraphInfo(io.nem.symbol.sdk.model.account.MultisigAccountGraphInfo) HashSet(java.util.HashSet) List(java.util.List) Stream(java.util.stream.Stream) Validate(org.apache.commons.lang3.Validate) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TreeMap(java.util.TreeMap) MultisigRepository(io.nem.symbol.sdk.api.MultisigRepository) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Map(java.util.Map) NetworkRepository(io.nem.symbol.sdk.api.NetworkRepository) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) Observable(io.reactivex.Observable) Address(io.nem.symbol.sdk.model.account.Address) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AggregateTransactionService(io.nem.symbol.sdk.api.AggregateTransactionService) Address(io.nem.symbol.sdk.model.account.Address) AggregateTransactionCosignature(io.nem.symbol.sdk.model.transaction.AggregateTransactionCosignature) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction)

Example 2 with MultisigAccountInfo

use of io.nem.symbol.sdk.model.account.MultisigAccountInfo 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)

Example 3 with MultisigAccountInfo

use of io.nem.symbol.sdk.model.account.MultisigAccountInfo 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 4 with MultisigAccountInfo

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

the class MultisigRepositoryVertxImplTest method getMultisigAccountInfo.

@Test
void getMultisigAccountInfo() throws Exception {
    MultisigAccountInfoDTO dto = createMultisigAccountInfoDTO();
    mockRemoteCall(dto);
    MultisigAccountInfo multisigAccountInfo = repository.getMultisigAccountInfo(account.getAddress()).toFuture().get();
    assertMultisignAccountInfo(multisigAccountInfo);
}
Also used : MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) MultisigAccountInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.MultisigAccountInfoDTO) Test(org.junit.jupiter.api.Test)

Example 5 with MultisigAccountInfo

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

the class MultisigRepositoryOkHttpImplTest method getMultisigAccountGraphInfo.

@Test
void getMultisigAccountGraphInfo() throws Exception {
    MultisigAccountGraphInfoDTO dto = new MultisigAccountGraphInfoDTO();
    dto.setLevel(10);
    dto.setMultisigEntries(new ArrayList<>());
    dto.getMultisigEntries().add(createMultisigAccountInfoDTO());
    List<MultisigAccountGraphInfoDTO> dtos = new ArrayList<>();
    dtos.add(dto);
    mockRemoteCall(dtos);
    MultisigAccountGraphInfo multisigAccountInfo = repository.getMultisigAccountGraphInfo(account.getAddress()).toFuture().get();
    Assertions.assertEquals(1, multisigAccountInfo.getMultisigEntries().size());
    List<MultisigAccountInfo> multisigAccountInfos = multisigAccountInfo.getMultisigEntries().get(10);
    Assertions.assertEquals(1, multisigAccountInfos.size());
    assertMultisignAccountInfo(multisigAccountInfos.get(0));
}
Also used : MultisigAccountGraphInfo(io.nem.symbol.sdk.model.account.MultisigAccountGraphInfo) ArrayList(java.util.ArrayList) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) MultisigAccountGraphInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.MultisigAccountGraphInfoDTO) Test(org.junit.jupiter.api.Test)

Aggregations

MultisigAccountInfo (io.nem.symbol.sdk.model.account.MultisigAccountInfo)16 Test (org.junit.jupiter.api.Test)9 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)7 Account (io.nem.symbol.sdk.model.account.Account)6 MultisigRepository (io.nem.symbol.sdk.api.MultisigRepository)5 Address (io.nem.symbol.sdk.model.account.Address)5 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)5 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)5 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)5 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)5 List (java.util.List)5 MultisigAccountGraphInfo (io.nem.symbol.sdk.model.account.MultisigAccountGraphInfo)4 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)4 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)4 Observable (io.reactivex.Observable)4 Set (java.util.Set)4 Collectors (java.util.stream.Collectors)4 Listener (io.nem.symbol.sdk.api.Listener)3 RepositoryCallException (io.nem.symbol.sdk.api.RepositoryCallException)3 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)3