Search in sources :

Example 1 with RootNamespaceHistoryBuilder

use of io.nem.symbol.catapult.builders.RootNamespaceHistoryBuilder 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)1 HeightDto (io.nem.symbol.catapult.builders.HeightDto)1 NamespaceAliasBuilder (io.nem.symbol.catapult.builders.NamespaceAliasBuilder)1 NamespaceIdDto (io.nem.symbol.catapult.builders.NamespaceIdDto)1 NamespaceLifetimeBuilder (io.nem.symbol.catapult.builders.NamespaceLifetimeBuilder)1 NamespacePathBuilder (io.nem.symbol.catapult.builders.NamespacePathBuilder)1 RootNamespaceHistoryBuilder (io.nem.symbol.catapult.builders.RootNamespaceHistoryBuilder)1