Search in sources :

Example 31 with Deadline

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());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 32 with Deadline

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());
}
Also used : PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) Test(org.junit.jupiter.api.Test)

Example 33 with Deadline

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);
}
Also used : AccountRestrictionFlagsEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountRestrictionFlagsEnum) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) List(java.util.List) AccountOperationRestrictionTransactionDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.AccountOperationRestrictionTransactionDTO) JsonHelper(io.nem.symbol.sdk.model.transaction.JsonHelper) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) AccountOperationRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionFlags) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) TransactionTypeEnum(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionTypeEnum) Collectors(java.util.stream.Collectors) AccountOperationRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransactionFactory) AccountOperationRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionFlags) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType)

Example 34 with Deadline

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;
}
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 35 with Deadline

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);
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MetadataTransactionService(io.nem.symbol.sdk.api.MetadataTransactionService) MosaicMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransactionFactory) NamespaceMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransactionFactory) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) AccountMetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.AccountMetadataTransactionFactory) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) MetadataType(io.nem.symbol.sdk.model.metadata.MetadataType) Function(java.util.function.Function) StringEncoder(io.nem.symbol.core.utils.StringEncoder) MetadataRepository(io.nem.symbol.sdk.api.MetadataRepository) Objects(java.util.Objects) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) MetadataTransactionFactory(io.nem.symbol.sdk.model.transaction.MetadataTransactionFactory) Duration(java.time.Duration) AliasService(io.nem.symbol.sdk.api.AliasService) MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) Deadline(io.nem.symbol.sdk.model.transaction.Deadline)

Aggregations

Deadline (io.nem.symbol.sdk.model.transaction.Deadline)49 Test (org.junit.jupiter.api.Test)38 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)28 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)23 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)22 SignedTransaction (io.nem.symbol.sdk.model.transaction.SignedTransaction)19 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)14 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)9 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)9 BigInteger (java.math.BigInteger)8 ArrayList (java.util.ArrayList)6 Address (io.nem.symbol.sdk.model.account.Address)5 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)5 Account (io.nem.symbol.sdk.model.account.Account)4 PublicAccount (io.nem.symbol.sdk.model.account.PublicAccount)4 TransactionType (io.nem.symbol.sdk.model.transaction.TransactionType)4 Duration (java.time.Duration)4 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)3 TransactionAnnounceResponse (io.nem.symbol.sdk.model.transaction.TransactionAnnounceResponse)3 BinarySerialization (io.nem.symbol.sdk.api.BinarySerialization)2