MCPcopy Create free account
hub / github.com/CPChain/chain / step

Method step

core/state/iterator.go:70–129  ·  view source on GitHub ↗

step moves the iterator to the next entry of the state trie.

()

Source from the content-addressed store, hash-verified

68
69// step moves the iterator to the next entry of the state trie.
70func (it *NodeIterator) step() error {
71 // Abort if we reached the end of the iteration
72 if it.state == nil {
73 return nil
74 }
75 // Initialize the iterator if we've just started
76 if it.stateIt == nil {
77 it.stateIt = it.state.trie.NodeIterator(nil)
78 }
79 // If we had data nodes previously, we surely have at least state nodes
80 if it.dataIt != nil {
81 if cont := it.dataIt.Next(true); !cont {
82 if it.dataIt.Error() != nil {
83 return it.dataIt.Error()
84 }
85 it.dataIt = nil
86 }
87 return nil
88 }
89 // If we had source code previously, discard that
90 if it.code != nil {
91 it.code = nil
92 return nil
93 }
94 // Step to the next state trie node, terminating if we're out of nodes
95 if cont := it.stateIt.Next(true); !cont {
96 if it.stateIt.Error() != nil {
97 return it.stateIt.Error()
98 }
99 it.state, it.stateIt = nil, nil
100 return nil
101 }
102 // If the state trie node is an internal entry, leave as is
103 if !it.stateIt.Leaf() {
104 return nil
105 }
106 // Otherwise we've reached an account node, initiate data iteration
107 var account Account
108 if err := rlp.Decode(bytes.NewReader(it.stateIt.LeafBlob()), &account); err != nil {
109 return err
110 }
111 dataTrie, err := it.state.db.OpenStorageTrie(common.BytesToHash(it.stateIt.LeafKey()), account.Root)
112 if err != nil {
113 return err
114 }
115 it.dataIt = dataTrie.NodeIterator(nil)
116 if !it.dataIt.Next(true) {
117 it.dataIt = nil
118 }
119 if !bytes.Equal(account.CodeHash, emptyCodeHash) {
120 it.codeHash = common.BytesToHash(account.CodeHash)
121 addrHash := common.BytesToHash(it.stateIt.LeafKey())
122 it.code, err = it.state.db.ContractCode(addrHash, common.BytesToHash(account.CodeHash))
123 if err != nil {
124 return fmt.Errorf("code %x: %v", account.CodeHash, err)
125 }
126 }
127 it.accountHash = it.stateIt.Parent()

Callers 1

NextMethod · 0.95

Calls 6

NodeIteratorMethod · 0.80
ErrorMethod · 0.65
OpenStorageTrieMethod · 0.65
EqualMethod · 0.65
ContractCodeMethod · 0.65
NextMethod · 0.45

Tested by

no test coverage detected