state

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 22, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClassTrieHeight           = 251
	ContractTrieHeight        = 251
	ContractStorageTrieHeight = 251
)

Variables

View Source
var (
	ErrContractNotDeployed        = errors.New("contract not deployed")
	ErrContractAlreadyDeployed    = errors.New("contract already deployed")
	ErrNoHistoryValue             = errors.New("no history value found")
	ErrHistoricalTrieNotSupported = errors.New("cannot support historical trie")
)

Functions

func DeleteClass

func DeleteClass(w db.KeyValueWriter, classHash *felt.Felt) error

func DeleteClassHashHistory

func DeleteClassHashHistory(w db.KeyValueWriter, addr *felt.Felt, blockNum uint64) error

func DeleteContract

func DeleteContract(w db.KeyValueWriter, addr *felt.Felt) error

func DeleteNonceHistory

func DeleteNonceHistory(w db.KeyValueWriter, addr *felt.Felt, blockNum uint64) error

func DeleteStorageHistory

func DeleteStorageHistory(w db.KeyValueWriter, addr, key *felt.Felt, blockNum uint64) error

func GetClass

func GetClass(r db.KeyValueReader, classHash *felt.Felt) (*core.DeclaredClassDefinition, error)

func GetContract

func GetContract(r db.KeyValueReader, addr *felt.Felt) (stateContract, error)

Gets a contract instance from the database. If it doesn't exist returns a contract not deployed error

func GetStateObject

func GetStateObject(r db.KeyValueReader, state *State, addr *felt.Felt) (*stateObject, error)

func HasClass

func HasClass(r db.KeyValueReader, classHash *felt.Felt) (bool, error)

func HasContract

func HasContract(r db.KeyValueReader, addr *felt.Felt) (bool, error)

func NewStateHistory

func NewStateHistory(blockNum uint64, stateRoot *felt.Felt, db *StateDB) (stateHistory, error)

func WriteClass

func WriteClass(
	w db.KeyValueWriter,
	classHash *felt.Felt,
	class core.ClassDefinition,
	declaredAt uint64,
) error

func WriteClassHashHistory

func WriteClassHashHistory(w db.KeyValueWriter, addr *felt.Felt, blockNum uint64, classHash *felt.Felt) error

func WriteContract

func WriteContract(w db.KeyValueWriter, addr *felt.Felt, contract *stateContract) error

func WriteNonceHistory

func WriteNonceHistory(w db.KeyValueWriter, addr *felt.Felt, blockNum uint64, nonce *felt.Felt) error

func WriteStorageHistory

func WriteStorageHistory(w db.KeyValueWriter, addr, key *felt.Felt, blockNum uint64, value *felt.Felt) error

Types

type State

type State struct {
	StateReader
	// contains filtered or unexported fields
}

State extends StateReader with mutation operations.

func New

func New(stateRoot *felt.Felt, db *StateDB, batch db.Batch) (*State, error)

New creates a writable state at the given root. The caller must provide a non-nil batch. Should be used for operations, where state mutations are required. Read operations are also supported.

func (*State) Revert

func (s *State) Revert(header *core.Header, update *core.StateUpdate) error

Revert a given state update. The block number is the block number of the state update.

func (*State) Update

func (s *State) Update(
	header *core.Header,
	update *core.StateUpdate,
	declaredClasses map[felt.Felt]core.ClassDefinition,
	skipVerifyNewRoot bool,
) error

Applies a state update to a given state. If any error is encountered, state is not updated. After a state update is applied, the root of the state must match the given new root in the state update.

type StateDB

type StateDB struct {
	// contains filtered or unexported fields
}

func NewStateDB

func NewStateDB(disk db.KeyValueStore, triedb database.TrieDB) *StateDB

func (*StateDB) ClassTrie

func (s *StateDB) ClassTrie(stateComm *felt.Felt) (*trie2.Trie, error)

Opens a class trie for the given state root

func (*StateDB) ContractStorageTrie

func (s *StateDB) ContractStorageTrie(stateComm, owner *felt.Felt) (*trie2.Trie, error)

Opens a contract storage trie for the given state root and contract address

func (*StateDB) ContractTrie

