From 665bb43a4c9e97d6f23de02575b92156881a2db8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felf=C3=B6ldi=20Zsolt?= Date: Mon, 28 Nov 2016 11:31:15 +0100 Subject: [PATCH] light: implemented VMState.Empty() (#3357) --- light/state_object.go | 9 +++++++-- light/vm_env.go | 7 +++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/light/state_object.go b/light/state_object.go index 61c3888fe..6161d2dfb 100644 --- a/light/state_object.go +++ b/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 diff --git a/light/vm_env.go b/light/vm_env.go index 5d330b072..d4d7bcce7 100644 --- a/light/vm_env.go +++ b/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 {