Skip to content
Snippets Groups Projects
Unverified Commit 4a4528b7 authored by Silas Davis's avatar Silas Davis
Browse files

Ensure storing zero value removes the key rather than panics


Signed-off-by: default avatarSilas Davis <silas@monax.io>
parent cb73b3b2
No related branches found
No related tags found
No related merge requests found
......@@ -33,7 +33,7 @@ type StorageGetter interface {
}
type StorageSetter interface {
// Store a 32-byte value at key for the account at address
// Store a 32-byte value at key for the account at address, setting to Zero256 removes the key
SetStorage(address acm.Address, key, value binary.Word256) error
}
......
......@@ -235,7 +235,11 @@ func (s *State) GetStorage(address acm.Address, key binary.Word256) (binary.Word
func (s *State) SetStorage(address acm.Address, key, value binary.Word256) error {
s.Lock()
defer s.Unlock()
s.tree.Set(prefixedKey(storagePrefix, address.Bytes(), key.Bytes()), value.Bytes())
if value == binary.Zero256 {
s.tree.Remove(key.Bytes())
} else {
s.tree.Set(prefixedKey(storagePrefix, address.Bytes(), key.Bytes()), value.Bytes())
}
return nil
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment