ForgeSdk v0.34.0 ForgeSdk.StateDb protocol View Source

StateDb protocol for interact with kv store

Link to this section Summary

Functions

Close the database

When a block is committed, record the last block and the app hash for that block. Then return the app hash

Retrieve the state from an address

Retrieve the state from an address by given height

Retrieve the last block height and the app_hash of the states db for a given height

Retrieve the raw state (not final) from an address, used internally for migration. No cache is needed

Open a database for write/read

Put the state into to address in the db. This will lead to a change of root_hash

Travel to different block height. The returned db handler could be used to retrieve old state from the db

Link to this section Types

Link to this section Functions

Link to this function

close(handler) View Source
close(t()) :: :ok

Close the database

Link to this function

commit_block(handler, height) View Source
commit_block(t(), non_neg_integer()) :: binary()

When a block is committed, record the last block and the app hash for that block. Then return the app hash.

Link to this function

get(handler, address) View Source
get(t(), binary()) :: map() | nil

Retrieve the state from an address

Link to this function

get(handler, address, height) View Source
get(t(), binary(), non_neg_integer()) :: map() | nil

Retrieve the state from an address by given height

Link to this function

get_info(handler, height \\ 0) View Source
get_info(t(), non_neg_integer()) :: map()

Retrieve the last block height and the app_hash of the states db for a given height

Link to this function

get_raw(handler, address) View Source
get_raw(t(), binary()) :: map() | binary() | nil

Retrieve the raw state (not final) from an address, used internally for migration. No cache is needed.

Link to this function

open(handler) View Source
open(t()) :: {:ok, map()} | {:error, term()}

Open a database for write/read

Link to this function

put(handler, address, data) View Source
put(t(), binary(), map()) :: {:ok, t()} | {:error, term()}

Put the state into to address in the db. This will lead to a change of root_hash.

Link to this function

travel(handler, height) View Source
travel(t(), non_neg_integer() | nil) :: t()

Travel to different block height. The returned db handler could be used to retrieve old state from the db.