Browse Source

light: implemented VMState.Empty() (#3357)

Felföldi Zsolt 9 years ago
parent
commit
665bb43a4c
2 changed files with 14 additions and 2 deletions
  1. 7 2
      light/state_object.go
  2. 7 0
      light/vm_env.go

+ 7 - 2
light/state_object.go

@@ -201,14 +201,19 @@ func (self *StateObject) Copy() *StateObject {
 // Attribute accessors
 //
 
+// empty returns whether the account is considered empty.
+func (self *StateObject) empty() bool {
+	return self.nonce == 0 && self.balance.BitLen() == 0 && bytes.Equal(self.codeHash, emptyCodeHash)
+}
+
 // Balance returns the account balance
 func (self *StateObject) Balance() *big.Int {
 	return self.balance
 }
 
 // Address returns the address of the contract/account
-func (c *StateObject) Address() common.Address {
-	return c.address
+func (self *StateObject) Address() common.Address {
+	return self.address
 }
 
 // Code returns the contract code

+ 7 - 0
light/vm_env.go

@@ -263,6 +263,13 @@ func (s *VMState) Exist(addr common.Address) bool {
 	return res
 }
 
+// Empty returns true if the account at the given address is considered empty
+func (s *VMState) Empty(addr common.Address) bool {
+	so, err := s.state.GetStateObject(s.ctx, addr)
+	s.errHandler(err)
+	return so == nil || so.empty()
+}
+
 // HasSuicided returns true if the given account has been marked for deletion
 // or false if the account does not exist
 func (s *VMState) HasSuicided(addr common.Address) bool {