Skip to content

Commit 665bb43

Browse files
zsfelfoldifjl
authored andcommitted
light: implemented VMState.Empty() (#3357)
1 parent e4bf004 commit 665bb43

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

light/state_object.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,19 @@ func (self *StateObject) Copy() *StateObject {
201201
// Attribute accessors
202202
//
203203

204+
// empty returns whether the account is considered empty.
205+
func (self *StateObject) empty() bool {
206+
return self.nonce == 0 && self.balance.BitLen() == 0 && bytes.Equal(self.codeHash, emptyCodeHash)
207+
}
208+
204209
// Balance returns the account balance
205210
func (self *StateObject) Balance() *big.Int {
206211
return self.balance
207212
}
208213

209214
// Address returns the address of the contract/account
210-
func (c *StateObject) Address() common.Address {
211-
return c.address
215+
func (self *StateObject) Address() common.Address {
216+
return self.address
212217
}
213218

214219
// Code returns the contract code

light/vm_env.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ func (s *VMState) Exist(addr common.Address) bool {
263263
return res
264264
}
265265

266+
// Empty returns true if the account at the given address is considered empty
267+
func (s *VMState) Empty(addr common.Address) bool {
268+
so, err := s.state.GetStateObject(s.ctx, addr)
269+
s.errHandler(err)
270+
return so == nil || so.empty()
271+
}
272+
266273
// HasSuicided returns true if the given account has been marked for deletion
267274
// or false if the account does not exist
268275
func (s *VMState) HasSuicided(addr common.Address) bool {

0 commit comments

Comments
 (0)