Documentation
¶
Index ¶
- Variables
- func HashDomains(domains ...string) []byte
- func HashDomainsPrefix(domains ...string) []byte
- type Action
- type Entry
- type Iterator
- type IteratorState
- type MerkleProof
- type Trie
- func (t *Trie) Clone() (*Trie, error)
- func (t *Trie) CopyTo(storage storage.Storage, needChangelog bool) (*Trie, error)
- func (t *Trie) Del(key []byte) ([]byte, error)
- func (t *Trie) Empty() bool
- func (t *Trie) Get(key []byte) ([]byte, error)
- func (t *Trie) Iterator(prefix []byte) (*Iterator, error)
- func (t *Trie) Prove(key []byte) (MerkleProof, error)
- func (t *Trie) Put(key []byte, val []byte) ([]byte, error)
- func (t *Trie) Replay(ft *Trie) ([]byte, error)
- func (t *Trie) RootHash() []byte
- func (t *Trie) SyncPath(rootHash []byte, key []byte) error
- func (t *Trie) SyncTrie(rootHash []byte) error
- func (t *Trie) Verify(rootHash []byte, key []byte, proof MerkleProof) error
Constants ¶
This section is empty.
Variables ¶
var ( ErrNotFound = storage.ErrKeyNotFound ErrInvalidProtoToNode = errors.New("Pb Message cannot be converted into Trie Node") )
Errors
var (
ErrNotIterable = errors.New("leaf node is not iterable")
)
errors constants
Functions ¶
func HashDomains ¶ added in v0.3.0
HashDomains for each variable in contract each domain will represented as 6 bytes, support 4 level domain at most such as, 4a56b7 000000 000000 000000, 4a56b8 1c9812 000000 000000, 4a56b8 3a1289 000000 000000, support iterator with same prefix
func HashDomainsPrefix ¶ added in v0.3.0
HashDomainsPrefix is same as HashDomains, but without tail zeros
Types ¶
type Entry ¶ added in v0.3.0
type Entry struct {
// contains filtered or unexported fields
}
Entry in log, [key, old value, new value]
type Iterator ¶ added in v0.3.0
type Iterator struct {
// contains filtered or unexported fields
}
Iterator to traverse leaf node in a trie
type IteratorState ¶ added in v0.3.0
type IteratorState struct {
// contains filtered or unexported fields
}
IteratorState represents the intermediate statue in iterator
type MerkleProof ¶
type MerkleProof [][][]byte
MerkleProof is a path from root to the proved node every element in path is the value of a node
type Trie ¶
type Trie struct {
// contains filtered or unexported fields
}
Trie is a Merkle Patricia Trie, consists of three kinds of nodes, Branch Node: 16-elements array, value is [hash_0, hash_1, ..., hash_f, hash] Extension Node: 3-elements array, value is [ext flag, prefix path, next hash] Leaf Node: 3-elements array, value is [leaf flag, suffix path, value]
func (*Trie) Del ¶
Del the node's value in trie
ext(ext->leaf-->leaf,ext->ext--->ext)
branch(branch->leaf-->leaf,branch->branch-->ext->branch,branch->ext-->ext)
ext ext | | branch --> leaf --> leaf / \
[leaf] leaf
branch ext / \ |
[leaf] ext --> branch
| branch branch ext / \ |
[leaf] branch --> branch
/ \ / \ leaf leaf leaf leaf
func (*Trie) Prove ¶
func (t *Trie) Prove(key []byte) (MerkleProof, error)
Prove the associated node to the key exists in trie if exists, MerkleProof is a complete path from root to the node otherwise, MerkleProof is nil
func (*Trie) SyncPath ¶
SyncPath from rootHash to key node from other servers Useful for verification quickly