Search in sources :

Example 1 with MosaicAliasTransaction

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

the class TransactionMapperVertxTest method shouldCreateAggregateMosaicAliasTransaction.

@Test
void shouldCreateAggregateMosaicAliasTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperVertx.loadTransactionInfoDTO("aggregateMosaicAliasTransaction.json");
    Transaction aggregateTransferTransaction = map(aggregateTransferTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateTransferTransaction, aggregateTransferTransactionDTO);
    MosaicAliasTransaction transaction = (MosaicAliasTransaction) ((AggregateTransaction) aggregateTransferTransaction).getInnerTransactions().get(0);
    Assertions.assertEquals(new BigInteger("884562898459306"), transaction.getMosaicId().getId());
    Assertions.assertEquals(AliasAction.UNLINK, transaction.getAliasAction());
    Assertions.assertEquals(new BigInteger("307262000798378"), transaction.getNamespaceId().getId());
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AccountKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.vertx.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) Test(org.junit.jupiter.api.Test)

Example 2 with MosaicAliasTransaction

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

the class TestHelper method createMosaic.

protected MosaicId createMosaic(Account account, RepositoryType type, BigInteger initialSupply, String alias) {
    MosaicNonce nonce = MosaicNonce.createRandom();
    MosaicId mosaicId = MosaicId.createFromNonce(nonce, account.getPublicAccount());
    MosaicDefinitionTransaction mosaicDefinitionTransaction = MosaicDefinitionTransactionFactory.create(getNetworkType(), getDeadline(), nonce, mosaicId, MosaicFlags.create(true, true, true), 4, new BlockDuration(100)).maxFee(maxFee).build();
    MosaicDefinitionTransaction validateTransaction = announceAndValidate(type, account, mosaicDefinitionTransaction);
    Assertions.assertEquals(mosaicId, validateTransaction.getMosaicId());
    UnresolvedMosaicId unresolvedMosaicId = mosaicId;
    if (alias != null) {
        NamespaceId rootNamespaceId = createRootNamespace(type, account, alias);
        unresolvedMosaicId = rootNamespaceId;
        MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
        announceAggregateAndValidate(type, addressAliasTransaction, account);
    }
    if (initialSupply != null && initialSupply.longValue() > 0) {
        MosaicSupplyChangeTransaction mosaicSupplyChangeTransaction = MosaicSupplyChangeTransactionFactory.create(getNetworkType(), getDeadline(), unresolvedMosaicId, MosaicSupplyChangeActionType.INCREASE, initialSupply).maxFee(maxFee).build();
        announceAndValidate(type, account, mosaicSupplyChangeTransaction);
    }
    return mosaicId;
}
Also used : MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) BlockDuration(io.nem.symbol.sdk.model.blockchain.BlockDuration) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNonce(io.nem.symbol.sdk.model.mosaic.MosaicNonce) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)

Example 3 with MosaicAliasTransaction

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

the class TransactionMapperOkHttpTest method shouldCreateAggregateMosaicAliasTransaction.

@Test
void shouldCreateAggregateMosaicAliasTransaction() {
    TransactionInfoDTO aggregateTransferTransactionDTO = TestHelperOkHttp.loadTransactionInfoDTO("aggregateMosaicAliasTransaction.json");
    Transaction aggregateTransferTransaction = map(aggregateTransferTransactionDTO);
    validateAggregateTransaction((AggregateTransaction) aggregateTransferTransaction, aggregateTransferTransactionDTO);
    MosaicAliasTransaction transaction = (MosaicAliasTransaction) ((AggregateTransaction) aggregateTransferTransaction).getInnerTransactions().get(0);
    Assertions.assertEquals(new BigInteger("884562898459306"), transaction.getMosaicId().getId());
    Assertions.assertEquals(AliasAction.UNLINK, transaction.getAliasAction());
    Assertions.assertEquals(new BigInteger("307262000798378"), transaction.getNamespaceId().getId());
}
Also used : SecretProofTransaction(io.nem.symbol.sdk.model.transaction.SecretProofTransaction) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) AccountOperationRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction) AccountAddressRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) MosaicDefinitionTransaction(io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction) MultisigAccountModificationTransaction(io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction) AccountMosaicRestrictionTransaction(io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) AccountKeyLinkTransaction(io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction) NamespaceMetadataTransaction(io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction) AccountMetadataTransaction(io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction) AddressAliasTransaction(io.nem.symbol.sdk.model.transaction.AddressAliasTransaction) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicSupplyChangeTransaction(io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction) SecretLockTransaction(io.nem.symbol.sdk.model.transaction.SecretLockTransaction) TransactionInfoDTO(io.nem.symbol.sdk.openapi.okhttp_gson.model.TransactionInfoDTO) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) BigInteger(java.math.BigInteger) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) Test(org.junit.jupiter.api.Test)

Example 4 with MosaicAliasTransaction

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

the class TestHelper method setMosaicAlias.

