@@ -198,22 +198,46 @@ func (s *hookedStateDB) SetState(address common.Address, key common.Hash, value
198198}
199199
200200func (s * hookedStateDB ) SelfDestruct (address common.Address ) uint256.Int {
201+ var prevCode []byte
202+ var prevCodeHash common.Hash
203+
204+ if s .hooks .OnCodeChange != nil {
205+ prevCode = s .inner .GetCode (address )
206+ prevCodeHash = s .inner .GetCodeHash (address )
207+ }
208+
201209 prev := s .inner .SelfDestruct (address )
202- if ! prev .IsZero () {
203- if s .hooks .OnBalanceChange != nil {
204- s .hooks .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
205- }
210+
211+ if s .hooks .OnBalanceChange != nil && ! prev .IsZero () {
212+ s .hooks .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
213+ }
214+
215+ if s .hooks .OnCodeChange != nil && len (prevCode ) > 0 {
216+ s .hooks .OnCodeChange (address , prevCodeHash , prevCode , types .EmptyCodeHash , nil )
206217 }
218+
207219 return prev
208220}
209221
210222func (s * hookedStateDB ) SelfDestruct6780 (address common.Address ) (uint256.Int , bool ) {
223+ var prevCode []byte
224+ var prevCodeHash common.Hash
225+
226+ if s .hooks .OnCodeChange != nil {
227+ prevCodeHash = s .inner .GetCodeHash (address )
228+ prevCode = s .inner .GetCode (address )
229+ }
230+
211231 prev , changed := s .inner .SelfDestruct6780 (address )
212- if ! prev .IsZero () && changed {
213- if s .hooks .OnBalanceChange != nil {
214- s .hooks .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
215- }
232+
233+ if s .hooks .OnBalanceChange != nil && changed && ! prev .IsZero () {
234+ s .hooks .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
235+ }
236+
237+ if s .hooks .OnCodeChange != nil && changed && len (prevCode ) > 0 {
238+ s .hooks .OnCodeChange (address , prevCodeHash , prevCode , types .EmptyCodeHash , nil )
216239 }
240+
217241 return prev , changed
218242}
219243
0 commit comments