diff options
author | Jeffrey Wilcke <jeffrey@ethereum.org> | 2017-02-23 06:29:59 +0800 |
---|---|---|
committer | Felix Lange <fjl@users.noreply.github.com> | 2017-02-23 06:29:59 +0800 |
commit | 024d41d0c2660d8f1dfbeb14921c7109e30493a2 (patch) | |
tree | a2b4ed630b84084c7f439d1539ed0551ec729cbd /light | |
parent | 46ec4357e73dd0c43951d11638d9aed94f8ffd29 (diff) | |
download | dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.tar dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.tar.gz dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.tar.bz2 dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.tar.lz dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.tar.xz dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.tar.zst dexon-024d41d0c2660d8f1dfbeb14921c7109e30493a2.zip |
core, core/state, core/vm: remove exported account getters (#3618)
Removed exported statedb object accessors, reducing the chance for nasty
bugs to creep in. It's also ugly and unnecessary to have these methods.
Diffstat (limited to 'light')
-rw-r--r-- | light/state.go | 20 | ||||
-rw-r--r-- | light/vm_env.go | 31 |
2 files changed, 31 insertions, 20 deletions
diff --git a/light/state.go b/light/state.go index b6cefc9b9..f19748e89 100644 --- a/light/state.go +++ b/light/state.go @@ -268,6 +268,26 @@ func (self *LightState) CreateStateObject(ctx context.Context, addr common.Addre return newSo, nil } +// ForEachStorage calls a callback function for every key/value pair found +// in the local storage cache. Note that unlike core/state.StateObject, +// light.StateObject only returns cached values and doesn't download the +// entire storage tree. +func (self *LightState) ForEachStorage(ctx context.Context, addr common.Address, cb func(key, value common.Hash) bool) error { + so, err := self.GetStateObject(ctx, addr) + if err != nil { + return err + } + + if so == nil { + return nil + } + + for h, v := range so.storage { + cb(h, v) + } + return nil +} + // // Setting, copying of the state methods // diff --git a/light/vm_env.go b/light/vm_env.go index d2cc7e960..ebd229de8 100644 --- a/light/vm_env.go +++ b/light/vm_env.go @@ -21,7 +21,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "golang.org/x/net/context" ) @@ -64,27 +63,10 @@ func (self *VMState) RevertToSnapshot(idx int) { self.snapshots = self.snapshots[:idx] } -// GetAccount returns the account object of the given account or nil if the -// account does not exist -func (s *VMState) GetAccount(addr common.Address) vm.Account { - so, err := s.state.GetStateObject(s.ctx, addr) - s.errHandler(err) - if err != nil { - // return a dummy state object to avoid panics - so = s.state.newStateObject(addr) - } - return so -} - // CreateAccount creates creates a new account object and takes ownership. -func (s *VMState) CreateAccount(addr common.Address) vm.Account { - so, err := s.state.CreateStateObject(s.ctx, addr) +func (s *VMState) CreateAccount(addr common.Address) { + _, err := s.state.CreateStateObject(s.ctx, addr) s.errHandler(err) - if err != nil { - // return a dummy state object to avoid panics - so = s.state.newStateObject(addr) - } - return so } // AddBalance adds the given amount to the balance of the specified account @@ -99,6 +81,15 @@ func (s *VMState) SubBalance(addr common.Address, amount *big.Int) { s.errHandler(err) } +// ForEachStorage calls a callback function for every key/value pair found +// in the local storage cache. Note that unlike core/state.StateObject, +// light.StateObject only returns cached values and doesn't download the +// entire storage tree. +func (s *VMState) ForEachStorage(addr common.Address, cb func(key, value common.Hash) bool) { + err := s.state.ForEachStorage(s.ctx, addr, cb) + s.errHandler(err) +} + // GetBalance retrieves the balance from the given address or 0 if the account does // not exist func (s *VMState) GetBalance(addr common.Address) *big.Int { |