Documentation ¶
Overview ¶
Package trie implements Merkle Patricia Tries.
Index ¶
- Constants
- Variables
- func DecodeNode(hash, buf []byte) (node, error)
- func DecodeNodeLazy(hash, buf []byte) (node, error)
- type LeafCallback
- type MissingNodeError
- type NodeBase
- type Trie
- func (t *Trie) Commit(onleaf LeafCallback) (root Hash, err error)
- func (t *Trie) Delete(key []byte)
- func (t *Trie) Get(key []byte) []byte
- func (t *Trie) Hash() Hash
- func (t *Trie) Prove(key []byte) [][]byte
- func (t *Trie) TryDelete(key []byte) error
- func (t *Trie) TryGet(key []byte) ([]byte, error)
- func (t *Trie) TryProve(key []byte) ([][]byte, error)
- func (t *Trie) TryUpdate(key, value []byte) error
- func (t *Trie) Update(key, value []byte)
- type TrieFullNode
- type TrieHashNode
- type TrieShortNode
- type TrieValueNode
Constants ¶
const MptData = "mpt-data"
Variables ¶
var (
// emptyRoot is the known root hash of an empty trie.
EmptyRoot = HexToHash("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421")
)
Functions ¶
func DecodeNode ¶
DecodeNode parses the RLP encoding of a trie node.
func DecodeNodeLazy ¶
Types ¶
type LeafCallback ¶
LeafCallback is a callback type invoked when a trie operation reaches a leaf node. It's used by state sync and commit to allow handling external references between account and storage tries.
type MissingNodeError ¶
type MissingNodeError struct { NodeHash common.Hash // hash of the missing node Path []byte // hex-encoded path to the missing node }
MissingNodeError is returned by the trie functions (TryGet, Trgithub.com/yu-org/yupdate, TryDelete) in the case where a trie node is not present in the local database. It contains information necessary for retrieving the missing node.
func (*MissingNodeError) Error ¶
func (err *MissingNodeError) Error() string
type NodeBase ¶
type NodeBase struct {
// contains filtered or unexported fields
}
func NewNodeBase ¶
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a Merkle Patricia Trie. The zero value is an empty trie with no database. Use New to create a trie that sits on top of a database.
Trie is not safe for concurrent use.
func NewTrie ¶
NewTrie creates a trie with an existing root node from db.
If root is the zero hash or the sha3 hash of an empty string, the trie is initially empty and does not require a database. Otherwise, New will panic if db is nil and returns a MissingNodeError if root does not exist in the database. Accessing the trie loads nodes from db on demand.
func (*Trie) Commit ¶
func (t *Trie) Commit(onleaf LeafCallback) (root Hash, err error)
Commit writes all nodes to the trie's memory database, tracking the internal and external (for account tries) references.
func (*Trie) Get ¶
Get returns the value for key stored in the trie. The value bytes must not be modified by the caller.
func (*Trie) Hash ¶
func (t *Trie) Hash() Hash
Hash returns the root hash of the trie. It does not write to the database and can be used even if the trie doesn't have one.
func (*Trie) TryDelete ¶
TryDelete removes any existing value for key from the trie. If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) TryGet ¶
TryGet returns the value for key stored in the trie. The value bytes must not be modified by the caller. If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) TryUpdate ¶
TryUpdate associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.
If a node was not found in the database, a MissingNodeError is returned.
func (*Trie) Update ¶
Update associates key with value in the trie. Subsequent calls to Get will return value. If value has length zero, any existing value is deleted from the trie and calls to Get will return nil.
The value bytes must not be modified by the caller while they are stored in the trie.
type TrieFullNode ¶
type TrieFullNode struct { Children [17]node // Actual trie node data to encode/decode (needs custom encoder) // contains filtered or unexported fields }
type TrieHashNode ¶
type TrieHashNode []byte
func (TrieHashNode) String ¶
func (n TrieHashNode) String() string
type TrieShortNode ¶
type TrieShortNode struct { Key []byte Val node // contains filtered or unexported fields }
func (*TrieShortNode) String ¶
func (n *TrieShortNode) String() string
type TrieValueNode ¶
type TrieValueNode []byte
func (TrieValueNode) String ¶
func (n TrieValueNode) String() string