Skip to content

Commit

Permalink
add trie UpdateStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
ucwong committed Jun 5, 2024
1 parent f901cc5 commit d04fe6b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions trie/secure_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,25 @@ func (t *StateTrie) TryGetNode(path []byte) ([]byte, int, error) {
return t.trie.TryGetNode(path)
}

// UpdateStorage associates key with value in the trie. Subsequent calls to
// Get will return value. If value has length zero, any existing value
// is deleted from the trie and calls to Get will return nil.
//
// The value bytes must not be modified by the caller while they are
// stored in the trie.
//
// If a node is not found in the database, a MissingNodeError is returned.
func (t *StateTrie) UpdateStorage(_ common.Address, key, value []byte) error {
hk := t.hashKey(key)
v, _ := rlp.EncodeToBytes(value)
err := t.trie.TryUpdate(hk, v)
if err != nil {
return err
}
t.getSecKeyCache()[string(hk)] = common.CopyBytes(key)
return nil
}

// TryUpdateAccount account will abstract the write of an account to the
// secure trie.
func (t *StateTrie) TryUpdateAccount(key []byte, acc *types.StateAccount) error {
Expand Down

0 comments on commit d04fe6b

Please sign in to comment.