From bbe08ac6e6da32408e15d738cd34b43ca8e9a505 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Wed, 6 Mar 2024 14:10:08 +0800 Subject: [PATCH] core/state: add function GetStorageRoot --- core/state/state_object.go | 4 ++++ core/state/statedb.go | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/core/state/state_object.go b/core/state/state_object.go index 6d50461f15..a5c7ce0bc9 100644 --- a/core/state/state_object.go +++ b/core/state/state_object.go @@ -393,6 +393,10 @@ func (self *stateObject) Nonce() uint64 { return self.data.Nonce } +func (self *stateObject) Root() common.Hash { + return self.data.Root +} + // Never called, but must be present to allow stateObject to be used // as a vm.Account interface that also satisfies the vm.ContractRef // interface. Interfaces are awesome. diff --git a/core/state/statedb.go b/core/state/statedb.go index 07bcf7596b..8b374fda65 100644 --- a/core/state/statedb.go +++ b/core/state/statedb.go @@ -221,6 +221,16 @@ func (self *StateDB) GetNonce(addr common.Address) uint64 { return 0 } +// GetStorageRoot retrieves the storage root from the given address or empty +// if object not found. +func (self *StateDB) GetStorageRoot(addr common.Address) common.Hash { + stateObject := self.getStateObject(addr) + if stateObject != nil { + return stateObject.Root() + } + return common.Hash{} +} + func (self *StateDB) GetCode(addr common.Address) []byte { stateObject := self.getStateObject(addr) if stateObject != nil {