Search in sources :

Example 6 with MosaicIdDto

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

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

the class MosaicGlobalRestriction method toGlobalKeyValueSetBuilder.

private GlobalKeyValueBuilder toGlobalKeyValueSetBuilder(Entry<BigInteger, MosaicGlobalRestrictionItem> entry) {
    MosaicRestrictionKeyDto key = new MosaicRestrictionKeyDto(entry.getKey().longValue());
    MosaicIdDto referenceMosaicId = SerializationUtils.toMosaicIdDto(entry.getValue().getReferenceMosaicId());
    long restrictionValue = entry.getValue().getRestrictionValue().longValue();
    MosaicRestrictionTypeDto restrictionType = MosaicRestrictionTypeDto.rawValueOf(entry.getValue().getRestrictionType().getValue());
    RestrictionRuleBuilder restrictionRule = RestrictionRuleBuilder.create(referenceMosaicId, restrictionValue, restrictionType);
    return GlobalKeyValueBuilder.create(key, restrictionRule);
}
Also used : MosaicRestrictionKeyDto(io.nem.symbol.catapult.builders.MosaicRestrictionKeyDto) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) MosaicRestrictionTypeDto(io.nem.symbol.catapult.builders.MosaicRestrictionTypeDto) RestrictionRuleBuilder(io.nem.symbol.catapult.builders.RestrictionRuleBuilder)

Example 8 with MosaicIdDto

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

Example 9 with MosaicIdDto

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

Example 10 with MosaicIdDto

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

the class ArtifactExpiryReceiptTest method shouldMosaicExpiryReceiptBuilderSerialize.

@Test
void shouldMosaicExpiryReceiptBuilderSerialize() {
    MosaicId mosaicId = new MosaicId("85BBEA6CC462B244");
    MosaicExpiryReceiptBuilder builder = MosaicExpiryReceiptBuilder.create((short) 1, ReceiptTypeDto.INFLATION, new MosaicIdDto(mosaicId.getId().longValue()));
    byte[] serialize = builder.serialize();
    // NOTE, size must be ignored for some reason!
    Assertions.assertEquals(12, serialize.length);
    Assertions.assertEquals(16, builder.getSize());
    String hex = ConvertUtils.toHex(serialize);
    Assertions.assertEquals("0100435144B262C46CEABB85", hex);
}
Also used : MosaicExpiryReceiptBuilder(io.nem.symbol.catapult.builders.MosaicExpiryReceiptBuilder) MosaicId(io.nem.symbol.sdk.model.mosaic.MosaicId) MosaicIdDto(io.nem.symbol.catapult.builders.MosaicIdDto) Test(org.junit.jupiter.api.Test)

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