func (s *StateDB) ContractTrie(stateComm *felt.Felt) (*trie2.Trie, error)

Opens a contract trie for the given state root

type StateReader

type StateReader struct {
	// contains filtered or unexported fields
}

StateReader is a read-only view of the state at a given root.

func NewStateReader added in v0.16.0

func NewStateReader(stateRoot *felt.Felt, db *StateDB) (*StateReader, error)

NewStateReader creates a read-only view of the state at the given root. Should be used for read operations that don't require state mutations.

func (*StateReader) Class added in v0.16.0

func (s *StateReader) Class(classHash *felt.Felt) (*core.DeclaredClassDefinition, error)

func (*StateReader) ClassTrie added in v0.16.0

func (s *StateReader) ClassTrie() (core.Trie, error)

func (*StateReader) Commitment added in v0.16.0

func (s *StateReader) Commitment(protocolVersion string) (felt.Felt, error)

func (*StateReader) CompiledClassHash added in v0.16.0

func (s *StateReader) CompiledClassHash(
	classHash *felt.SierraClassHash,
) (felt.CasmClassHash, error)

func (*StateReader) CompiledClassHashAt added in v0.16.0

func (s *StateReader) CompiledClassHashAt(
	classHash *felt.SierraClassHash,
	blockNumber uint64,
) (felt.CasmClassHash, error)

func (*StateReader) CompiledClassHashV2 added in v0.16.0

func (s *StateReader) CompiledClassHashV2(
	classHash *felt.SierraClassHash,
) (felt.CasmClassHash, error)

func (*StateReader) ContractClassHash added in v0.16.0

func (s *StateReader) ContractClassHash(addr *felt.Felt) (felt.Felt, error)

func (*StateReader) ContractClassHashAt added in v0.16.0

func (s *StateReader) ContractClassHashAt(addr *felt.Felt, blockNum uint64) (felt.Felt, error)

Returns the class hash of a contract at a given block number.

func (*StateReader) ContractDeployedAt added in v0.16.0

func (s *StateReader) ContractDeployedAt(addr *felt.Felt, blockNum uint64) (bool, error)

func (*StateReader) ContractNonce added in v0.16.0

func (s *StateReader) ContractNonce(addr *felt.Felt) (felt.Felt, error)

func (*StateReader) ContractNonceAt added in v0.16.0

func (s *StateReader) ContractNonceAt(addr *felt.Felt, blockNum uint64) (felt.Felt, error)

Returns the nonce of a contract at a given block number.

func (*StateReader) ContractStorage added in v0.16.0

func (s *StateReader) ContractStorage(addr, key *felt.Felt) (felt.Felt, error)

ContractStorage reads a storage slot directly from the trie at this reader's root. Missing slots read as felt.Zero.

func (*StateReader) ContractStorageAt added in v0.16.0

func (s *StateReader) ContractStorageAt(addr, key *felt.Felt, blockNum uint64) (felt.Felt, error)

Returns the storage value of a contract at a given storage key at a given block number.

func (*StateReader) ContractStorageLastUpdatedAt added in v0.16.0

func (s *StateReader) ContractStorageLastUpdatedAt(
	addr *felt.Address,
	key *felt.Felt,
	blockNum uint64,
) (uint64, error)

Returns the block number at which a given storage slot key of a given contract was last updated, up to and including the given block number.

func (*StateReader) ContractStorageLastUpdatedBlock added in v0.16.0

func (s *StateReader) ContractStorageLastUpdatedBlock(
	addr *felt.Address,
	key *felt.Felt,
) (uint64, error)

ContractStorageLastUpdatedBlock returns the most recent block number at which a given storage slot key of a given contract was last updated.

func (*StateReader) ContractStorageTrie added in v0.16.0

func (s *StateReader) ContractStorageTrie(addr *felt.Felt) (core.Trie, error)

func (*StateReader) ContractTrie added in v0.16.0

func (s *StateReader) ContractTrie() (core.Trie, error)

func (*StateReader) GetReverseStateDiff added in v0.16.0

func (s *StateReader) GetReverseStateDiff(
	blockNum uint64,
	diff *core.StateDiff,
) (core.StateDiff, error)

type Storage

type Storage map[felt.Felt]*felt.Felt

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL