Search in sources :

Example 6 with UnresolvedAddress

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

the class AccountRestrictionIntegrationTest method sendAccountRestrictionAddress.

private void sendAccountRestrictionAddress(RepositoryType type, UnresolvedAddress unresolvedAddress, boolean add, AccountAddressRestrictionFlags accountRestrictionFlags) {
    List<UnresolvedAddress> additions = add ? Collections.singletonList(unresolvedAddress) : Collections.emptyList();
    List<UnresolvedAddress> deletions = !add ? Collections.singletonList(unresolvedAddress) : Collections.emptyList();
    AccountAddressRestrictionTransaction transaction = AccountAddressRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), accountRestrictionFlags, additions, deletions).maxFee(maxFee).build();
    AccountAddressRestrictionTransaction processedTransaction = announceAndValidate(type, testAccount, transaction);
    Assertions.assertEquals(accountRestrictionFlags, processedTransaction.getRestrictionFlags());
    Assertions.assertEquals(accountRestrictionFlags, processedTransaction.getRestrictionFlags());
    Assertions.assertEquals(additions, processedTransaction.getRestrictionAdditions());
    Assertions.assertEquals(deletions, processedTransaction.getRestrictionDeletions());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)

Example 7 with UnresolvedAddress

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

the class ListenerVertxTest method subscribeValid.

@ParameterizedTest
@ValueSource(strings = { "CONFIRMED_ADDED", "AGGREGATE_BONDED_ADDED" })
public void subscribeValid(ListenerChannel channel) throws InterruptedException, ExecutionException, TimeoutException {
    simulateWebSocketStartup();
    TransactionInfoDTO transactionInfo = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicCreationTransaction.json");
    ObjectNode transactionInfoDtoJsonObject = jsonHelper.convert(transactionInfo, ObjectNode.class);
    Address address = Address.createFromPublicKey(jsonHelper.getString(transactionInfoDtoJsonObject, "transaction", "signerPublicKey"), NETWORK_TYPE);
    String channelName = channel.toString();
    List<Transaction> transactions = new ArrayList<>();
    List<Throwable> exceptions = new ArrayList<>();
    BiFunction<UnresolvedAddress, String, Observable<? extends Transaction>> subscriber = channel == ListenerChannel.CONFIRMED_ADDED ? listener::confirmedOrError : listener::aggregateBondedAddedOrError;
    TransactionMetaDTO meta = jsonHelper.convert(transactionInfo.getMeta(), TransactionMetaDTO.class);
    subscriber.apply(address, meta.getHash()).doOnError(exceptions::add).forEach(transactions::add);
    handle(transactionInfoDtoJsonObject, channelName + "/" + address.plain());
    Assertions.assertEquals(1, transactions.size());
    Assertions.assertEquals(0, exceptions.size());
    Assertions.assertEquals(address, transactions.get(0).getSigner().get().getAddress());
    Mockito.verify(webSocketMock).handler(Mockito.any());
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, channelName + "/" + address.plain())));
    Mockito.verify(webSocketMock).writeTextMessage(jsonHelper.print(new ListenerSubscribeMessage(this.wsId, "status" + "/" + address.plain())));
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ArrayList(java.util.ArrayList) Observable(io.reactivex.Observable) ListenerSubscribeMessage(io.nem.symbol.sdk.infrastructure.ListenerSubscribeMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) TransactionMetaDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionMetaDTO) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 8 with UnresolvedAddress

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

the class AccountAddressRestrictionTransactionMapper method createFactory.

@Override
protected AccountAddressRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountAddressRestrictionTransactionDTO transaction) {
    AccountAddressRestrictionFlags restrictionFlags = AccountAddressRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
    List<UnresolvedAddress> restrictionAdditions = transaction.getRestrictionAdditions().stream().map(MapperUtils::toUnresolvedAddress).collect(Collectors.toList());
    List<UnresolvedAddress> restrictionDeletions = transaction.getRestrictionDeletions().stream().map(MapperUtils::toUnresolvedAddress).collect(Collectors.toList());
    return AccountAddressRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, restrictionAdditions, restrictionDeletions);
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) AccountAddressRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionFlags)

Example 9 with UnresolvedAddress

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

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

the class TransactionServiceTest method secretProofTransactionResolveAlias.

@Test
void secretProofTransactionResolveAlias() throws ExecutionException, InterruptedException {
    UnresolvedAddress recipient = addressNamespace1;
    String transactionHash = "aaaa";
    String secret = "1118ba10229ab5778d05d9c4b7f56676a88bf9295c185acfc0f961db5408cafe";
    String proof = "2228ba10229ab5778d05d9c4b7f56676a88bf9295c185acfc0f961db5408cafe";
    TransactionFactory<SecretProofTransaction> factory = SecretProofTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), LockHashAlgorithm.SHA3_256, recipient, secret, proof).transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    simulateStatement(height, 1, 0);
    SecretProofTransaction transaction = factory.build();
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    SecretProofTransaction resolvedTransaction = (SecretProofTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(address1, resolvedTransaction.getRecipient());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) Test(org.junit.jupiter.api.Test)

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