Search in sources :

Example 1 with MosaicGlobalRestrictionTransactionFactory

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

the class TransactionServiceImpl method resolveTransactionFactory.

private Observable<TransactionFactory<? extends Transaction>> resolveTransactionFactory(MosaicGlobalRestrictionTransaction transaction, ReceiptSource expectedReceiptSource, Observable<List<MosaicResolutionStatement>> mosaicResolutionStatements) {
    Observable<MosaicId> resolvedMosaicId = getResolvedMosaicId(transaction, transaction.getMosaicId(), mosaicResolutionStatements, expectedReceiptSource);
    Observable<MosaicId> resolvedReferenceMosaicId = getResolvedMosaicId(transaction, transaction.getReferenceMosaicId(), mosaicResolutionStatements, expectedReceiptSource);
    return Observable.combineLatest(resolvedMosaicId, resolvedReferenceMosaicId, (mosaicId, referenceMosaicId) -> {
        MosaicGlobalRestrictionTransactionFactory factory = MosaicGlobalRestrictionTransactionFactory.create(transaction.getNetworkType(), transaction.getDeadline(), mosaicId, transaction.getRestrictionKey(), transaction.getNewRestrictionValue(), transaction.getNewRestrictionType());
        if (referenceMosaicId != null) {
            factory.referenceMosaicId(referenceMosaicId);
        }
        return factory.previousRestrictionValue(transaction.getPreviousRestrictionValue()).previousRestrictionType(transaction.getPreviousRestrictionType());
    });
}
Also used : MosaicGlobalRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId)

Example 2 with MosaicGlobalRestrictionTransactionFactory

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

the class MosaicGlobalRestrictionTransactionMapper method createFactory.

@Override
protected TransactionFactory<MosaicGlobalRestrictionTransaction> createFactory(NetworkType networkType, Deadline deadline, MosaicGlobalRestrictionTransactionDTO transaction) {
    byte prevRestrictionType = transaction.getPreviousRestrictionType().getValue().byteValue();
    byte newRestrictionType = transaction.getNewRestrictionType().getValue().byteValue();
    MosaicGlobalRestrictionTransactionFactory factory = MosaicGlobalRestrictionTransactionFactory.create(networkType, deadline, toUnresolvedMosaicId(transaction.getMosaicId()), MapperUtils.fromHexToBigInteger(transaction.getRestrictionKey()), transaction.getNewRestrictionValue(), MosaicRestrictionType.rawValueOf(newRestrictionType));
    if (transaction.getReferenceMosaicId() != null) {
        factory.referenceMosaicId(MapperUtils.toUnresolvedMosaicId(transaction.getReferenceMosaicId()));
    }
    return factory.previousRestrictionValue(transaction.getPreviousRestrictionValue()).previousRestrictionType(MosaicRestrictionType.rawValueOf(prevRestrictionType));
}
Also used : MosaicGlobalRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory)

Example 3 with MosaicGlobalRestrictionTransactionFactory

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

the class MosaicGlobalRestrictionTransactionMapper method createFactory.

@Override
protected TransactionFactory<MosaicGlobalRestrictionTransaction> createFactory(NetworkType networkType, Deadline deadline, MosaicGlobalRestrictionTransactionDTO transaction) {
    byte prevRestrictionType = transaction.getPreviousRestrictionType().getValue().byteValue();
    byte newRestrictionType = transaction.getNewRestrictionType().getValue().byteValue();
    MosaicGlobalRestrictionTransactionFactory factory = MosaicGlobalRestrictionTransactionFactory.create(networkType, deadline, toUnresolvedMosaicId(transaction.getMosaicId()), MapperUtils.fromHexToBigInteger(transaction.getRestrictionKey()), transaction.getNewRestrictionValue(), MosaicRestrictionType.rawValueOf(newRestrictionType));
    if (transaction.getReferenceMosaicId() != null) {
        factory.referenceMosaicId(MapperUtils.toUnresolvedMosaicId(transaction.getReferenceMosaicId()));
    }
    return factory.previousRestrictionValue(transaction.getPreviousRestrictionValue()).previousRestrictionType(MosaicRestrictionType.rawValueOf(prevRestrictionType));
}
Also used : MosaicGlobalRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory)

Example 4 with MosaicGlobalRestrictionTransactionFactory

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

the class TransactionServiceTest method mosaicGlobalRestrictionTransactionResolveAlias.

@Test
void mosaicGlobalRestrictionTransactionResolveAlias() throws ExecutionException, InterruptedException {
    String transactionHash = "aaaa";
    MosaicGlobalRestrictionTransactionFactory mosaicGlobalRestrictionTransactionFactory = MosaicGlobalRestrictionTransactionFactory.create(NetworkType.MIJIN_TEST, new Deadline(BigInteger.ONE), mosaicNamespace2, BigInteger.TEN, BigInteger.ONE, MosaicRestrictionType.GT);
    mosaicGlobalRestrictionTransactionFactory.referenceMosaicId(mosaicNamespace3);
    mosaicGlobalRestrictionTransactionFactory.previousRestrictionType(MosaicRestrictionType.EQ);
    mosaicGlobalRestrictionTransactionFactory.previousRestrictionValue(BigInteger.valueOf(3));
    TransactionFactory<MosaicGlobalRestrictionTransaction> factory = mosaicGlobalRestrictionTransactionFactory.transactionInfo(TransactionInfo.create(height, 0, "ABC", transactionHash, ""));
    MosaicGlobalRestrictionTransaction transaction = factory.build();
    simulateStatement(height, 1, 0);
    List<String> hashes = Collections.singletonList(transactionHash);
    Mockito.when(transactionRepositoryMock.getTransactions(Mockito.eq(TransactionGroup.CONFIRMED), Mockito.eq(hashes))).thenReturn(Observable.just(Collections.singletonList(transaction)));
    MosaicGlobalRestrictionTransaction resolvedTransaction = (MosaicGlobalRestrictionTransaction) service.resolveAliases(hashes).toFuture().get().get(0);
    Assertions.assertEquals(mosaicId2, resolvedTransaction.getMosaicId());
    Assertions.assertEquals(mosaicId3, resolvedTransaction.getReferenceMosaicId());
}
Also used : MosaicGlobalRestrictionTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory) MosaicGlobalRestrictionTransaction(io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction) Deadline(io.nem.symbol.sdk.model.transaction.Deadline) Test(org.junit.jupiter.api.Test)

Aggregations

MosaicGlobalRestrictionTransactionFactory (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransactionFactory)4 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)1 Deadline (io.nem.symbol.sdk.model.transaction.Deadline)1 MosaicGlobalRestrictionTransaction (io.nem.symbol.sdk.model.transaction.MosaicGlobalRestrictionTransaction)1 Test (org.junit.jupiter.api.Test)1