@@ -28,56 +28,58 @@ import (
28
28
29
29
type stateDBLogger struct {
30
30
* StateDB
31
- logger * tracing.Hooks
31
+ hooks * tracing.Hooks
32
32
}
33
33
34
- func newStateDBLogger (db * StateDB , logger * tracing.Hooks ) * stateDBLogger {
35
- s := & stateDBLogger {db , logger }
36
-
34
+ func newStateDBLogger (db * StateDB , hooks * tracing.Hooks ) * stateDBLogger {
35
+ s := & stateDBLogger {db , hooks }
36
+ if s .hooks == nil {
37
+ s .hooks = new (tracing.Hooks )
38
+ }
37
39
db .SetBurnCallback (func (address common.Address , amount * uint256.Int ) {
38
- if s .logger != nil && s . logger .OnBalanceChange != nil {
39
- s .logger .OnBalanceChange (address , amount .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestructBurn )
40
+ if s .hooks .OnBalanceChange != nil {
41
+ s .hooks .OnBalanceChange (address , amount .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestructBurn )
40
42
}
41
43
})
42
44
return s
43
45
}
44
46
45
47
func (s * stateDBLogger ) AddBalance (address common.Address , amount * uint256.Int , reason tracing.BalanceChangeReason ) uint256.Int {
46
48
prev := s .StateDB .AddBalance (address , amount , reason )
47
- if s .logger != nil && s . logger .OnBalanceChange != nil {
49
+ if s .hooks .OnBalanceChange != nil {
48
50
newBalance := new (uint256.Int ).Add (& prev , amount )
49
- s .logger .OnBalanceChange (address , prev .ToBig (), newBalance .ToBig (), reason )
51
+ s .hooks .OnBalanceChange (address , prev .ToBig (), newBalance .ToBig (), reason )
50
52
}
51
53
return prev
52
54
}
53
55
54
56
func (s * stateDBLogger ) SetNonce (address common.Address , nonce uint64 ) {
55
57
s .StateDB .SetNonce (address , nonce )
56
- if s .logger != nil && s . logger .OnNonceChange != nil {
57
- s .logger .OnNonceChange (address , nonce - 1 , nonce )
58
+ if s .hooks .OnNonceChange != nil {
59
+ s .hooks .OnNonceChange (address , nonce - 1 , nonce )
58
60
}
59
61
}
60
62
61
63
func (s * stateDBLogger ) SetCode (address common.Address , code []byte ) {
62
64
s .StateDB .SetCode (address , code )
63
- if s .logger != nil && s . logger .OnCodeChange != nil {
64
- s .logger .OnCodeChange (address , types .EmptyCodeHash , nil , crypto .Keccak256Hash (code ), code )
65
+ if s .hooks .OnCodeChange != nil {
66
+ s .hooks .OnCodeChange (address , types .EmptyCodeHash , nil , crypto .Keccak256Hash (code ), code )
65
67
}
66
68
}
67
69
68
70
func (s * stateDBLogger ) SetState (address common.Address , key common.Hash , value common.Hash ) common.Hash {
69
71
prev := s .StateDB .SetState (address , key , value )
70
- if s .logger != nil && s . logger .OnStorageChange != nil && prev != value {
71
- s .logger .OnStorageChange (address , key , prev , value )
72
+ if s .hooks .OnStorageChange != nil && prev != value {
73
+ s .hooks .OnStorageChange (address , key , prev , value )
72
74
}
73
75
return prev
74
76
}
75
77
76
78
func (s * stateDBLogger ) SelfDestruct (address common.Address ) uint256.Int {
77
79
prev := s .StateDB .SelfDestruct (address )
78
80
if ! prev .IsZero () {
79
- if s .logger != nil && s . logger .OnBalanceChange != nil {
80
- s .logger .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
81
+ if s .hooks .OnBalanceChange != nil {
82
+ s .hooks .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
81
83
}
82
84
}
83
85
return prev
@@ -86,8 +88,8 @@ func (s *stateDBLogger) SelfDestruct(address common.Address) uint256.Int {
86
88
func (s * stateDBLogger ) Selfdestruct6780 (address common.Address ) uint256.Int {
87
89
prev := s .StateDB .Selfdestruct6780 (address )
88
90
if ! prev .IsZero () {
89
- if s .logger != nil && s . logger .OnBalanceChange != nil {
90
- s .logger .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
91
+ if s .hooks .OnBalanceChange != nil {
92
+ s .hooks .OnBalanceChange (address , prev .ToBig (), new (big.Int ), tracing .BalanceDecreaseSelfdestruct )
91
93
}
92
94
}
93
95
return prev
@@ -96,7 +98,7 @@ func (s *stateDBLogger) Selfdestruct6780(address common.Address) uint256.Int {
96
98
func (s * stateDBLogger ) AddLog (log * types.Log ) {
97
99
// The inner will modify the log (add fields), so invoke that first
98
100
s .StateDB .AddLog (log )
99
- if s .logger != nil && s . logger .OnLog != nil {
100
- s .logger .OnLog (log )
101
+ if s .hooks .OnLog != nil {
102
+ s .hooks .OnLog (log )
101
103
}
102
104
}
0 commit comments