Skip to main content

ContractState

@midnight-ntwrk/onchain-runtime v2.0.1


@midnight-ntwrk/onchain-runtime / ContractState

Class: ContractState

The state of a contract, consisting primarily of the data accessible directly to the contract, and the map of ContractOperations that can be called on it, the keys of which can be accessed with operations, and the individual operations can be read with operation and written to with setOperation.

Constructors

new ContractState()

new ContractState(): ContractState

Creates a blank contract state

Returns

ContractState

Properties

balance

balance: Map<TokenType, bigint>;

The public balances held by this contract


data

data: ChargedState;

The current value of the primary state of the contract


maintenanceAuthority

maintenanceAuthority: ContractMaintenanceAuthority;

The maintenance authority associated with this contract

Methods

operation()

operation(operation): undefined | ContractOperation

Get the operation at a specific entry point name

Parameters

operation

string | Uint8Array<ArrayBufferLike>

Returns

undefined | ContractOperation


operations()

operations(): (string | Uint8Array<ArrayBufferLike>)[]

Return a list of the entry points currently registered on this contract

Returns

(string | Uint8Array<ArrayBufferLike>)[]


query()

query(query, cost_model): GatherResult[]

Runs a series of operations against the current state, and returns the results

Parameters

query

Op<null>[]

cost_model

CostModel

Returns

GatherResult[]


serialize()

serialize(): Uint8Array

Returns

Uint8Array


setOperation()

setOperation(operation, value): void

Set a specific entry point name to contain a given operation

Parameters

operation

string | Uint8Array<ArrayBufferLike>

value

ContractOperation

Returns

void


toString()

toString(compact?): string

Parameters

compact?

boolean

Returns

string


deserialize()

static deserialize(raw): ContractState

Parameters

raw

Uint8Array

Returns

ContractState