@@ -23,6 +23,7 @@ import (
23
23
"sync/atomic"
24
24
"time"
25
25
26
+ "github.com/ethereum/go-ethereum/accounts/abi"
26
27
"github.com/ethereum/go-ethereum/common"
27
28
"github.com/ethereum/go-ethereum/common/hexutil"
28
29
"github.com/ethereum/go-ethereum/core/vm"
@@ -36,15 +37,16 @@ func init() {
36
37
}
37
38
38
39
type callFrame struct {
39
- Type vm.OpCode `json:"-"`
40
- From common.Address `json:"from"`
41
- Gas uint64 `json:"gas"`
42
- GasUsed uint64 `json:"gasUsed"`
43
- To common.Address `json:"to,omitempty" rlp:"optional"`
44
- Input []byte `json:"input" rlp:"optional"`
45
- Output []byte `json:"output,omitempty" rlp:"optional"`
46
- Error string `json:"error,omitempty" rlp:"optional"`
47
- Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
40
+ Type vm.OpCode `json:"-"`
41
+ From common.Address `json:"from"`
42
+ Gas uint64 `json:"gas"`
43
+ GasUsed uint64 `json:"gasUsed"`
44
+ To common.Address `json:"to,omitempty" rlp:"optional"`
45
+ Input []byte `json:"input" rlp:"optional"`
46
+ Output []byte `json:"output,omitempty" rlp:"optional"`
47
+ Error string `json:"error,omitempty" rlp:"optional"`
48
+ Revertal string `json:"revertReason,omitempty"`
49
+ Calls []callFrame `json:"calls,omitempty" rlp:"optional"`
48
50
// Placed at end on purpose. The RLP will be decoded to 0 instead of
49
51
// nil if there are non-empty elements after in the struct.
50
52
Value * big.Int `json:"value,omitempty" rlp:"optional"`
@@ -109,13 +111,20 @@ func (t *callTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Ad
109
111
func (t * callTracer ) CaptureEnd (output []byte , gasUsed uint64 , _ time.Duration , err error ) {
110
112
t .callstack [0 ].GasUsed = gasUsed
111
113
output = common .CopyBytes (output )
112
- if err != nil {
113
- t .callstack [0 ].Error = err .Error ()
114
- if err .Error () == "execution reverted" && len (output ) > 0 {
115
- t .callstack [0 ].Output = output
116
- }
117
- } else {
114
+ if err == nil {
118
115
t .callstack [0 ].Output = output
116
+ return
117
+ }
118
+ t .callstack [0 ].Error = err .Error ()
119
+ if ! errors .Is (err , vm .ErrExecutionReverted ) || len (output ) == 0 {
120
+ return
121
+ }
122
+ t .callstack [0 ].Output = output
123
+ if len (output ) < 4 {
124
+ return
125
+ }
126
+ if unpacked , err := abi .UnpackRevert (output ); err == nil {
127
+ t .callstack [0 ].Revertal = unpacked
119
128
}
120
129
}
121
130
0 commit comments