Search in sources :

Example 1 with AddressDto

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

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

the class ResolutionEntry method serialize.

/**
 * Serialize receipt and returns receipt bytes
 *
 * @return receipt bytes
 */
public byte[] serialize() {
    ReceiptSourceBuilder receiptSourceBuilder = ReceiptSourceBuilder.create((int) getReceiptSource().getPrimaryId(), (int) getReceiptSource().getSecondaryId());
    Class<?> resolutionClass = this.resolved.getClass();
    if (Address.class.isAssignableFrom(resolutionClass)) {
        AddressDto addressBuilder = new AddressDto(SerializationUtils.fromAddressToByteBuffer((Address) getResolved()));
        AddressResolutionEntryBuilder builder = AddressResolutionEntryBuilder.create(receiptSourceBuilder, addressBuilder);
        return builder.serialize();
    } else {
        MosaicIdDto mosaicIdDto = SerializationUtils.toMosaicIdDto((MosaicId) getResolved());
        MosaicResolutionEntryBuilder builder = MosaicResolutionEntryBuilder.create(receiptSourceBuilder, mosaicIdDto);
        return builder.serialize();
    }
}
Also used : AddressResolutionEntryBuilder(io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder) Address(io.nem.symbol.sdk.model.account.Address) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) MosaicResolutionEntryBuilder(io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder) AddressDto(io.nem.symbol.catapult.builders.AddressDto) ReceiptSourceBuilder(io.nem.symbol.catapult.builders.ReceiptSourceBuilder)

Example 3 with AddressDto

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

the class MosaicAddressRestriction method serialize.

/**
 * @return serializes the state of this object.
 */
public byte[] serialize() {
    MosaicIdDto mosaicId = SerializationUtils.toMosaicIdDto(getMosaicId());
    AddressDto targetAddress = SerializationUtils.toAddressDto(getTargetAddress());
    AddressKeyValueSetBuilder restrictions = AddressKeyValueSetBuilder.create(getRestrictions().entrySet().stream().sorted(Entry.comparingByKey()).map(this::toAddressKeyValueBuilder).collect(Collectors.toList()));
    MosaicAddressRestrictionEntryBuilder entry = MosaicAddressRestrictionEntryBuilder.create(mosaicId, targetAddress, restrictions);
    return MosaicRestrictionEntryBuilder.createAddress((short) getVersion(), entry).serialize();
}
Also used : MosaicAddressRestrictionEntryBuilder(io.nem.symbol.catapult.builders.MosaicAddressRestrictionEntryBuilder) AddressKeyValueSetBuilder(io.nem.symbol.catapult.builders.AddressKeyValueSetBuilder) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) AddressDto(io.nem.symbol.catapult.builders.AddressDto)

Example 4 with AddressDto

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

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

Aggregations

AddressDto (io.nem.symbol.catapult.builders.AddressDto)12 HeightDto (io.nem.symbol.catapult.builders.HeightDto)5 MosaicBuilder (io.nem.symbol.catapult.builders.MosaicBuilder)5 MosaicIdDto (io.nem.symbol.catapult.builders.MosaicIdDto)5 Hash256Dto (io.nem.symbol.catapult.builders.Hash256Dto)2 LockStatusDto (io.nem.symbol.catapult.builders.LockStatusDto)2 ReceiptTypeDto (io.nem.symbol.catapult.builders.ReceiptTypeDto)2 AccountKeyTypeFlagsDto (io.nem.symbol.catapult.builders.AccountKeyTypeFlagsDto)1 AccountRestrictionsInfoBuilder (io.nem.symbol.catapult.builders.AccountRestrictionsInfoBuilder)1 AccountTypeDto (io.nem.symbol.catapult.builders.AccountTypeDto)1 AddressKeyValueSetBuilder (io.nem.symbol.catapult.builders.AddressKeyValueSetBuilder)1 AddressResolutionEntryBuilder (io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder)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