Documentation ¶
Index ¶
- func MustRlpEncode(w io.Writer, val interface{})
- func VerifyProof(rootHash common.Hash, key []byte, proof map[string][]byte) (value []byte, err error)
- type BranchNode
- type Database
- type ExtensionNode
- type LeafNode
- type Node
- type Trie
- func (t *Trie) Commit(batch database.Batch) common.Hash
- func (t *Trie) Delete(key []byte) (bool, error)
- func (t *Trie) DeletePrefix(prefix []byte) (bool, error)
- func (t *Trie) Get(key []byte) ([]byte, bool, error)
- func (t *Trie) GetProof(key []byte) (map[string][]byte, error)
- func (t *Trie) Hash() common.Hash
- func (t *Trie) Put(key, value []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func MustRlpEncode ¶ added in v1.0.4
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 ¶
Database is used to load trie nodes by hash. It's levelDB in full node, and odrDB in light node.
type ExtensionNode ¶
ExtensionNode is extension node struct
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a Merkle Patricia Trie
func NewEmptyTrie ¶
NewEmptyTrie creates an empty trie tree.
func NewTrie ¶
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 ¶
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 ¶
Delete delete node with key in the trie return true is delete successfully;false mean the key not exist
func (*Trie) DeletePrefix ¶
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) GetProof ¶
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.