Search in sources :

Example 1 with AccountMosaicRestrictionFlags

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

the class AccountMosaicRestrictionTransactionMapper method createFactory.

@Override
protected AccountMosaicRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountMosaicRestrictionTransactionDTO transaction) {
    AccountMosaicRestrictionFlags restrictionFlags = AccountMosaicRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
    List<UnresolvedMosaicId> additions = transaction.getRestrictionAdditions().stream().map(MapperUtils::toUnresolvedMosaicId).collect(Collectors.toList());
    List<UnresolvedMosaicId> deletions = transaction.getRestrictionDeletions().stream().map(MapperUtils::toUnresolvedMosaicId).collect(Collectors.toList());
    return AccountMosaicRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, additions, deletions);
}
Also used : AccountMosaicRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 2 with AccountMosaicRestrictionFlags

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

the class AccountMosaicRestrictionTransactionMapper method createFactory.

@Override
protected AccountMosaicRestrictionTransactionFactory createFactory(NetworkType networkType, Deadline deadline, AccountMosaicRestrictionTransactionDTO transaction) {
    AccountMosaicRestrictionFlags restrictionFlags = AccountMosaicRestrictionFlags.rawValueOf(transaction.getRestrictionFlags().getValue());
    List<UnresolvedMosaicId> additions = transaction.getRestrictionAdditions().stream().map(MapperUtils::toUnresolvedMosaicId).collect(Collectors.toList());
    List<UnresolvedMosaicId> deletions = transaction.getRestrictionDeletions().stream().map(MapperUtils::toUnresolvedMosaicId).collect(Collectors.toList());
    return AccountMosaicRestrictionTransactionFactory.create(networkType, deadline, restrictionFlags, additions, deletions);
}
Also used : AccountMosaicRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 3 with AccountMosaicRestrictionFlags

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

the class AccountRestrictionIntegrationTest method addAndRemoveMosaicRestriction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addAndRemoveMosaicRestriction(RepositoryType type) {
    AccountMosaicRestrictionFlags restrictionFlags = AccountMosaicRestrictionFlags.ALLOW_INCOMING_MOSAIC;
    MosaicNonce nonce = MosaicNonce.createRandom();
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, testAccount.getPublicAccount());
    Assertions.assertNotNull(get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(testAccount.getAddress())));
    if (hasRestriction(type, testAccount, restrictionFlags, mosaicId)) {
        System.out.println("Removing existing mosaic restriction!");
        sendAccountRestrictionMosaic(type, mosaicId, false, restrictionFlags);
        Assertions.assertFalse(hasRestriction(type, testAccount, restrictionFlags, mosaicId));
    }
    System.out.println("Adding mosaic restriction");
    sendAccountRestrictionMosaic(type, mosaicId, true, restrictionFlags);
    Assertions.assertTrue(hasRestriction(type, testAccount, restrictionFlags, mosaicId));
    System.out.println("Removing mosaic restriction");
    sendAccountRestrictionMosaic(type, mosaicId, false, restrictionFlags);
    Assertions.assertFalse(hasRestriction(type, testAccount, restrictionFlags, mosaicId));
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) AccountMosaicRestrictionFlags(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)3 AccountMosaicRestrictionFlags (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionFlags)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)1 MosaicNonce (io.nem.symbol.sdk.model.mosaic.MosaicNonce)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 EnumSource (org.junit.jupiter.params.provider.EnumSource)1