trie

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2021 License: LGPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ChildStorageKeyPrefix = []byte(":child_storage:default:")

ChildStorageKeyPrefix is the prefix for all child storage keys

View Source
var EmptyHash, _ = NewEmptyTrie().Hash()

nolint

Functions

func GetFromDB added in v0.3.0

func GetFromDB(db chaindb.Database, root common.Hash, key []byte) ([]byte, error)

GetFromDB retrieves a value from the trie using the database. It recursively descends into the trie using the database starting from the root node until it reaches the node with the given key. It then reads the value from the database.

Types

type Hasher

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

Hasher is a wrapper around a hash function

func NewHasher

func NewHasher() (*Hasher, error)

NewHasher create new Hasher instance

func (*Hasher) Hash

func (h *Hasher) Hash(n node) (res []byte, err error)

Hash encodes the node and then hashes it if its encoded length is > 32 bytes

type Test

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

Test represents a key-value pair for a test

func GenerateRandomTests

func GenerateRandomTests(t *testing.T, size int) []Test

GenerateRandomTests returns an array of random Tests

func (*Test) Key

func (t *Test) Key() []byte

Key returns the test key

func (*Test) Value

func (t *Test) Value() []byte

Value returns the test value

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 NewTrie to create a trie that sits on top of a database.

func NewEmptyTrie

func NewEmptyTrie() *Trie

NewEmptyTrie creates a trie with a nil root

func NewTrie

func NewTrie(root node) *Trie

NewTrie creates a trie with an existing root node

func (*Trie) ClearFromChild added in v0.2.0

func (t *Trie) ClearFromChild(keyToChild, key []byte) error

ClearFromChild removes the child storage entry

func (*Trie) ClearPrefix added in v0.3.0

func (t *Trie) ClearPrefix(prefix []byte)

ClearPrefix deletes all key-value pairs from the trie where the key starts with the given prefix

func (*Trie) ClearPrefixFromDB added in v0.3.0

func (t *Trie) ClearPrefixFromDB(db chaindb.Database, prefix []byte) error

ClearPrefixFromDB deletes all keys with the given prefix from the trie and writes the updated nodes the database. Since it needs to write all the nodes from the changed node up to the root, it writes these in a batch operation.

func (*Trie) Decode

func (t *Trie) Decode(enc []byte) error

Decode decodes a trie from the DB and sets the receiver to it The encoded trie must have been encoded with t.Encode

func (*Trie) DeepCopy added in v0.2.0

func (t *Trie) DeepCopy() (*Trie, error)

DeepCopy makes a new trie and copies over the existing trie into the new trie

func (*Trie) Delete

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

Delete removes any existing value for key from the trie.

func (*Trie) DeleteFromChild added in v0.2.0

func (t *Trie) DeleteFromChild(keyToChild []byte) error

DeleteFromChild deletes from child storage

func (*Trie) DeleteFromDB added in v0.3.0

func (t *Trie) DeleteFromDB(db chaindb.Database, key []byte) error

DeleteFromDB deletes a value from the trie and writes the updated nodes the database. Since it needs to write all the nodes from the changed node up to the root, it writes these in a batch operation.

func (*Trie) Encode

func (t *Trie) Encode() ([]byte, error)

Encode traverses the trie recursively, encodes each node, SCALE encodes the encoded node, and appends them all together

func (*Trie) EncodeRoot

func (t *Trie) EncodeRoot() ([]byte, error)

EncodeRoot returns the encoded root of the trie

func (*Trie) Entries

func (t *Trie) Entries() map[string][]byte

Entries returns all the key-value pairs in the trie as a map of keys to values

func (*Trie) Get

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

Get returns the value for key stored in the trie at the corresponding key

func (*Trie) GetChild

func (t *Trie) GetChild(keyToChild []byte) (*Trie, error)

GetChild returns the child trie at key :child_storage:[keyToChild]

func (*Trie) GetFromChild

func (t *Trie) GetFromChild(keyToChild, key []byte) ([]byte, error)

GetFromChild retrieves a key-value pair from the child trie located in the main trie at key :child_storage:[keyToChild]

func (*Trie) GetKeysWithPrefix added in v0.2.0

func (t *Trie) GetKeysWithPrefix(prefix []byte) [][]byte

GetKeysWithPrefix returns all keys in the trie that have the given prefix

func (*Trie) Hash

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

Hash returns the hashed root of the trie

func (*Trie) Load

func (t *Trie) Load(db chaindb.Database, root common.Hash) error

Load reconstructs the trie from the database from the given root hash. Used when restarting the node to load the current state trie.

func (*Trie) LoadFromMap added in v0.3.0

func (t *Trie) LoadFromMap(data map[string]string) error

LoadFromMap loads the given data into trie

func (*Trie) MustHash added in v0.2.0

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

MustHash returns the hashed root of the trie. It panics if it fails to hash the root node.

func (*Trie) NextKey added in v0.2.0

func (t *Trie) NextKey(key []byte) []byte

NextKey returns the next key in the trie in lexicographic order. It returns nil if there is no next key

func (*Trie) Print

func (t *Trie) Print()

Print prints the trie through pre-order traversal

func (*Trie) Put

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

Put inserts a key with value into the trie

func (*Trie) PutChild

func (t *Trie) PutChild(keyToChild []byte, child *Trie) error

PutChild inserts a child trie into the main trie at key :child_storage:[keyToChild]

func (*Trie) PutInDB added in v0.3.0

func (t *Trie) PutInDB(db chaindb.Database, key, value []byte) error

PutInDB puts a value into the trie and writes the updates nodes the database. Since it needs to write all the nodes from the changed node up to the root, it writes these in a batch operation.

func (*Trie) PutIntoChild

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

PutIntoChild puts a key-value pair into the child trie located in the main trie at key :child_storage:[keyToChild]

func (*Trie) RootNode

func (t *Trie) RootNode() node

RootNode returns the root of the trie

func (*Trie) Snapshot added in v0.3.0

func (t *Trie) Snapshot() *Trie

Snapshot created a copy of the trie.

func (*Trie) Store added in v0.3.0

func (t *Trie) Store(db chaindb.Database) error

Store stores each trie node in the database, where the key is the hash of the encoded node and the value is the encoded node. Generally, this will only be used for the genesis trie.

func (*Trie) String

func (t *Trie) String() string

String returns the trie stringified through pre-order traversal

func (*Trie) WriteDirty added in v0.3.0

func (t *Trie) WriteDirty(db chaindb.Database) error

WriteDirty writes all dirty nodes to the database and sets them to clean

Jump to

Keyboard shortcuts

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