Skip to main content

LedgerState

@midnight/ledger v7.0.0


@midnight/ledger / LedgerState

Class: LedgerState

The state of the Midnight ledger

Constructors

Constructor

new LedgerState(network_id, zswap): LedgerState;

Intializes from a Zswap state, with an empty contract set

Parameters

network_id

string

zswap

ZswapChainState

Returns

LedgerState

Properties

blockRewardPool

readonly blockRewardPool: bigint;

The remaining unrewarded supply of native tokens.


dust

readonly dust: DustState;

The dust subsystem state


lockedPool

readonly lockedPool: bigint;

The remaining size of the locked Night pool.


parameters

parameters: LedgerParameters;

The parameters of the ledger


reservePool

readonly reservePool: bigint;

The size of the reserve Night pool


utxo

readonly utxo: UtxoState;

The unshielded utxos present


zswap

readonly zswap: ZswapChainState;

The Zswap part of the ledger state

Methods

apply()

apply(transaction, context): [LedgerState, TransactionResult];

Applies a Transaction

Parameters

transaction

VerifiedTransaction

context

TransactionContext

Returns

[LedgerState, TransactionResult]


applySystemTx()

applySystemTx(transaction, tblock): [LedgerState, Event[]];

Applies a system transaction to this ledger state.

Parameters

transaction

SystemTransaction

tblock

Date

Returns

[LedgerState, Event[]]


bridgeReceiving()

Call Signature

bridgeReceiving(recipient): bigint;

How much in bridged night a recipient is owed and can claim.

Parameters
recipient

string

Returns

bigint

Call Signature

bridgeReceiving(recipient): bigint;

How much in bridged night a recipient is owed and can claim.

Parameters
recipient

string

Returns

bigint


index()

index(address): undefined | ContractState;

Indexes into the contract state map with a given contract address

Parameters

address

string

Returns

undefined | ContractState


postBlockUpdate()

postBlockUpdate(
tblock,
detailedBlockFullness?,
overallBlockFullness?): LedgerState;

Carries out a post-block update, which does amortized bookkeeping that only needs to be done once per state change.

Typically, postBlockUpdate should be run after any (sequence of) (system)-transaction application(s).

Parameters

tblock

Date

detailedBlockFullness?

NormalizedCost

overallBlockFullness?

number

Returns

LedgerState


serialize()

serialize(): Uint8Array;

Returns

Uint8Array


testingDistributeNight()

testingDistributeNight(
recipient,
amount,
tblock): LedgerState;

Allows distributing the specified amount of Night to the recipient's address. Use is for testing purposes only.

Parameters

recipient

string

amount

bigint

tblock

Date

Returns

LedgerState


toString()

toString(compact?): string;

Parameters

compact?

boolean

Returns

string


treasuryBalance()

treasuryBalance(token_type): bigint;

Retrieves the balance of the treasury for a specific token type.

Parameters

token_type

TokenType

Returns

bigint


unclaimedBlockRewards()

unclaimedBlockRewards(recipient): bigint;

How much in block rewards a recipient is owed and can claim.

Parameters

recipient

string

Returns

bigint


updateIndex()

updateIndex(
address,
state,
balance): LedgerState;

Sets the state of a given contract address from a ChargedState

Parameters

address

string

state

ChargedState

balance

Map<TokenType, bigint>

Returns

LedgerState


blank()

static blank(network_id): LedgerState;

A fully blank state

Parameters

network_id

string

Returns

LedgerState


deserialize()

static deserialize(raw): LedgerState;

Parameters

raw

Uint8Array

Returns

LedgerState