Skip to content

Commit 328c212

Browse files
committed
eth/tracers: add revertReason to callTracer
1 parent 13e6985 commit 328c212

File tree

2 files changed

+24
-123
lines changed

2 files changed

+24
-123
lines changed

eth/tracers/native/call.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"sync/atomic"
2424
"time"
2525

26+
"github.com/ethereum/go-ethereum/accounts/abi"
2627
"github.com/ethereum/go-ethereum/common"
2728
"github.com/ethereum/go-ethereum/common/hexutil"
2829
"github.com/ethereum/go-ethereum/core/vm"
@@ -36,15 +37,16 @@ func init() {
3637
}
3738

3839
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"`
4850
// Placed at end on purpose. The RLP will be decoded to 0 instead of
4951
// nil if there are non-empty elements after in the struct.
5052
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
109111
func (t *callTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
110112
t.callstack[0].GasUsed = gasUsed
111113
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 {
118115
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
119128
}
120129
}
121130

eth/tracers/native/revertreason.go

Lines changed: 0 additions & 108 deletions
This file was deleted.

0 commit comments

Comments
 (0)