Search in sources :

Example 1 with MosaicIdDto

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

the class MosaicGlobalRestriction method serialize.

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

Example 2 with MosaicIdDto

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

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

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

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

Aggregations

MosaicIdDto (io.nem.symbol.catapult.builders.MosaicIdDto)10 AddressDto (io.nem.symbol.catapult.builders.AddressDto)5 ReceiptTypeDto (io.nem.symbol.catapult.builders.ReceiptTypeDto)4 MosaicBuilder (io.nem.symbol.catapult.builders.MosaicBuilder)3 MosaicId (io.nem.symbol.sdk.model.mosaic.MosaicId)2 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 GlobalKeyValueSetBuilder (io.nem.symbol.catapult.builders.GlobalKeyValueSetBuilder)1 HeightDto (io.nem.symbol.catapult.builders.HeightDto)1 MosaicAddressRestrictionEntryBuilder (io.nem.symbol.catapult.builders.MosaicAddressRestrictionEntryBuilder)1 MosaicDefinitionBuilder (io.nem.symbol.catapult.builders.MosaicDefinitionBuilder)1 MosaicExpiryReceiptBuilder (io.nem.symbol.catapult.builders.MosaicExpiryReceiptBuilder)1 MosaicFlagsDto (io.nem.symbol.catapult.builders.MosaicFlagsDto)1 MosaicGlobalRestrictionEntryBuilder (io.nem.symbol.catapult.builders.MosaicGlobalRestrictionEntryBuilder)1 MosaicPropertiesBuilder (io.nem.symbol.catapult.builders.MosaicPropertiesBuilder)1 MosaicResolutionEntryBuilder (io.nem.symbol.catapult.builders.MosaicResolutionEntryBuilder)1 MosaicRestrictionKeyDto (io.nem.symbol.catapult.builders.MosaicRestrictionKeyDto)1 MosaicRestrictionTypeDto (io.nem.symbol.catapult.builders.MosaicRestrictionTypeDto)1