Search in sources :

Example 46 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class SerializationUtils method fromUnresolvedAddressToByteBuffer.

/**
 * It serializes a {@link UnresolvedAddress} to an hex catbuffer understand.
 *
 * @param unresolvedAddress the {@link Address} or {@link NamespaceId} to be serialized.
 * @param networkType the network type to customize the {@link NamespaceId} serialization
 * @return the serialized {@link UnresolvedAddress} as {@link ByteBuffer}.
 */
public static ByteBuffer fromUnresolvedAddressToByteBuffer(UnresolvedAddress unresolvedAddress, NetworkType networkType) {
    Validate.notNull(unresolvedAddress, "unresolvedAddress must not be null");
    if (unresolvedAddress instanceof NamespaceId) {
        final ByteBuffer namespaceIdAlias = ByteBuffer.allocate(24);
        NamespaceId namespaceId = (NamespaceId) unresolvedAddress;
        final byte firstByte = (byte) (networkType.getValue() | 0x01);
        namespaceIdAlias.order(ByteOrder.LITTLE_ENDIAN);
        namespaceIdAlias.put(firstByte);
        namespaceIdAlias.putLong(namespaceId.getIdAsLong());
        return ByteBuffer.wrap(namespaceIdAlias.array());
    }
    if (unresolvedAddress instanceof Address) {
        return fromAddressToByteBuffer((Address) unresolvedAddress);
    }
    throw new IllegalArgumentException("Unexpected UnresolvedAddress type " + unresolvedAddress.getClass());
}
Also used : UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) ByteBuffer(java.nio.ByteBuffer)

Example 47 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class StateProofServiceImpl method namespace.

@Override
public Observable<StateMerkleProof<NamespaceInfo>> namespace(NamespaceInfo state) {
    NamespaceId id = state.getId();
    NamespaceRepository namespaceRepository = this.repositoryFactory.createNamespaceRepository();
    PaginationStreamer<NamespaceInfo, NamespaceSearchCriteria> streamer = namespaceRepository.streamer();
    return namespaceRepository.getNamespaceMerkle(id).flatMap(merkle -> streamer.search(new NamespaceSearchCriteria().level0(state.getId().getIdAsHex()).registrationType(NamespaceRegistrationType.SUB_NAMESPACE)).toList().toObservable().map(state::serialize).map(s -> toStateMerkleProof(state, merkle, s)));
}
Also used : NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) Hashes(io.nem.symbol.core.crypto.Hashes) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) StateProofService(io.nem.symbol.sdk.api.StateProofService) StateMerkleProof(io.nem.symbol.sdk.model.state.StateMerkleProof) SecretLockInfo(io.nem.symbol.sdk.model.transaction.SecretLockInfo) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) MosaicInfo(io.nem.symbol.sdk.model.mosaic.MosaicInfo) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) NamespaceRepository(io.nem.symbol.sdk.api.NamespaceRepository) PaginationStreamer(io.nem.symbol.sdk.api.PaginationStreamer) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) NamespaceRegistrationType(io.nem.symbol.sdk.model.namespace.NamespaceRegistrationType) MosaicRestriction(io.nem.symbol.sdk.model.restriction.MosaicRestriction) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria) AccountRestrictions(io.nem.symbol.sdk.model.account.AccountRestrictions) AccountInfo(io.nem.symbol.sdk.model.account.AccountInfo) MerkleStateInfo(io.nem.symbol.sdk.model.blockchain.MerkleStateInfo) HashLockInfo(io.nem.symbol.sdk.model.transaction.HashLockInfo) Observable(io.reactivex.Observable) Address(io.nem.symbol.sdk.model.account.Address) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.symbol.sdk.model.namespace.NamespaceInfo) NamespaceSearchCriteria(io.nem.symbol.sdk.api.NamespaceSearchCriteria)

Example 48 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class ListenerIntegrationTest method getAllMultisigAddressesAndAliasesWhenMultisig.

