use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class ReceiptRepositoryOkHttpImpl method searchAddressResolutionStatements.
@Override
public Observable<Page<AddressResolutionStatement>> searchAddressResolutionStatements(ResolutionStatementSearchCriteria criteria) {
BigInteger height = criteria.getHeight();
Integer pageSize = criteria.getPageSize();
Integer pageNumber = criteria.getPageNumber();
String offset = criteria.getOffset();
Order order = toDto(criteria.getOrder());
Callable<ResolutionStatementPage> callback = () -> getClient().searchAddressResolutionStatements(height, pageSize, pageNumber, offset, order);
return exceptionHandling(call(callback).map(page -> this.toPage(page.getPagination(), page.getData().stream().map(mapper::createAddressResolutionStatementFromDto).collect(Collectors.toList()))));
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class TestHelper method createMultisigAccountBonded.
public MultisigAccountInfo createMultisigAccountBonded(RepositoryType type, Account multisigAccount, Account... accounts) {
AccountRepository accountRepository = getRepositoryFactory(type).createAccountRepository();
MultisigRepository multisigRepository = getRepositoryFactory(type).createMultisigRepository();
AccountInfo accountInfo = get(accountRepository.getAccountInfo(multisigAccount.getAddress()));
System.out.println(getJsonHelper().print(accountInfo));
if (isMultisig(type, multisigAccount)) {
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " already exist");
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
System.out.println("Multisig account with address " + multisigAccount.getAddress().plain() + " does not exist. Creating");
System.out.println("Creating multisg account " + multisigAccount.getAddress().plain());
List<UnresolvedAddress> additions = Arrays.stream(accounts).map(Account::getAddress).collect(Collectors.toList());
MultisigAccountModificationTransaction convertIntoMultisigTransaction = MultisigAccountModificationTransactionFactory.create(getNetworkType(), getDeadline(), (byte) 1, (byte) 1, additions, Collections.emptyList()).maxFee(maxFee).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createBonded(getNetworkType(), getDeadline(), Collections.singletonList(convertIntoMultisigTransaction.toAggregate(multisigAccount.getPublicAccount()))).maxFee(maxFee).build();
SignedTransaction signedAggregateTransaction = aggregateTransaction.signTransactionWithCosigners(multisigAccount, Arrays.asList(accounts), getGenerationHash());
Mosaic hashAmount = getCurrency().createRelative(BigInteger.valueOf(10));
HashLockTransaction hashLockTransaction = HashLockTransactionFactory.create(getNetworkType(), getDeadline(), hashAmount, BigInteger.valueOf(100), signedAggregateTransaction).maxFee(maxFee).build();
SignedTransaction signedHashLockTransaction = hashLockTransaction.signWith(multisigAccount, getGenerationHash());
getTransactionOrFail(getTransactionService(type).announceHashLockAggregateBonded(getListener(type), signedHashLockTransaction, signedAggregateTransaction), aggregateTransaction);
HashLockRepository hashLockRepository = getRepositoryFactory(type).createHashLockRepository();
HashLockInfo hashLockInfo = get(hashLockRepository.getHashLock(hashLockTransaction.getHash()));
Assertions.assertNotNull(hashLockInfo);
Assertions.assertEquals(multisigAccount.getAddress(), hashLockInfo.getOwnerAddress());
Assertions.assertEquals(hashAmount.getAmount(), hashLockInfo.getAmount());
Assertions.assertEquals(LockStatus.UNUSED, hashLockInfo.getStatus());
Assertions.assertEquals(hashLockTransaction.getHash(), hashLockInfo.getHash());
Page<HashLockInfo> page = get(hashLockRepository.search(new HashLockSearchCriteria().address(multisigAccount.getAddress())));
Assertions.assertTrue(page.getData().stream().anyMatch(m -> m.getHash().equals(hashLockTransaction.getHash())));
Assertions.assertEquals(20, page.getPageSize());
sleep(1000);
return get(multisigRepository.getMultisigAccountInfo(multisigAccount.getAddress()));
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class SecretLockIntegrationTest method secretLockAndProofTransaction.
@ParameterizedTest
@MethodSource("provider")
void secretLockAndProofTransaction(RepositoryType type, LockHashAlgorithm lockHashAlgorithm) {
RepositoryFactory repositoryFactory = getRepositoryFactory(type);
byte[] secretSeed = RandomUtils.generateRandomBytes(20);
String secret = ConvertUtils.toHex(lockHashAlgorithm.hash(secretSeed));
String storedSecret = ConvertUtils.padHex(secret, LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE);
if (lockHashAlgorithm == LockHashAlgorithm.HASH_160) {
Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, storedSecret.length());
Assertions.assertEquals(40, secret.length());
} else {
Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, storedSecret.length());
Assertions.assertEquals(LockHashAlgorithm.DEFAULT_SECRET_HEX_SIZE, secret.length());
}
String proof = ConvertUtils.toHex(secretSeed);
Account account = config().getNemesisAccount1();
Account account2 = config().getNemesisAccount2();
Currency currency = get(repositoryFactory.getNetworkCurrency());
Mosaic mosaic = currency.createAbsolute(BigInteger.valueOf(1));
BigInteger amount = mosaic.getAmount();
BigInteger duration = BigInteger.valueOf(10000);
SecretLockTransaction secretLockTransaction = SecretLockTransactionFactory.create(getNetworkType(), getDeadline(), mosaic, duration, lockHashAlgorithm, secret, account2.getAddress()).maxFee(maxFee).build();
announceAndValidate(type, account, secretLockTransaction);
SecretProofTransaction secretProofTransaction = SecretProofTransactionFactory.create(getNetworkType(), getDeadline(), lockHashAlgorithm, account2.getAddress(), secret, proof).maxFee(maxFee).build();
SecretProofTransaction secretProofTransactionAnnounced = announceAndValidate(type, account, secretProofTransaction);
sleep(500);
Assertions.assertEquals(lockHashAlgorithm, secretProofTransactionAnnounced.getHashType());
Assertions.assertEquals(account2.getAddress(), secretProofTransactionAnnounced.getRecipient());
Assertions.assertEquals(storedSecret, secretProofTransactionAnnounced.getSecret());
Assertions.assertEquals(proof, secretProofTransactionAnnounced.getProof());
SecretLockRepository hashLockRepository = getRepositoryFactory(type).createSecretLockRepository();
SecretLockInfo info = get(hashLockRepository.search(new SecretLockSearchCriteria().address(account.getAddress()).secret(storedSecret))).getData().get(0);
Assertions.assertNotNull(info);
Assertions.assertEquals(account.getAddress(), info.getOwnerAddress());
Assertions.assertEquals(account2.getAddress(), info.getRecipientAddress());
Assertions.assertEquals(amount, info.getAmount());
Assertions.assertEquals(storedSecret, info.getSecret());
Assertions.assertEquals(lockHashAlgorithm, info.getHashAlgorithm());
Assertions.assertEquals(LockStatus.USED, info.getStatus());
Page<SecretLockInfo> page = get(hashLockRepository.search(new SecretLockSearchCriteria().address(account.getAddress()).order(OrderBy.DESC)));
Assertions.assertTrue(page.getData().stream().anyMatch(m -> m.getSecret().equals(storedSecret)));
Assertions.assertEquals(20, page.getPageSize());
SecretLockInfo infoSearch = page.getData().stream().filter(m -> m.getSecret().equals(storedSecret)).findFirst().get();
Assertions.assertNotNull(infoSearch);
Assertions.assertEquals(account.getAddress(), infoSearch.getOwnerAddress());
Assertions.assertEquals(account2.getAddress(), infoSearch.getRecipientAddress());
Assertions.assertEquals(amount, infoSearch.getAmount());
Assertions.assertEquals(lockHashAlgorithm, infoSearch.getHashAlgorithm());
Assertions.assertEquals(LockStatus.USED, infoSearch.getStatus());
Assertions.assertEquals(storedSecret, infoSearch.getSecret());
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldCreateNamespaceMetadataTransactionFactory.
@Test
void shouldCreateNamespaceMetadataTransactionFactory() 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.NAMESPACE, StringEncoder.getBytes(oldValue), namespaceId.getIdAsHex());
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(namespaceId).metadataType(MetadataType.NAMESPACE);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
NamespaceMetadataTransactionFactory result = service.createNamespaceMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, namespaceId).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());
Assertions.assertEquals(namespaceId.getId(), result.getTargetNamespaceId().getId());
Mockito.verify(metadataRepositoryMock).search(criteria);
}
use of io.nem.symbol.sdk.api.Page in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceTest method shouldCreateMosaicMetadataTransactionFactoryUsingAlias.
@Test
void shouldCreateMosaicMetadataTransactionFactoryUsingAlias() 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.MOSAIC, StringEncoder.getBytes(oldValue), mosaicId.getIdAsHex());
MetadataSearchCriteria criteria = new MetadataSearchCriteria().sourceAddress(sourceAddress).scopedMetadataKey(metadataKey).targetId(mosaicId).metadataType(MetadataType.MOSAIC);
Mockito.when(metadataRepositoryMock.search(Mockito.eq(criteria))).thenReturn(Observable.just(new Page<>(Collections.singletonList(metadata))));
MosaicMetadataTransactionFactory result = service.createMosaicMetadataTransactionFactory(targetAccount.getAddress(), metadataKey, newValue, sourceAddress, mosaicAlias).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());
Assertions.assertEquals(mosaicAlias, result.getTargetMosaicId());
Mockito.verify(metadataRepositoryMock).search(Mockito.eq(criteria));
}
Aggregations