github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/store/mpt/store_iterator.go (about) 1 package mpt 2 3 import ( 4 ethstate "github.com/ethereum/go-ethereum/core/state" 5 "github.com/ethereum/go-ethereum/trie" 6 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/store/types" 7 ) 8 9 var _ types.Iterator = (*mptIterator)(nil) 10 11 type mptIterator struct { 12 // Domain 13 start, end []byte 14 15 // Underlying store 16 iterator *trie.Iterator 17 trie ethstate.Trie 18 19 valid bool 20 } 21 22 func newMptIterator(t ethstate.Trie, start, end []byte) *mptIterator { 23 iter := &mptIterator{ 24 iterator: trie.NewIterator(t.NodeIterator(start)), 25 trie: t, 26 start: types.Cp(start), 27 end: nil, // enforce end is nil, because trie iterator origin key is out of order 28 valid: true, 29 } 30 iter.Next() 31 return iter 32 } 33 34 func (it *mptIterator) Domain() (start []byte, end []byte) { 35 return it.start, it.end 36 } 37 38 func (it *mptIterator) Valid() bool { 39 return it.valid 40 } 41 42 func (it *mptIterator) Next() { 43 if !it.iterator.Next() || it.iterator.Key == nil { 44 it.valid = false 45 } 46 } 47 48 func (it *mptIterator) Key() []byte { 49 key := it.iterator.Key 50 originKey := it.trie.GetKey(key) 51 return originKey 52 } 53 54 func (it *mptIterator) Value() []byte { 55 value := it.iterator.Value 56 return value 57 } 58 59 func (it *mptIterator) Error() error { 60 return it.iterator.Err 61 } 62 63 func (it *mptIterator) Close() { 64 return 65 }