Search in sources :

Example 1 with HeightDto

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

the class AccountInfo method serialize.

public byte[] serialize() {
    AddressDto address = SerializationUtils.toAddressDto(getAddress());
    HeightDto addressHeight = new HeightDto(getAddressHeight().longValue());
    KeyDto publicKey = SerializationUtils.toKeyDto(getPublicKey());
    HeightDto publicKeyHeight = new HeightDto(getPublicKeyHeight().longValue());
    AccountTypeDto accountType = AccountTypeDto.rawValueOf((byte) getAccountType().getValue());
    EnumSet<AccountKeyTypeFlagsDto> supplementalPublicKeysMask = getAccountKeyTypeFlags();
    KeyDto linkedPublicKey = getSupplementalAccountKeys().getLinked().map(SerializationUtils::toKeyDto).orElse(null);
    KeyDto nodePublicKey = getSupplementalAccountKeys().getNode().map(SerializationUtils::toKeyDto).orElse(null);
    KeyDto vrfPublicKey = getSupplementalAccountKeys().getVrf().map(SerializationUtils::toKeyDto).orElse(null);
    List<PinnedVotingKeyBuilder> votingPublicKeys = getSupplementalAccountKeys().getVoting().stream().map(this::toPinnedVotingKeyBuilder).collect(Collectors.toList());
    ImportanceDto importanceValue = new ImportanceDto(getImportance().getValue().longValue());
    ImportanceHeightDto importanceHeight = new ImportanceHeightDto(getImportance().getHeight().longValue());
    ImportanceSnapshotBuilder importanceSnapshots = ImportanceSnapshotBuilder.create(importanceValue, importanceHeight);
    HeightActivityBucketsBuilder activityBuckets = toHeightActivityBucketsBuilder();
    List<MosaicBuilder> balances = SerializationUtils.toMosaicBuilders(getMosaics());
    if (isHighValue()) {
        return AccountStateBuilder.createHighValue((short) getVersion(), address, addressHeight, publicKey, publicKeyHeight, accountType, supplementalPublicKeysMask, linkedPublicKey, nodePublicKey, vrfPublicKey, votingPublicKeys, importanceSnapshots, activityBuckets, balances).serialize();
    } else {
        return AccountStateBuilder.createRegular((short) getVersion(), address, addressHeight, publicKey, publicKeyHeight, accountType, supplementalPublicKeysMask, linkedPublicKey, nodePublicKey, vrfPublicKey, votingPublicKeys, balances).serialize();
    }
}
Also used : VotingKeyDto(io.nem.symbol.catapult.builders.VotingKeyDto) KeyDto(io.nem.symbol.catapult.builders.KeyDto) PinnedVotingKeyBuilder(io.nem.symbol.catapult.builders.PinnedVotingKeyBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) AccountKeyTypeFlagsDto(io.nem.symbol.catapult.builders.AccountKeyTypeFlagsDto) ImportanceHeightDto(io.nem.symbol.catapult.builders.ImportanceHeightDto) HeightDto(io.nem.symbol.catapult.builders.HeightDto) AccountTypeDto(io.nem.symbol.catapult.builders.AccountTypeDto) ImportanceDto(io.nem.symbol.catapult.builders.ImportanceDto) ImportanceHeightDto(io.nem.symbol.catapult.builders.ImportanceHeightDto) MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) ImportanceSnapshotBuilder(io.nem.symbol.catapult.builders.ImportanceSnapshotBuilder) HeightActivityBucketsBuilder(io.nem.symbol.catapult.builders.HeightActivityBucketsBuilder)

Example 2 with HeightDto

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

the class HashLockInfo method serialize.

/**
 * @return serializes the state of this object.
 */
public byte[] serialize() {
    AddressDto ownerAddress = SerializationUtils.toAddressDto(getOwnerAddress());
    MosaicBuilder mosaic = MosaicBuilder.create(SerializationUtils.toMosaicIdDto(getMosaicId()), SerializationUtils.toAmount(getAmount()));
    HeightDto endHeight = new HeightDto(getEndHeight().longValue());
    LockStatusDto status = LockStatusDto.rawValueOf(getStatus().getValue());
    Hash256Dto hash = SerializationUtils.toHash256Dto(getHash());
    return HashLockInfoBuilder.create((short) getVersion(), ownerAddress, mosaic, endHeight, status, hash).serialize();
}
Also used : Hash256Dto(io.nem.symbol.catapult.builders.Hash256Dto) MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) HeightDto(io.nem.symbol.catapult.builders.HeightDto) LockStatusDto(io.nem.symbol.catapult.builders.LockStatusDto)

Example 3 with HeightDto

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

the class SecretLockInfo method serialize.

/**
 * @return serializes the state of this object.
 */
