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
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
artifact
staticartifact:Artifact
Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:16
Inherited from
stateType?
staticoptionalstateType:string
Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:17
Inherited from
deserializeState()
staticdeserializeState\<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 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()
staticloadArtifact(artifact): typeofSmartContractLib
Defined in: packages/scrypt-ts-opcat/src/smart-contract/smartContractLib.ts:19
Parameters
artifact
Returns
typeof SmartContractLib
Inherited from
stateHash()
staticstateHash\<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
The hash as a ByteString
State
serializeState()
staticserializeState\<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
Serialized state as ByteString
Throws
Error if artifact is not loaded, library not found in artifact, or state type is undefined