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());
}
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)));
}
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);
}
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());
}
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())));
}
Aggregations