@@ -40,11 +40,24 @@ const (
4040 pointCacheSize = 4096
4141)
4242
43+ // PreimageReader wraps the function Preimage for accessing the preimage of
44+ // a given hash.
45+ type PreimageReader interface {
46+ // Preimage returns the preimage of associated hash.
47+ Preimage (hash common.Hash ) []byte
48+ }
49+
4350// Database wraps access to tries and contract code.
4451type Database interface {
52+ PreimageReader
53+
4554 // Reader returns a state reader associated with the specified state root.
4655 Reader (root common.Hash ) (Reader , error )
4756
57+ // Iteratee returns a state iteratee associated with the specified state root,
58+ // through which the account iterator and storage iterator can be created.
59+ Iteratee (root common.Hash ) (Iteratee , error )
60+
4861 // OpenTrie opens the main account trie.
4962 OpenTrie (root common.Hash ) (Trie , error )
5063
@@ -57,9 +70,6 @@ type Database interface {
5770 // TrieDB returns the underlying trie database for managing trie nodes.
5871 TrieDB () * triedb.Database
5972
60- // Snapshot returns the underlying state snapshot.
61- Snapshot () * snapshot.Tree
62-
6373 // Commit flushes all pending writes and finalizes the state transition,
6474 // committing the changes to the underlying storage. It returns an error
6575 // if the commit fails.
@@ -187,6 +197,11 @@ func (db *CachingDB) WithSnapshot(snapshot *snapshot.Tree) *CachingDB {
187197 return db
188198}
189199
200+ // Preimage returns the preimage of associated hash.
201+ func (db * CachingDB ) Preimage (hash common.Hash ) []byte {
202+ return db .triedb .Preimage (hash )
203+ }
204+
190205// Reader returns a state reader associated with the specified state root.
191206func (db * CachingDB ) Reader (stateRoot common.Hash ) (Reader , error ) {
192207 var readers []StateReader
@@ -277,11 +292,6 @@ func (db *CachingDB) PointCache() *utils.PointCache {
277292 return db .pointCache
278293}
279294
280- // Snapshot returns the underlying state snapshot.
281- func (db * CachingDB ) Snapshot () * snapshot.Tree {
282- return db .snap
283- }
284-
285295// Commit flushes all pending writes and finalizes the state transition,
286296// committing the changes to the underlying storage. It returns an error
287297// if the commit fails.
@@ -316,6 +326,12 @@ func (db *CachingDB) Commit(update *stateUpdate) error {
316326 return db .triedb .Update (update .root , update .originRoot , update .blockNumber , update .nodes , update .stateSet ())
317327}
318328
329+ // Iteratee returns a state iteratee associated with the specified state root,
330+ // through which the account iterator and storage iterator can be created.
331+ func (db * CachingDB ) Iteratee (root common.Hash ) (Iteratee , error ) {
332+ return newStateIteratee (! db .triedb .IsVerkle (), root , db .triedb , db .snap )
333+ }
334+
319335// mustCopyTrie returns a deep-copied trie.
320336func mustCopyTrie (t Trie ) Trie {
321337 switch t := t .(type ) {
0 commit comments