protected NamespaceId setMosaicAlias(RepositoryType type, MosaicId mosaicId, String namespaceName) {
    Account nemesisAccount = config().getNemesisAccount1();
    NamespaceId namespaceId = NamespaceId.createFromName(namespaceName);
    if (isAlias(type, mosaicId, namespaceId)) {
        System.out.println(namespaceName + " MOSAIC Alias found, reusing it.");
        return namespaceId;
    } else {
        System.out.println(namespaceName + " MOSAIC Alias not found, CREATING MOSAIC ALIAS");
    }
    System.out.println("Setting up namespace " + namespaceName);
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, nemesisAccount).getLeft().getNamespaceId();
    System.out.println("Setting mosaic alias " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
    MosaicAliasTransaction aliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
    announceAggregateAndValidate(type, aliasTransaction, nemesisAccount);
    int retry = 10;
    while (!isAlias(type, mosaicId, namespaceId)) {
        sleep(300);
        retry--;
        if (retry == 0) {
            Assertions.fail("Could not create " + mosaicId.getIdAsHex() + " alias: " + namespaceName);
        }
    }
    return rootNamespaceId;
}
Also used : Account(io.nem.symbol.sdk.model.account.Account) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)

Example 5 with MosaicAliasTransaction

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

the class MosaicAliasTransactionIntegrationTest method sendMosaicAliasTransaction.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void sendMosaicAliasTransaction(RepositoryType type) {
    String namespaceName = "test-root-namespace-for-mosaic-alias-" + Double.valueOf(Math.floor(Math.random() * 10000)).intValue();
    Account account = this.config().getDefaultAccount();
    AccountInfo accountInfo = get(getRepositoryFactory(type).createAccountRepository().getAccountInfo(account.getPublicAccount().getAddress()));
    Assertions.assertFalse(accountInfo.getMosaics().isEmpty());
    MosaicId mosaicId = createMosaic(account, type, BigInteger.ZERO, null);
    NamespaceRegistrationTransaction namespaceRegistrationTransaction = NamespaceRegistrationTransactionFactory.createRootNamespace(getNetworkType(), getDeadline(), namespaceName, helper().getDuration()).maxFee(maxFee).build();
    NamespaceId rootNamespaceId = announceAggregateAndValidate(type, namespaceRegistrationTransaction, account).getLeft().getNamespaceId();
    MosaicAliasTransaction addressAliasTransaction = MosaicAliasTransactionFactory.create(getNetworkType(), getDeadline(), AliasAction.LINK, rootNamespaceId, mosaicId).maxFee(maxFee).build();
    announceAggregateAndValidate(type, addressAliasTransaction, account);
    List<MosaicNames> accountNames = get(getRepositoryFactory(type).createNamespaceRepository().getMosaicsNames(Collections.singletonList(mosaicId)));
    Assertions.assertEquals(1, accountNames.size());
    assertEquals(1, accountNames.size());
    assertEquals(mosaicId, accountNames.get(0).getMosaicId());
    assertTrue(accountNames.get(0).getNames().stream().anyMatch(n -> namespaceName.equals(n.getName())));
}
Also used : NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) Account(io.nem.symbol.sdk.model.account.Account) EnumSource(org.junit.jupiter.params.provider.EnumSource) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) MosaicAliasTransactionFactory(io.nem.symbol.sdk.model.transaction.MosaicAliasTransactionFactory) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TestInstance(org.junit.jupiter.api.TestInstance) NamespaceRegistrationTransactionFactory(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) Assertions(org.junit.jupiter.api.Assertions) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) AliasAction(io.nem.symbol.sdk.model.namespace.AliasAction) Collections(java.util.Collections) Account(io.nem.symbol.sdk.model.account.Account) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicNames(io.nem.symbol.sdk.model.mosaic.MosaicNames) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) MosaicAliasTransaction(io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) NamespaceRegistrationTransaction(io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

MosaicAliasTransaction (io.nem.symbol.sdk.model.transaction.MosaicAliasTransaction)5 NamespaceRegistrationTransaction (io.nem.symbol.sdk.model.transaction.NamespaceRegistrationTransaction)4 NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)3 MosaicDefinitionTransaction (io.nem.symbol.sdk.model.transaction.MosaicDefinitionTransaction)3 MosaicSupplyChangeTransaction (io.nem.symbol.sdk.model.transaction.MosaicSupplyChangeTransaction)3 BigInteger (java.math.BigInteger)3 Account (io.nem.symbol.sdk.model.account.Account)2 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 AccountAddressRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountAddressRestrictionTransaction)2 AccountKeyLinkTransaction (io.nem.symbol.sdk.model.transaction.AccountKeyLinkTransaction)2 AccountMetadataTransaction (io.nem.symbol.sdk.model.transaction.AccountMetadataTransaction)2 AccountMosaicRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountMosaicRestrictionTransaction)2 AccountOperationRestrictionTransaction (io.nem.symbol.sdk.model.transaction.AccountOperationRestrictionTransaction)2 AddressAliasTransaction (io.nem.symbol.sdk.model.transaction.AddressAliasTransaction)2 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)2 HashLockTransaction (io.nem.symbol.sdk.model.transaction.HashLockTransaction)2 MosaicMetadataTransaction (io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction)2 MultisigAccountModificationTransaction (io.nem.symbol.sdk.model.transaction.MultisigAccountModificationTransaction)2 NamespaceMetadataTransaction (io.nem.symbol.sdk.model.transaction.NamespaceMetadataTransaction)2 SecretLockTransaction (io.nem.symbol.sdk.model.transaction.SecretLockTransaction)2