@ParameterizedTest
@EnumSource(RepositoryType.class)
void getAllMultisigAddressesAndAliasesWhenMultisig(RepositoryType type) {
    final MultisigAccountInfo multisigAccountInfo = get(getRepositoryFactory(type).createMultisigRepository().getMultisigAccountInfo(this.multisigAccount.getAddress()));
    Assertions.assertEquals(Arrays.asList(this.cosignatoryAccount.getAddress(), this.cosignatoryAccount2.getAddress()), multisigAccountInfo.getCosignatoryAddresses());
    Set<NamespaceId> aliases = get(getRepositoryFactory(type).createNamespaceRepository().getAccountsNames(Arrays.asList(multisigAccount.getAddress(), cosignatoryAccount.getAddress(), cosignatoryAccount2.getAddress()))).stream().flatMap(a -> a.getNames().stream().map(n -> n.getNamespaceId())).collect(Collectors.toSet());
    Listener listener = getRepositoryFactory(type).createListener();
    final Set<UnresolvedAddress> unresolvedAddresses = get(listener.getAllMultisigAddressesAndAliases(this.multisigAccount.getAddress()));
    final Set<UnresolvedAddress> expectedAddresees = Sets.newSet(this.multisigAccount.getAddress(), this.cosignatoryAccount.getAddress(), this.cosignatoryAccount2.getAddress());
    expectedAddresees.addAll(aliases);
    Assertions.assertEquals(expectedAddresees, unresolvedAddresses);
}
Also used : Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) FinalizedBlock(io.nem.symbol.sdk.model.blockchain.FinalizedBlock) BeforeEach(org.junit.jupiter.api.BeforeEach) TransactionSearchCriteria(io.nem.symbol.sdk.api.TransactionSearchCriteria) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) Arrays(java.util.Arrays) HashLockTransaction(io.nem.symbol.sdk.model.transaction.HashLockTransaction) HashLockTransactionFactory(io.nem.symbol.sdk.model.transaction.HashLockTransactionFactory) BlockInfo(io.nem.symbol.sdk.model.blockchain.BlockInfo) Account(io.nem.symbol.sdk.model.account.Account) CompletableFuture(java.util.concurrent.CompletableFuture) EnumSource(org.junit.jupiter.params.provider.EnumSource) TransactionStatusError(io.nem.symbol.sdk.model.transaction.TransactionStatusError) Disabled(org.junit.jupiter.api.Disabled) RepositoryFactory(io.nem.symbol.sdk.api.RepositoryFactory) CosignatureTransaction(io.nem.symbol.sdk.model.transaction.CosignatureTransaction) TestInstance(org.junit.jupiter.api.TestInstance) Sets(org.mockito.internal.util.collections.Sets) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) Pair(org.apache.commons.lang3.tuple.Pair) TransactionService(io.nem.symbol.sdk.api.TransactionService) SignedTransaction(io.nem.symbol.sdk.model.transaction.SignedTransaction) TransactionType(io.nem.symbol.sdk.model.transaction.TransactionType) TransferTransaction(io.nem.symbol.sdk.model.transaction.TransferTransaction) Observable(io.reactivex.Observable) BigInteger(java.math.BigInteger) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Listener(io.nem.symbol.sdk.api.Listener) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) NamespaceName(io.nem.symbol.sdk.model.namespace.NamespaceName) Set(java.util.Set) PlainMessage(io.nem.symbol.sdk.model.message.PlainMessage) Transaction(io.nem.symbol.sdk.model.transaction.Transaction) Collectors(java.util.stream.Collectors) ExecutionException(java.util.concurrent.ExecutionException) TransactionGroup(io.nem.symbol.sdk.model.transaction.TransactionGroup) List(java.util.List) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) TransferTransactionFactory(io.nem.symbol.sdk.model.transaction.TransferTransactionFactory) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) AggregateTransactionFactory(io.nem.symbol.sdk.model.transaction.AggregateTransactionFactory) Address(io.nem.symbol.sdk.model.account.Address) Collections(java.util.Collections) TransactionRepository(io.nem.symbol.sdk.api.TransactionRepository) CosignatureSignedTransaction(io.nem.symbol.sdk.model.transaction.CosignatureSignedTransaction) Listener(io.nem.symbol.sdk.api.Listener) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) MultisigAccountInfo(io.nem.symbol.sdk.model.account.MultisigAccountInfo) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 49 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId in project nem2-sdk-java by nemtech.

the class MosaicMetadataIntegrationTest method addMetadataToMosaic.

