Search in sources :

Example 1 with MosaicBuilder

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

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

the class BalanceTransferReceipt method serialize.

/**
 * Serialize receipt and returns receipt bytes
 *
 * @return receipt bytes
 */
@Override
public byte[] serialize() {
    final short version = (short) getVersion().getValue();
    final ReceiptTypeDto type = ReceiptTypeDto.rawValueOf((short) getType().getValue());
    final MosaicBuilder mosaic = MosaicBuilder.create(new MosaicIdDto(getMosaicId().getIdAsLong()), SerializationUtils.toAmount(getAmount()));
    final AddressDto senderAddress = SerializationUtils.toAddressDto(getSenderAddress());
    final AddressDto recipientAddress = SerializationUtils.toAddressDto(getRecipientAddress());
    return BalanceTransferReceiptBuilder.create(version, type, mosaic, senderAddress, recipientAddress).serialize();
}
Also used : MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) AddressDto(io.nem.symbol.catapult.builders.AddressDto) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto)

Example 3 with MosaicBuilder

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

the class BalanceChangeReceipt method serialize.

/**
 * Serialize receipt and returns receipt bytes
 *
 * @return receipt bytes
 */
@Override
public byte[] serialize() {
    short version = (short) getVersion().getValue();
    ReceiptTypeDto type = ReceiptTypeDto.rawValueOf((short) getType().getValue());
    MosaicBuilder mosaic = MosaicBuilder.create(new MosaicIdDto(getMosaicId().getIdAsLong()), SerializationUtils.toAmount(getAmount()));
    AddressDto targetAddress = SerializationUtils.toAddressDto(getTargetAddress());
    return BalanceChangeReceiptBuilder.create(version, type, mosaic, targetAddress).serialize();
}
Also used : MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) AddressDto(io.nem.symbol.catapult.builders.AddressDto) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto)

Example 4 with MosaicBuilder

use of io.nem.symbol.catapult.builders.MosaicBuilder 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 5 with MosaicBuilder

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

Aggregations

MosaicBuilder (io.nem.symbol.catapult.builders.MosaicBuilder)6 AddressDto (io.nem.symbol.catapult.builders.AddressDto)5 HeightDto (io.nem.symbol.catapult.builders.HeightDto)3 MosaicIdDto (io.nem.symbol.catapult.builders.MosaicIdDto)3 ReceiptTypeDto (io.nem.symbol.catapult.builders.ReceiptTypeDto)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 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 PinnedVotingKeyBuilder (io.nem.symbol.catapult.builders.PinnedVotingKeyBuilder)1 VotingKeyDto (io.nem.symbol.catapult.builders.VotingKeyDto)1