Skip to content

Commit 8f2817f

Browse files
author
Aryan Tikarya
committed
refactor: eth call error to execution reverted error
1 parent 6c85b64 commit 8f2817f

File tree

7 files changed

+158
-150
lines changed

7 files changed

+158
-150
lines changed

chain/types/ethtypes/errors.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package ethtypes
2+
3+
import (
4+
"fmt"
5+
6+
"golang.org/x/xerrors"
7+
)
8+
9+
var ErrExecutionReverted = xerrors.New("execution reverted")
10+
11+
// ExecutionRevertedError is an error that occurs when a transaction reverts.
12+
type ExecutionRevertedError struct {
13+
Message string
14+
Code int
15+
Meta []byte
16+
Data string
17+
}
18+
19+
// Error implements the error interface.
20+
func (e *ExecutionRevertedError) Error() string {
21+
if e.Message == "" {
22+
return fmt.Sprintf("json-rpc error %d", e.Code)
23+
}
24+
return e.Message
25+
}
26+
27+
// ErrorData returns the error data.
28+
func (e *ExecutionRevertedError) ErrorData() interface{} {
29+
return e.Data
30+
}
31+
32+
// ErrorCode returns the JSON error code for a revert.
33+
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal
34+
func (e *ExecutionRevertedError) ErrorCode() int {
35+
return 3
36+
}
37+
38+
// NewExecutionRevertedWithDataError returns an ExecutionRevertedError with the given code and data.
39+
func NewExecutionRevertedWithDataError(code int, data string) *ExecutionRevertedError {
40+
return &ExecutionRevertedError{
41+
Message: ErrExecutionReverted.Error(),
42+
Code: code,
43+
Data: data,
44+
}
45+
}

chain/types/ethtypes/eth_types.go

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,37 +1165,3 @@ type EthCreateTraceResult struct {
11651165
GasUsed EthUint64 `json:"gasUsed"`
11661166
Code EthBytes `json:"code"`
11671167
}
1168-
1169-
type EthCallError struct {
1170-
Message string
1171-
Code int
1172-
Meta []byte
1173-
Data string
1174-
}
1175-
1176-
func (e *EthCallError) Error() string {
1177-
if e.Message == "" {
1178-
return fmt.Sprintf("json-rpc error %d", e.Code)
1179-
}
1180-
return e.Message
1181-
}
1182-
1183-
func (e *EthCallError) ErrorData() interface{} {
1184-
return e.Data
1185-
}
1186-
1187-
func EthCallErrorWithDefaultCode(msg string, data string) *EthCallError {
1188-
return &EthCallError{
1189-
Message: msg,
1190-
Code: -32000,
1191-
Data: data,
1192-
}
1193-
}
1194-
1195-
func EthCallErrorWithCode(msg string, code int, data string) *EthCallError {
1196-
return &EthCallError{
1197-
Message: msg,
1198-
Code: code,
1199-
Data: data,
1200-
}
1201-
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ replace github.com/filecoin-project/test-vectors => ./extern/test-vectors // pro
1212

1313
replace github.com/filecoin-project/filecoin-ffi => ./extern/filecoin-ffi // provided via a git submodule
1414

15+
replace github.com/filecoin-project/go-jsonrpc => github.com/virajbhartiya/go-jsonrpc v0.0.0-20241011111701-53eab64ec154
16+
1517
require (
1618
contrib.go.opencensus.io/exporter/prometheus v0.4.2
1719
github.com/BurntSushi/toml v1.3.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,6 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1/go.mod h1:gXpNmr3oQx8l3o7qkGy
287287
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBwFmYdT8SOFUwB3ovSUfG1Ux0g=
288288
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0 h1:nYs6OPUF8KbZ3E8o9p9HJnQaE8iugjHR5WYVMcicDJc=
289289
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0/go.mod h1:s0qiHRhFyrgW0SvdQMSJFQxNa4xEIG5XvqCBZUEgcbc=
290-
github.com/filecoin-project/go-jsonrpc v0.6.0 h1:/fFJIAN/k6EgY90m7qbyfY28woMwyseZmh2gVs5sYjY=
291-
github.com/filecoin-project/go-jsonrpc v0.6.0/go.mod h1:/n/niXcS4ZQua6i37LcVbY1TmlJR0UIK9mDFQq2ICek=
292290
github.com/filecoin-project/go-padreader v0.0.1 h1:8h2tVy5HpoNbr2gBRr+WD6zV6VD6XHig+ynSGJg8ZOs=
293291
github.com/filecoin-project/go-padreader v0.0.1/go.mod h1:VYVPJqwpsfmtoHnAmPx6MUwmrK6HIcDqZJiuZhtmfLQ=
294292
github.com/filecoin-project/go-paramfetch v0.0.4 h1:H+Me8EL8T5+79z/KHYQQcT8NVOzYVqXIi7nhb48tdm8=
@@ -1281,6 +1279,8 @@ github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8W
12811279
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
12821280
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
12831281
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
1282+
github.com/virajbhartiya/go-jsonrpc v0.0.0-20241011111701-53eab64ec154 h1:k3+bv8KyRZZXFjNtT5CK2Y8KqIK19ISShIPMqO6uEQI=
1283+
github.com/virajbhartiya/go-jsonrpc v0.0.0-20241011111701-53eab64ec154/go.mod h1:lAUpS8BSVtKaA8+/CFUMA5dokMiSM7n0ehf8bHOFdpE=
12841284
github.com/warpfork/go-testmark v0.12.1 h1:rMgCpJfwy1sJ50x0M0NgyphxYYPMOODIJHhsXyEHU0s=
12851285
github.com/warpfork/go-testmark v0.12.1/go.mod h1:kHwy7wfvGSPh1rQJYKayD4AbtNaeyZdcGi9tNJTaa5Y=
12861286
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=

0 commit comments

Comments
 (0)