GetState returns a value in account storage.
(db Database, key common.Hash)
| 161 | |
| 162 | // GetState returns a value in account storage. |
| 163 | func (self *stateObject) GetState(db Database, key common.Hash) common.Hash { |
| 164 | value, exists := self.cachedStorage[key] |
| 165 | if exists { |
| 166 | return value |
| 167 | } |
| 168 | // Load from DB in case it is missing. |
| 169 | enc, err := self.getTrie(db).TryGet(key[:]) |
| 170 | if err != nil { |
| 171 | self.setError(err) |
| 172 | return common.Hash{} |
| 173 | } |
| 174 | if len(enc) > 0 { |
| 175 | _, content, _, err := rlp.Split(enc) |
| 176 | if err != nil { |
| 177 | self.setError(err) |
| 178 | } |
| 179 | value.SetBytes(content) |
| 180 | } |
| 181 | self.cachedStorage[key] = value |
| 182 | return value |
| 183 | } |
| 184 | |
| 185 | // SetState updates a value in account storage. |
| 186 | func (self *stateObject) SetState(db Database, key, value common.Hash) { |