Search in sources :

Example 1 with NamespacePathBuilder

use of io.nem.symbol.catapult.builders.NamespacePathBuilder in project nem2-sdk-java by nemtech.

the class NamespaceInfo method toNamespaceAliasTypeDto.

private NamespacePathBuilder toNamespaceAliasTypeDto(NamespaceInfo namespaceInfo) {
    List<NamespaceIdDto> path = namespaceInfo.getLevels().stream().skip(1).map(id -> new NamespaceIdDto(id.getIdAsLong())).collect(Collectors.toList());
    NamespaceAliasBuilder alias = namespaceInfo.getAlias().createAliasBuilder();
    return NamespacePathBuilder.create(path, alias);
}
Also used : HeightDto(io.nem.symbol.catapult.builders.HeightDto) NamespacePathBuilder(io.nem.symbol.catapult.builders.NamespacePathBuilder) NamespaceIdDto(io.nem.symbol.catapult.builders.NamespaceIdDto) NamespaceLifetimeBuilder(io.nem.symbol.catapult.builders.NamespaceLifetimeBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Stored(io.nem.symbol.sdk.model.Stored) List(java.util.List) NamespaceAliasBuilder(io.nem.symbol.catapult.builders.NamespaceAliasBuilder) RootNamespaceHistoryBuilder(io.nem.symbol.catapult.builders.RootNamespaceHistoryBuilder) Validate(org.apache.commons.lang3.Validate) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) Comparator(java.util.Comparator) SerializationUtils(io.nem.symbol.sdk.infrastructure.SerializationUtils) NamespaceIdDto(io.nem.symbol.catapult.builders.NamespaceIdDto) NamespaceAliasBuilder(io.nem.symbol.catapult.builders.NamespaceAliasBuilder)

Example 2 with NamespacePathBuilder

use of io.nem.symbol.catapult.builders.NamespacePathBuilder in project nem2-sdk-java by nemtech.

the class NamespaceInfo method serialize.

/**
 * @return serializes the state of this object.
 */
public byte[] serialize(List<NamespaceInfo> fullPath) {
    if (!this.isRoot()) {
        throw new IllegalArgumentException("Namespace must be root in order to serialize!");
    }
    List<NamespaceInfo> children = sortList(fullPath, this.getId());
    if (fullPath.size() != children.size()) {
        throw new IllegalArgumentException("Some of the children do not belong to this root namespace");
    }
    NamespaceIdDto id = new NamespaceIdDto(getId().getIdAsLong());
    AddressDto ownerAddress = SerializationUtils.toAddressDto(getOwnerAddress());
    NamespaceLifetimeBuilder lifetime = NamespaceLifetimeBuilder.create(new HeightDto(getStartHeight().longValue()), new HeightDto(getEndHeight().longValue()));
    NamespaceAliasBuilder rootAlias = getAlias().createAliasBuilder();
    List<NamespacePathBuilder> paths = children.stream().map(this::toNamespaceAliasTypeDto).collect(Collectors.toList());
    RootNamespaceHistoryBuilder builder = RootNamespaceHistoryBuilder.create((short) getVersion(), id, ownerAddress, lifetime, rootAlias, paths);
    return builder.serialize();
}
Also used : NamespaceIdDto(io.nem.symbol.catapult.builders.NamespaceIdDto) RootNamespaceHistoryBuilder(io.nem.symbol.catapult.builders.RootNamespaceHistoryBuilder) NamespaceLifetimeBuilder(io.nem.symbol.catapult.builders.NamespaceLifetimeBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) HeightDto(io.nem.symbol.catapult.builders.HeightDto) NamespaceAliasBuilder(io.nem.symbol.catapult.builders.NamespaceAliasBuilder) NamespacePathBuilder(io.nem.symbol.catapult.builders.NamespacePathBuilder)

Aggregations

AddressDto (io.nem.symbol.catapult.builders.AddressDto)2 HeightDto (io.nem.symbol.catapult.builders.HeightDto)2 NamespaceAliasBuilder (io.nem.symbol.catapult.builders.NamespaceAliasBuilder)2 NamespaceIdDto (io.nem.symbol.catapult.builders.NamespaceIdDto)2 NamespaceLifetimeBuilder (io.nem.symbol.catapult.builders.NamespaceLifetimeBuilder)2 NamespacePathBuilder (io.nem.symbol.catapult.builders.NamespacePathBuilder)2 RootNamespaceHistoryBuilder (io.nem.symbol.catapult.builders.RootNamespaceHistoryBuilder)2 SerializationUtils (io.nem.symbol.sdk.infrastructure.SerializationUtils)1 Stored (io.nem.symbol.sdk.model.Stored)1 Address (io.nem.symbol.sdk.model.account.Address)1 BigInteger (java.math.BigInteger)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 Validate (org.apache.commons.lang3.Validate)1