public byte[] serialize() {
    short version = (short) getVersion();
    AddressDto ownerAddress = SerializationUtils.toAddressDto(getOwnerAddress());
    MosaicBuilder mosaic = MosaicBuilder.create(SerializationUtils.toMosaicIdDto(getMosaicId()), SerializationUtils.toAmount(getAmount()));
    HeightDto endHeight = new HeightDto(getEndHeight().longValue());
    LockStatusDto status = LockStatusDto.rawValueOf(getStatus().getValue());
    Hash256Dto secret = SerializationUtils.toHash256Dto(getSecret());
    AddressDto recipient = SerializationUtils.toAddressDto(getRecipientAddress());
    LockHashAlgorithmDto hashAlgorithm = LockHashAlgorithmDto.rawValueOf((byte) this.hashAlgorithm.getValue());
    return SecretLockInfoBuilder.create(version, ownerAddress, mosaic, endHeight, status, hashAlgorithm, secret, recipient).serialize();
}
Also used : Hash256Dto(io.nem.symbol.catapult.builders.Hash256Dto) MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) LockHashAlgorithmDto(io.nem.symbol.catapult.builders.LockHashAlgorithmDto) AddressDto(io.nem.symbol.catapult.builders.AddressDto) HeightDto(io.nem.symbol.catapult.builders.HeightDto) LockStatusDto(io.nem.symbol.catapult.builders.LockStatusDto)

Example 4 with HeightDto

use of io.nem.symbol.catapult.builders.HeightDto 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)

Example 5 with HeightDto

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

the class MosaicInfo method serialize.

/**
 * @return serializes the state of the mosaic.
 */
public byte[] serialize() {
    MosaicIdDto mosaicId = SerializationUtils.toMosaicIdDto(getMosaicId());
    AmountDto supply = SerializationUtils.toAmount(getSupply());
    HeightDto startHeight = new HeightDto(getStartHeight().longValue());
    AddressDto ownerAddress = SerializationUtils.toAddressDto(getOwnerAddress());
    int revision = (int) getRevision();
    EnumSet<MosaicFlagsDto> flags = SerializationUtils.getMosaicFlagsEnumSet(this.getMosaicFlags());
    MosaicPropertiesBuilder properties = MosaicPropertiesBuilder.create(flags, (byte) getDivisibility(), new BlockDurationDto(getDuration().longValue()));
    MosaicDefinitionBuilder definition = MosaicDefinitionBuilder.create(startHeight, ownerAddress, revision, properties);
    return MosaicEntryBuilder.create((short) getVersion(), mosaicId, supply, definition).serialize();
}
Also used : MosaicDefinitionBuilder(io.nem.symbol.catapult.builders.MosaicDefinitionBuilder) BlockDurationDto(io.nem.symbol.catapult.builders.BlockDurationDto) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) MosaicFlagsDto(io.nem.symbol.catapult.builders.MosaicFlagsDto) AmountDto(io.nem.symbol.catapult.builders.AmountDto) AddressDto(io.nem.symbol.catapult.builders.AddressDto) MosaicPropertiesBuilder(io.nem.symbol.catapult.builders.MosaicPropertiesBuilder) HeightDto(io.nem.symbol.catapult.builders.HeightDto)

Aggregations

AddressDto (io.nem.symbol.catapult.builders.AddressDto)5 HeightDto (io.nem.symbol.catapult.builders.HeightDto)5 MosaicBuilder (io.nem.symbol.catapult.builders.MosaicBuilder)3 Hash256Dto (io.nem.symbol.catapult.builders.Hash256Dto)2 LockStatusDto (io.nem.symbol.catapult.builders.LockStatusDto)2 AccountKeyTypeFlagsDto (io.nem.symbol.catapult.builders.AccountKeyTypeFlagsDto)1 AccountTypeDto (io.nem.symbol.catapult.builders.AccountTypeDto)1 AmountDto (io.nem.symbol.catapult.builders.AmountDto)1 BlockDurationDto (io.nem.symbol.catapult.builders.BlockDurationDto)1 HeightActivityBucketsBuilder (io.nem.symbol.catapult.builders.HeightActivityBucketsBuilder)1 ImportanceDto (io.nem.symbol.catapult.builders.ImportanceDto)1 ImportanceHeightDto (io.nem.symbol.catapult.builders.ImportanceHeightDto)1 ImportanceSnapshotBuilder (io.nem.symbol.catapult.builders.ImportanceSnapshotBuilder)1 KeyDto (io.nem.symbol.catapult.builders.KeyDto)1 LockHashAlgorithmDto (io.nem.symbol.catapult.builders.LockHashAlgorithmDto)1 MosaicDefinitionBuilder (io.nem.symbol.catapult.builders.MosaicDefinitionBuilder)1 MosaicFlagsDto (io.nem.symbol.catapult.builders.MosaicFlagsDto)1 MosaicIdDto (io.nem.symbol.catapult.builders.MosaicIdDto)1 MosaicPropertiesBuilder (io.nem.symbol.catapult.builders.MosaicPropertiesBuilder)1 NamespaceAliasBuilder (io.nem.symbol.catapult.builders.NamespaceAliasBuilder)1