state/Trie接口
// Trie is a Ethereum Merkle Trie.
type Trie interface {
TryGet(key []byte) ([]byte, error)
TryUpdate(key, value []byte) error
TryDelete(key []byte) error
Commit(onleaf trie.LeafCallback) (common.Hash, error)
Hash() common.Hash
NodeIterator(startKey []byte) trie.NodeIterator
GetKey([]byte) []byte // TODO(fjl): remove this when SecureTrie is removed
Prove(key []byte, fromLevel uint, proofDb ethdb.Putter) error
}
Trie接口中定义的方法有Get、Put等操作/查询数据的方法,除此之外,Trie作为数据结构,在进行持久化时需要自定义持久化的数据结构,Commit方法则为进行持久化时的操作。
Trie接口的实现主要是SecureTrie。cachedTrie结构中包含了匿名成员SecureTrie,所以cachedTrie也算Trie接口的实现。SecureTrie位于trie包下,内部是trie/Trie结构体(非接口)的封装,trie/Trie结构体是Trie数据结构的具体实现。
state/Database接口
// Database wraps access