use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusFalseMultipleNormalAccount.
/*
* ACT Alice: account1 Bob: account4 An escrow contract is signed by all the participants
* (normal accounts) Given Alice defined the following escrow contract: | sender | recipient |
* type | data | | Alice | Bob | send-an-asset | 1 concert.ticket | | Bob | Alice |
* send-an-asset | 20 euros | And Alice signs the contract Then the contract should appear as
* incomplete
*/
@Test
void shouldReturnCorrectIsCompleteStatusFalseMultipleNormalAccount() throws ExecutionException, InterruptedException {
TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account1.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
TransferTransaction transferTransaction2 = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account4.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Arrays.asList(transferTransaction.toAggregate(account4.getPublicAccount()), transferTransaction2.toAggregate(account1.getPublicAccount()))).build();
SignedTransaction signedTransaction = account1.signTransactionWithCosignatories(aggregateTransaction, Collections.emptyList(), generationHash);
Assertions.assertFalse(service.isComplete(signedTransaction).toFuture().get());
}
use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class AggregateTransactionServiceTest method shouldReturnCorrectIsCompleteStatusFALSEMultisigSingleLevel.
/*
* ACT - Multisig single level Alice (account1): initiate an transfer to Bob Bob (multisig3): is
* a 2/2 multisig account (account2 && account3)
*/
@Test
void shouldReturnCorrectIsCompleteStatusFALSEMultisigSingleLevel() throws ExecutionException, InterruptedException {
TransferTransaction transferTransaction = TransferTransactionFactory.create(networkType, new Deadline(BigInteger.ONE), account4.getAddress(), Collections.emptyList()).message(new PlainMessage("test-message")).build();
AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(networkType, new Deadline(BigInteger.ONE), Collections.singletonList(transferTransaction.toAggregate(multisig3.getPublicAccount()))).build();
SignedTransaction signedTransaction = account2.signTransactionWithCosignatories(aggregateTransaction, Collections.emptyList(), generationHash);
Assertions.assertFalse(service.isComplete(signedTransaction).toFuture().get());
}
use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class AccountOperationRestrictionTransactionMapper method createFactory.
@Override
protected AccountOperationRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountOperationRestrictionTransactionDTO transaction) {
AccountOperationRestrictionFlags restrictionFlags = AccountOperationRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
List<TransactionType> additions = transaction.getRestrictionAdditions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
List<TransactionType> deletions = transaction.getRestrictionDeletions().stream().map(transactionTypeEnum -> TransactionType.rawValueOf(transactionTypeEnum.getValue())).collect(Collectors.toList());
return AccountOperationRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, additions, deletions);
}
use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class BinarySerializationImpl method toTransactionFactory.
/**
* It converts a {@link TransactionBuilder} to a {@link Transaction}
*
* @param builder the builder
* @return the {@link Transaction} model.
*/
private TransactionFactory<?> toTransactionFactory(TransactionBuilder builder) {
TransactionType transactionType = TransactionType.rawValueOf(SerializationUtils.shortToUnsignedInt(builder.getType().getValue()));
NetworkType networkType = NetworkType.rawValueOf(SerializationUtils.byteToUnsignedInt(builder.getNetwork().getValue()));
Deadline deadline = new Deadline(SerializationUtils.toUnsignedBigInteger(builder.getDeadline().getTimestamp()));
TransactionFactory<?> factory = resolveSerializer(transactionType, builder.getVersion()).fromBodyBuilder(networkType, deadline, builder.getBody());
factory.version(SerializationUtils.byteToUnsignedInt(builder.getVersion()));
factory.maxFee(SerializationUtils.toUnsignedBigInteger(builder.getFee()));
if (!areAllZeros(builder.getSignature().getSignature().array())) {
factory.signature(SerializationUtils.toHexString(builder.getSignature().getSignature()));
}
if (!areAllZeros(builder.getSignerPublicKey().getKey().array())) {
factory.signer(SerializationUtils.toPublicAccount(builder.getSignerPublicKey(), networkType));
}
return factory;
}
use of io.nem.symbol.sdk.model.transaction.Deadline in project nem2-sdk-java by nemtech.
the class MetadataTransactionServiceImpl method processMetadata.
/**
* Generic way of processing a metadata entity and creating a new metadata transaction factory
* depending on the existing metadata value. This works for Account, Mosaic and Namespace
* metadata.
*
* @param criteria the criteria
* @param transactionFactory the function that creates a transaction factory
* @param newValue the new value you want to set.
* @param <T> the type of the transaction factory.
* @return an Observable of a transaction factory.
*/
private <T extends MetadataTransactionFactory> Observable<T> processMetadata(MetadataSearchCriteria criteria, TriFunction<byte[], NetworkType, Deadline, T> transactionFactory, String newValue) {
return Observable.combineLatest(networkTypeObservable, epochAdjustmentObservable, (networkType, epochAdjustment) -> metadataRepository.search(criteria).map(page -> {
Deadline deadline = Deadline.create(epochAdjustment);
if (page.getData().isEmpty()) {
return transactionFactory.apply(StringEncoder.getBytes(newValue), networkType, deadline);
} else {
byte[] originalValue = page.getData().get(0).getValue();
byte[] newValueBytes = StringEncoder.getBytes(newValue);
byte[] xoredBytes = ConvertUtils.xor(originalValue, newValueBytes);
T factory = transactionFactory.apply(xoredBytes, networkType, deadline);
factory.valueSizeDelta(newValueBytes.length - originalValue.length);
return factory;
}
})).flatMap(f -> f);
}
Aggregations