Help us shape the future of Go! Take the 2026 Go Developer Survey

trienode

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NilValueNode = (*ValueNode)(&felt.Felt{})

Used when collapsing internal trie nodes for hashing, since unset children need to be hashed correctly

Functions

func DecodeTriesRoots added in v0.14.7

func DecodeTriesRoots(val []byte) (felt.Felt, felt.Felt, error)

func EncodeNode

func EncodeNode(n Node) []byte

Returns the encoded bytes of a node

func NewNodeFlag

func NewNodeFlag() nodeFlag

Creates a new node flag and marks the node as dirty

Types

type BinaryNode

type BinaryNode struct {
	Children [2]Node // 0 = left, 1 = right
	Flags    nodeFlag
}

Represents a binary branch node in the trie with two children

func (*BinaryNode) Cache

func (n *BinaryNode) Cache() (*HashNode, bool)

func (*BinaryNode) Copy

func (n *BinaryNode) Copy() *BinaryNode

func (*BinaryNode) Hash

func (n *BinaryNode) Hash(hf crypto.HashFn) felt.Felt

func (*BinaryNode) Left

func (n *BinaryNode) Left() Node

func (*BinaryNode) Right

func (n *BinaryNode) Right() Node

func (*BinaryNode) String

func (n *BinaryNode) String() string

func (*BinaryNode) Write

func (n *BinaryNode) Write(buf *bytes.Buffer) error

Enc(binary) = binaryNodeType + HashNode(left) + HashNode(right)

type DeletedNode

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

func NewDeleted

func NewDeleted(isLeaf bool) *DeletedNode

func (*DeletedNode) Blob

func (r *DeletedNode) Blob() []byte

func (*DeletedNode) Hash

func (r *DeletedNode) Hash() felt.Felt

func (*DeletedNode) IsLeaf

func (r *DeletedNode) IsLeaf() bool

type EdgeNode

type EdgeNode struct {
	Child Node            // The child node at the end of the path
	Path  *trieutils.Path // The compressed path segment
	Flags nodeFlag
}

Represents a path-compressed node that stores a path segment and a single child node

func (*EdgeNode) Cache

func (n *EdgeNode) Cache() (*HashNode, bool)

func (*EdgeNode) CommonPath

func (n *EdgeNode) CommonPath(key *trieutils.Path) trieutils.Path

Returns the common bits between the current node and the given key, starting from the most significant bit

func (*EdgeNode) Copy

func (n *EdgeNode) Copy() *EdgeNode

func (*EdgeNode) Hash

func (n *EdgeNode) Hash(hf crypto.HashFn) felt.Felt

func (*EdgeNode) PathMatches

func (n *EdgeNode) PathMatches(key *trieutils.Path) bool

func (*EdgeNode) String

func (n *EdgeNode) String() string

func (*EdgeNode) Write

func (n *EdgeNode) Write(buf *bytes.Buffer) error

Enc(edge) = edgeNodeType + HashNode(child) + Path

type HashNode

type HashNode felt.Felt

Represents a node that only contains a hash reference to another node

func (*HashNode) Cache

func (n *HashNode) Cache() (*HashNode, bool)

func (*HashNode) Hash

func (n *HashNode) Hash(crypto.HashFn) felt.Felt

func (HashNode) String

func (n HashNode) String() string

func (*HashNode) Write

func (n *HashNode) Write(buf *bytes.Buffer) error

Enc(hash) = Felt

type LeafNode

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

func NewLeaf

func NewLeaf(hash felt.Felt, blob []byte) *LeafNode

func (*LeafNode) Blob

func (r *LeafNode) Blob() []byte

func (*LeafNode) Hash

func (r *LeafNode) Hash() felt.Felt

func (*LeafNode) IsLeaf

func (r *LeafNode) IsLeaf() bool

type MergeNodeSet

type MergeNodeSet struct {
	OwnerSet  *NodeSet                  // the node set of contract or class nodes
	ChildSets map[felt.Address]*NodeSet // each node set is indexed by the owner
}

func NewMergeNodeSet

func NewMergeNodeSet(nodes *NodeSet) *MergeNodeSet

func (*MergeNodeSet) Flatten

func (m *MergeNodeSet) Flatten() (
	map[trieutils.Path]TrieNode,
	map[felt.Address]map[trieutils.Path]TrieNode,
)

func (*MergeNodeSet) Merge

func (m *MergeNodeSet) Merge(other *NodeSet) error

type Node

type Node interface {
	Hash(crypto.HashFn) felt.Felt
	Cache() (*HashNode, bool)
	Write(*bytes.Buffer) error
	String() string
}

func DecodeNode

func DecodeNode(blob []byte, hash *felt.Felt, pathLen, maxPathLen uint8) (Node, error)

Decodes the encoded bytes and returns the corresponding node

type NodeSet

type NodeSet struct {
	Owner felt.Address // The owner (contract address)
	Nodes map[trieutils.Path]TrieNode
	// contains filtered or unexported fields
}

Contains a set of nodes, which are indexed by their path in the trie. It is not thread safe.

func NewNodeSet

func NewNodeSet(owner felt.Address) NodeSet

func (*NodeSet) Add

func (ns *NodeSet) Add(key *trieutils.Path, node TrieNode)

func (*NodeSet) ForEach

func (ns *NodeSet) ForEach(desc bool, callback func(key trieutils.Path, node TrieNode) error) error

Iterates over the nodes in a sorted order and calls the callback for each node.

func (*NodeSet) Merge

func (ns *NodeSet) Merge(owner felt.Address, other map[trieutils.Path]TrieNode) error

Adds a set of nodes to the current node set.

func (*NodeSet) MergeSet

func (ns *NodeSet) MergeSet(other *NodeSet) error

Merges the other node set into the current node set. The owner of both node sets must be the same.

type NonLeafNode

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

Represents a raw non-leaf trie node, which contains the encoded blob and the hash of the node.

func NewNonLeaf

func NewNonLeaf(hash felt.Felt, blob []byte) *NonLeafNode

func (*NonLeafNode) Blob

func (r *NonLeafNode) Blob() []byte

func (*NonLeafNode) Hash

func (r *NonLeafNode) Hash() felt.Felt

func (*NonLeafNode) IsLeaf

func (r *NonLeafNode) IsLeaf() bool

type TrieNode

type TrieNode interface {
	Blob() []byte
	// TODO(maksym): update to make Hash() return felt.Hash instead of felt.Felt
	Hash() felt.Felt
	IsLeaf() bool
}

type ValueNode

type ValueNode felt.Felt

Represents a leaf node that stores an actual value in the trie

func (*ValueNode) Cache

func (n *ValueNode) Cache() (*HashNode, bool)

func (*ValueNode) Hash

func (n *ValueNode) Hash(crypto.HashFn) felt.Felt

func (ValueNode) String

func (n ValueNode) String() string

func (*ValueNode) Write

func (n *ValueNode) Write(buf *bytes.Buffer) error

Enc(value) = Felt

Jump to

Keyboard shortcuts

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