Search in sources :

Example 1 with TransactionType

use of io.nem.symbol.sdk.model.transaction.TransactionType in project nem2-sdk-java by nemtech.

the class BinarySerializationImpl method toTransaction.

/**
 * It converts a {@link EmbeddedTransactionBuilder} to a {@link Transaction}
 *
 * @param builder the builder
 * @return the {@link Transaction} model.
 */
private Transaction toTransaction(EmbeddedTransactionBuilder builder) {
    TransactionType transactionType = TransactionType.rawValueOf(SerializationUtils.shortToUnsignedInt(builder.getType().getValue()));
    NetworkType networkType = NetworkType.rawValueOf(SerializationUtils.byteToUnsignedInt(builder.getNetwork().getValue()));
    TransactionFactory<?> factory = resolveSerializer(transactionType, builder.getVersion()).fromBodyBuilder(networkType, new Deadline(BigInteger.ZERO), builder.getBody());
    factory.signer(SerializationUtils.toPublicAccount(builder.getSignerPublicKey(), networkType));
    factory.version(SerializationUtils.byteToUnsignedInt(builder.getVersion()));
    return factory.build();
}
Also used : TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline)

Example 2 with TransactionType

use of io.nem.symbol.sdk.model.transaction.TransactionType in project nem2-sdk-java by nemtech.

the class AccountRestrictionIntegrationTest method sendAccountRestrictionTransaction.

private void sendAccountRestrictionTransaction(RepositoryType type, TransactionType transactionType, boolean add, AccountOperationRestrictionFlags accountRestrictionFlags) {
    List<TransactionType> additions = add ? Collections.singletonList(transactionType) : Collections.emptyList();
    List<TransactionType> deletions = !add ? Collections.singletonList(transactionType) : Collections.emptyList();
    AccountOperationRestrictionTransaction transaction = AccountOperationRestrictionTransactionFactory.create(getNetworkType(), getDeadline(), accountRestrictionFlags, additions, deletions).maxFee(maxFee).build();
    AccountOperationRestrictionTransaction processedTransaction = announceAndValidate(type, testAccount, transaction);
    Assertions.assertEquals(accountRestrictionFlags, processedTransaction.getRestrictionFlags());
    Assertions.assertEquals(additions, processedTransaction.getRestrictionAdditions());
    Assertions.assertEquals(deletions, processedTransaction.getRestrictionDeletions());
}
Also used : TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)

Example 3 with TransactionType

use of io.nem.symbol.sdk.model.transaction.TransactionType in project nem2-sdk-java by nemtech.

the class AccountRestrictionIntegrationTest method addAndRemoveTransactionRestriction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addAndRemoveTransactionRestriction(RepositoryType type) {
    AccountOperationRestrictionFlags restrictionFlags = AccountOperationRestrictionFlags.BLOCK_OUTGOING_TRANSACTION_TYPE;
    TransactionType transactionType = TransactionType.SECRET_PROOF;
    Assertions.assertNotNull(get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(testAccount.getAddress())));
    if (hasRestriction(type, testAccount, restrictionFlags, transactionType)) {
        System.out.println("Removing existing transaction restriction!");
        sendAccountRestrictionTransaction(type, transactionType, false, restrictionFlags);
        Assertions.assertFalse(hasRestriction(type, testAccount, restrictionFlags, transactionType));
    }
    System.out.println("Adding transaction restriction");
    sendAccountRestrictionTransaction(type, transactionType, true, restrictionFlags);
    Assertions.assertTrue(hasRestriction(type, testAccount, restrictionFlags, transactionType));
    System.out.println("Removing transaction restriction");
    sendAccountRestrictionTransaction(type, transactionType, false, restrictionFlags);
    Assertions.assertFalse(hasRestriction(type, testAccount, restrictionFlags, transactionType));
}
Also used : AccountOperationRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionFlags) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with TransactionType

use of io.nem.symbol.sdk.model.transaction.TransactionType in project nem2-sdk-java by nemtech.

the class AccountRepositoryIntegrationTest method getMultipleTransactions.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getMultipleTransactions(RepositoryType type) {
    TransactionRepository transactionRepository = getRepositoryFactory(type).createTransactionRepository();
    Account account = config().getDefaultAccount();
    List<TransactionType> transactionTypes = Arrays.asList(TransactionType.TRANSFER, TransactionType.AGGREGATE_COMPLETE, TransactionType.NAMESPACE_METADATA);
    List<Transaction> transactions = get(transactionRepository.search(new TransactionSearchCriteria(TransactionGroup.CONFIRMED).signerPublicKey(account.getPublicAccount().getPublicKey()).transactionTypes(transactionTypes))).getData();
    Assertions.assertFalse(transactions.isEmpty());
    transactions.forEach(t -> Assertions.assertTrue(transactionTypes.contains(t.getType())));
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) PublicAccount(io.nem.symbol.sdk.model.account.PublicAccount) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with TransactionType

use of io.nem.symbol.sdk.model.transaction.TransactionType in project nem2-sdk-java by nemtech.

the class GeneralTransactionMapper method resolveMapper.

private TransactionMapper resolveMapper(Object transactionInfoJson) {
    Integer type = getJsonHelper().getInteger(transactionInfoJson, "transaction", "type");
    if (type == null) {
        throw new IllegalArgumentException("Transaction cannot be mapped, object does not not have transaction type.");
    }
    Integer version = getJsonHelper().getInteger(transactionInfoJson, "transaction", "version");
    if (version == null) {
        throw new IllegalArgumentException("Transaction cannot be mapped, object does not not have transaction version.");
    }
    TransactionType transactionType = TransactionType.rawValueOf(type);
    return resolveMapper(transactionType, version);
}
Also used : TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType)

Aggregations

TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)10 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)4 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)4 AccountOperationRestrictionFlags (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionFlags)3 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 TransactionRepository (io.nem.symbol.sdk.api.TransactionRepository)2 TransactionSearchCriteria (io.nem.symbol.sdk.api.TransactionSearchCriteria)2 Account (io.nem.symbol.sdk.model.account.Account)2 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)2 AccountOperationRestrictionTransactionFactory (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransactionFactory)2 JsonHelper (io.nem.symbol.sdk.model.transaction.JsonHelper)2 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)2 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 AccountOperationRestrictionTransactionDTO (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountOperationRestrictionTransactionDTO)1 AccountRestrictionFlagsEnum (io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionFlagsEnum)1 TransactionTypeEnum (io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionTypeEnum)1