@ParameterizedTest
@EnumSource(RepositoryType.class)
public void addMetadataToMosaic(RepositoryType type) {
    MosaicId targetMosaicId = createMosaic(type);
    NamespaceId alias = setMosaicAlias(type, targetMosaicId, "mosaicalias" + targetMosaicId.getIdAsHex().toLowerCase());
    String message = "This is the message in the mosaic!";
    BigInteger key = BigInteger.TEN;
    MosaicMetadataTransaction transaction = MosaicMetadataTransactionFactory.create(getNetworkType(), getDeadline(), testAccount.getAddress(), alias, key, StringEncoder.getBytes(message)).maxFee(maxFee).build();
    AggregateTransaction aggregateTransaction = AggregateTransactionFactory.createComplete(getNetworkType(), getDeadline(), Collections.singletonList(transaction.toAggregate(testAccount.getPublicAccount()))).maxFee(maxFee).build();
    AggregateTransaction announceCorrectly = announceAndValidate(type, testAccount, aggregateTransaction);
    Assertions.assertEquals(aggregateTransaction.getType(), announceCorrectly.getType());
    Assertions.assertEquals(testAccount.getPublicAccount(), announceCorrectly.getSigner().get());
    Assertions.assertEquals(1, announceCorrectly.getInnerTransactions().size());
    Assertions.assertEquals(transaction.getType(), announceCorrectly.getInnerTransactions().get(0).getType());
    MosaicMetadataTransaction processedTransaction = (MosaicMetadataTransaction) announceCorrectly.getInnerTransactions().get(0);
    Assertions.assertEquals(transaction.getTargetMosaicId(), processedTransaction.getTargetMosaicId());
    Assertions.assertEquals(transaction.getValueSizeDelta(), processedTransaction.getValueSizeDelta());
    Assertions.assertEquals(transaction.getScopedMetadataKey(), processedTransaction.getScopedMetadataKey());
    System.out.println(targetMosaicId.getIdAsHex());
    System.out.println(key);
    sleep(5000);
    List<Metadata> metadata = get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetMosaicId).metadataType(MetadataType.MOSAIC))).getData();
    assertMetadata(targetMosaicId, transaction, metadata);
    assertMetadata(targetMosaicId, transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().targetId(targetMosaicId).metadataType(MetadataType.MOSAIC).scopedMetadataKey(key))).getData());
    assertMetadata(targetMosaicId, transaction, get(getRepositoryFactory(type).createMetadataRepository().search(new MetadataSearchCriteria().sourceAddress(testAccount.getAddress()).targetId(targetMosaicId).metadataType(MetadataType.MOSAIC).scopedMetadataKey(key))).getData());
    assertMetadata(targetMosaicId, transaction, metadata);
    Assertions.assertArrayEquals(StringEncoder.getBytes(message), processedTransaction.getValue());
}
Also used : MetadataSearchCriteria(io.nem.symbol.sdk.api.MetadataSearchCriteria) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) AggregateTransaction(io.nem.symbol.sdk.model.transaction.AggregateTransaction) MosaicMetadataTransaction(io.nem.symbol.sdk.model.transaction.MosaicMetadataTransaction) Metadata(io.nem.symbol.sdk.model.metadata.Metadata) BigInteger(java.math.BigInteger) NamespaceId(io.nem.symbol.sdk.model.namespace.NamespaceId) EnumSource(org.junit.jupiter.params.provider.EnumSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 50 with NamespaceId

use of io.nem.symbol.sdk.model.namespace.NamespaceId 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

NamespaceId (io.nem.symbol.sdk.model.namespace.NamespaceId)70 Test (org.junit.jupiter.api.Test)37 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)18 BigInteger (java.math.BigInteger)17 Account (io.nem.symbol.sdk.model.account.Account)15 Address (io.nem.symbol.sdk.model.account.Address)15 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 EnumSource (org.junit.jupiter.params.provider.EnumSource)14 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)10 PlainMessage (io.nem.symbol.sdk.model.message.PlainMessage)9 NamespaceName (io.nem.symbol.sdk.model.namespace.NamespaceName)8 AggregateTransaction (io.nem.symbol.sdk.model.transaction.AggregateTransaction)8 TransferTransaction (io.nem.symbol.sdk.model.transaction.TransferTransaction)8 RepositoryFactory (io.nem.symbol.sdk.api.RepositoryFactory)7 Observable (io.reactivex.Observable)7 List (java.util.List)7 Mosaic (io.nem.symbol.sdk.model.mosaic.Mosaic)6 Transaction (io.nem.symbol.sdk.model.transaction.Transaction)6 TransferTransactionFactory (io.nem.symbol.sdk.model.transaction.TransferTransactionFactory)6 ArrayList (java.util.ArrayList)6