Search in sources :

Example 1 with ReceiptTypeDto

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

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

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

the class InflationReceipt 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()));
    return InflationReceiptBuilder.create(version, type, mosaic).serialize();
}
Also used : MosaicBuilder(io.nem.symbol.catapult.builders.MosaicBuilder) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto)

Example 4 with ReceiptTypeDto

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

the class ResolutionStatement method serialize.

/**
 * Serializes the statement using the catuffer builders
 *
 * @param networkType the network type.
 * @return the serialized content.
 */
private byte[] serialize(NetworkType networkType) {
    ReceiptType type = this.resolutionType == ResolutionType.ADDRESS ? ReceiptType.ADDRESS_ALIAS_RESOLUTION : ReceiptType.MOSAIC_ALIAS_RESOLUTION;
    ReceiptTypeDto recipientTypeDto = ReceiptTypeDto.rawValueOf((short) type.getValue());
    short version = (short) ReceiptVersion.RESOLUTION_STATEMENT.getValue();
    Serializer serializer = this.resolutionType == ResolutionType.ADDRESS ? AddressResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedAddress((UnresolvedAddress) this.unresolved, networkType), this.resolutionEntries.stream().map((entry) -> AddressResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toAddressDto((Address) entry.getResolved()))).collect(Collectors.toList())) : MosaicResolutionStatementBuilder.create(version, recipientTypeDto, SerializationUtils.toUnresolvedMosaicIdDto((UnresolvedMosaicId) this.unresolved), this.resolutionEntries.stream().map((entry) -> MosaicResolutionEntryBuilder.create(ReceiptSourceBuilder.create((int) entry.getReceiptSource().getPrimaryId(), (int) entry.getReceiptSource().getSecondaryId()), SerializationUtils.toMosaicIdDto((MosaicId) entry.getResolved()))).collect(Collectors.toList()));
    return serializer.serialize();
}
Also used : UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicResolutionStatementBuilder(io.nem.symbol.catapult.builders.MosaicResolutionStatementBuilder) Hashes(io.nem.symbol.core.crypto.Hashes) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) ConvertUtils(io.nem.symbol.core.utils.ConvertUtils) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptSourceBuilder(io.nem.symbol.catapult.builders.ReceiptSourceBuilder) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Collectors(java.util.stream.Collectors) Stored(io.nem.symbol.sdk.model.Stored) AddressResolutionStatementBuilder(io.nem.symbol.catapult.builders.AddressResolutionStatementBuilder) MosaicResolutionEntryBuilder(io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder) Serializer(io.nem.symbol.catapult.builders.Serializer) List(java.util.List) AddressResolutionEntryBuilder(io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder) Optional(java.util.Optional) BigInteger(java.math.BigInteger) Address(io.nem.symbol.sdk.model.account.Address) NetworkType(io.nem.symbol.sdk.model.network.NetworkType) SerializationUtils(io.nem.symbol.sdk.infrastructure.SerializationUtils) UnresolvedAddress(io.nem.symbol.sdk.model.account.UnresolvedAddress) Address(io.nem.symbol.sdk.model.account.Address) UnresolvedMosaicId(io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto) Serializer(io.nem.symbol.catapult.builders.Serializer)

Example 5 with ReceiptTypeDto

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

the class ArtifactExpiryReceipt method serialize.

/**
 * Serialize receipt and returns receipt bytes
 *
 * @return receipt bytes
 */
public byte[] serialize() {
    short version = (short) getVersion().getValue();
    ReceiptTypeDto type = ReceiptTypeDto.rawValueOf((short) getType().getValue());
    if (this.artifactId instanceof MosaicId) {
        return MosaicExpiryReceiptBuilder.create(version, type, new MosaicIdDto(getArtifactIdValue().longValue())).serialize();
    } else {
        return NamespaceExpiryReceiptBuilder.create(version, type, new NamespaceIdDto(getArtifactIdValue().longValue())).serialize();
    }
}
Also used : NamespaceIdDto(io.nem.symbol.catapult.builders.NamespaceIdDto) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) ReceiptTypeDto(io.nem.symbol.catapult.builders.ReceiptTypeDto)

Aggregations

ReceiptTypeDto (io.nem.symbol.catapult.builders.ReceiptTypeDto)5 MosaicIdDto (io.nem.symbol.catapult.builders.MosaicIdDto)4 MosaicBuilder (io.nem.symbol.catapult.builders.MosaicBuilder)3 AddressDto (io.nem.symbol.catapult.builders.AddressDto)2 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 AddressResolutionEntryBuilder (io.nem.symbol.catapult.builders.AddressResolutionEntryBuilder)1 AddressResolutionStatementBuilder (io.nem.symbol.catapult.builders.AddressResolutionStatementBuilder)1 MosaicResolutionEntryBuilder (io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder)1 MosaicResolutionStatementBuilder (io.nem.symbol.catapult.builders.MosaicResolutionStatementBuilder)1 NamespaceIdDto (io.nem.symbol.catapult.builders.NamespaceIdDto)1 ReceiptSourceBuilder (io.nem.symbol.catapult.builders.ReceiptSourceBuilder)1 Serializer (io.nem.symbol.catapult.builders.Serializer)1 Hashes (io.nem.symbol.core.crypto.Hashes)1 ConvertUtils (io.nem.symbol.core.utils.ConvertUtils)1 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 UnresolvedAddress (io.nem.symbol.sdk.model.account.UnresolvedAddress)1 UnresolvedMosaicId (io.nem.symbol.sdk.model.mosaic.UnresolvedMosaicId)1 NetworkType (io.nem.symbol.sdk.model.network.NetworkType)1