All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.casper.sdk.model.transaction.target.ByPackageHash Maven / Gradle / Ivy

Go to download

SDK to streamline the 3rd party Java client integration processes. Such 3rd parties include exchanges & app developers.

The newest version!
package com.casper.sdk.model.transaction.target;

import com.casper.sdk.exception.NoSuchTypeException;
import com.casper.sdk.model.clvalue.serde.Target;
import com.casper.sdk.model.common.Digest;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import lombok.*;

import java.util.Optional;

/**
 * The address and optional version identifying the package.
 *
 * @author [email protected]
 */
@NoArgsConstructor
@AllArgsConstructor
@Setter
@Getter
public class ByPackageHash implements TransactionInvocationTarget {
    /** The package address. */
    private Digest addr;
    /** If `None`, the latest enabled version is implied. */
    @Getter(AccessLevel.NONE)
    @JsonProperty("version")
    private Long version;

    @JsonIgnore
    public Optional getVersion() {
        return Optional.ofNullable(version);
    }

    @Override
    public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException {
        ser.writeU8(getByteTag());
        ser.writeByteArray(addr.getDigest());
        if (getVersion().isPresent()) {
            ser.writeBool(true);
            ser.writeU32(version);
        } else {
            ser.writeBool(false);
        }
    }

    @JsonIgnore
    @Override
    public byte getByteTag() {
        return 2;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy