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();
}
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);
}
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());
}
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);
}
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));
}
Aggregations