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