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

com.casper.sdk.model.transaction.target.Session 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.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonTypeName;
import dev.oak3.sbs4j.SerializerBuffer;
import dev.oak3.sbs4j.exception.ValueSerializationException;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * The execution target is the included module bytes, i.e. compiled Wasm.
 *
 * @author [email protected]
 */
@NoArgsConstructor
@Getter
@Setter
@JsonTypeName("Session")
public class Session implements TransactionTarget {

    /** The compiled Wasm. */
    @JsonProperty("module_bytes")
    private byte[] moduleBytes;
    /** The execution runtime to use. */
    @JsonProperty("runtime")
    private TransactionRuntime runtime;

    public Session(final byte[] moduleBytes, final TransactionRuntime runtime) {
        this.moduleBytes = moduleBytes;
        this.runtime = runtime;
    }

    @Override
    public void serialize(final SerializerBuffer ser, final Target target) throws ValueSerializationException, NoSuchTypeException {
        ser.writeU8(getByteTag());
        if (moduleBytes != null) {
            ser.writeI32(moduleBytes.length);
            ser.writeByteArray(moduleBytes);
        } else {
            ser.writeI32(0);
        }
        runtime.serialize(ser, target);
    }

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy