trie

package
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2020 License: LGPL-3.0 Imports: 9 Imported by: 18

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MustRlpEncode added in v1.0.4

func MustRlpEncode(w io.Writer, val interface{})

func VerifyProof

func VerifyProof(rootHash common.Hash, key []byte, proof map[string][]byte) (value []byte, err error)

VerifyProof checks merkle proofs. The given proof must contain the value for key in a trie with the given root hash. VerifyProof returns an error if the proof contains invalid trie nodes or the wrong value.

Types

type BranchNode

type BranchNode struct {
	Node
	Children [numBranchChildren]noder
}

BranchNode is node for branch

type Database

type Database interface {
	Get(key []byte) ([]byte, error)
}

Database is used to load trie nodes by hash. It's levelDB in full node, and odrDB in light node.

type ExtensionNode

type ExtensionNode struct {
	Node
	Key      []byte // for shared nibbles
	NextNode noder  // for next node
}

ExtensionNode is extension node struct

type LeafNode

type LeafNode struct {
	Node
	Key   []byte // for key-end
	Value []byte // the value of leafnode
}

LeafNode is leaf node struct

type Node

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

Node is trie node struct

func (*Node) Hash

func (n *Node) Hash() []byte

Hash return the hash of node

func (*Node) SetHash

func (n *Node) SetHash(hash []byte)

SetHash set the node hash

func (*Node) SetStatus

func (n *Node) SetStatus(status nodeStatus)

SetStatus set the node status

func (*Node) Status

func (n *Node) Status() nodeStatus

Status return the status of node

type Trie

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

Trie is a Merkle Patricia Trie

func NewEmptyTrie

func NewEmptyTrie(dbprefix []byte, db Database) *Trie

NewEmptyTrie creates an empty trie tree.

func NewTrie

func NewTrie(root common.Hash, dbprefix []byte, db Database) (*Trie, error)

NewTrie new a trie tree param dbprefix will be used as prefix of hash key to save db. because we save all of trie trees in the same db,dbprefix protects key/values for different trees

func (*Trie) Commit

func (t *Trie) Commit(batch database.Batch) common.Hash

Commit commit the dirty node to database with given batch. Note, it will panic on nil batch, please use Hash() instead to get the root hash.

func (*Trie) Delete

func (t *Trie) Delete(key []byte) (bool, error)

Delete delete node with key in the trie return true is delete successfully;false mean the key not exist

func (*Trie) DeletePrefix

func (t *Trie) DeletePrefix(prefix []byte) (bool, error)

DeletePrefix deletes nodes with specified prefix in the trie. Return true if any node deleted, otherwise false. Note, no node deleted if the prefix is nil or empty.

func (*Trie) Get

func (t *Trie) Get(key []byte) ([]byte, bool, error)

Get get the value by key

func (*Trie) GetProof

func (t *Trie) GetProof(key []byte) (map[string][]byte, error)

GetProof constructs a merkle proof for key. The result contains all encoded nodes on the path to the value at key. The value itself is also included in the last node and can be retrieved by verifying the proof.

If the trie does not contain a value for key, the returned proof contains all nodes of the longest existing prefix of the key (at least the root node), ending with the node that proves the absence of the key.

func (*Trie) Hash

func (t *Trie) Hash() common.Hash

Hash return the hash of trie

func (*Trie) Put

func (t *Trie) Put(key, value []byte) error

Put add or update [key,value] in the trie

Jump to

Keyboard shortcuts

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