From d04fe6b02e0a5722c968bfa7ebdcecf0c7e03df0 Mon Sep 17 00:00:00 2001 From: ucwong Date: Wed, 5 Jun 2024 19:17:10 +0800 Subject: [PATCH] add trie UpdateStorage --- trie/secure_trie.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/trie/secure_trie.go b/trie/secure_trie.go index 3a31ae5811..aca01cc2d4 100644 --- a/trie/secure_trie.go +++ b/trie/secure_trie.go @@ -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 {