Skip to main content

StateLib

@opcat-labs/scrypt-ts-opcat v1.0.4


@opcat-labs/scrypt-ts-opcat / StateLib

Class: StateLib\<ST>

Defined in: packages/scrypt-ts-opcat/src/smart-contract/builtin-libs/stateLib.ts:15

Library for computing the hash of a state.

Onchain​

Extends​

Type Parameters​

• ST extends OpcatState

Constructors​

new StateLib()​

new StateLib\<ST>(...args): StateLib\<ST>

Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:32

Parameters​

args​

...SupportedParamType[]

Returns​

StateLib\<ST>

Inherited from​

SmartContractLib.constructor

Other​

__state_lib_dummy_private_field__​

protected __state_lib_dummy_private_field__: ST

Defined in: packages/scrypt-ts-opcat/src/smart-contract/builtin-libs/stateLib.ts:99


args​

args: any[] = []

Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:31

Inherited from​

SmartContractLib.args


artifact​

static artifact: Artifact

Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:16

Inherited from​

SmartContractLib.artifact


stateType?​

static optional stateType: string

Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:17

Inherited from​

SmartContractLib.stateType


deserializeState()​

static deserializeState\<T>(this, serializedState): T

Defined in: packages/scrypt-ts-opcat/src/smart-contract/builtin-libs/stateLib.ts:60

Deserializes a state object from its ByteString representation.

Type Parameters​

• T extends StructObject

Type of the state object extending OpcatState

Parameters​

this​

(...args) => StateLib\<T>

Reference to the StateLib class constructor

serializedState​

ByteString

ByteString containing the serialized state data

Returns​

T

The deserialized state object of type T

Throws​

Error if artifact is not loaded, library is not found, or state type is undefined


loadArtifact()​

static loadArtifact(artifact): typeof SmartContractLib

Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:19

Parameters​

artifact​

Artifact

Returns​

typeof SmartContractLib

Inherited from​

SmartContractLib.loadArtifact


stateHash()​

static stateHash\<T>(this, state): ByteString

Defined in: packages/scrypt-ts-opcat/src/smart-contract/builtin-libs/stateLib.ts:91

Computes the SHA-256 hash of a serialized state object.

Type Parameters​

• T extends StructObject

Type extending OpcatState

Parameters​

this​

(...args) => StateLib\<T>

state​

T

The state object to hash

Returns​

ByteString

The hash as a ByteString

State​

serializeState()​

static serializeState\<T>(this, state): ByteString

Defined in: packages/scrypt-ts-opcat/src/smart-contract/builtin-libs/stateLib.ts:25

Serializes the given state object into a ByteString using the library's artifact.

Type Parameters​

• T extends StructObject

Type of the state object extending OpcatState

Parameters​

this​

(...args) => StateLib\<T>

Reference to the StateLib class constructor

state​

T

State object to be serialized

Returns​

ByteString

Serialized state as ByteString

Throws​

Error if artifact is not loaded, library not found in artifact, or state type is undefined