@@ -198,22 +198,46 @@ func (s *hookedStateDB) SetState(address common.Address, key common.Hash, value
198
198
}
199
199
200
200
func (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
+
201
209
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 )
206
217
}
218
+
207
219
return prev
208
220
}
209
221
210
222
func (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
+
211
231
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 )
216
239
}
240
+
217
241
return prev , changed
218
242
}
219
243
0 commit comments