Skip to content

Commit

Permalink
refactor: eth call error to execution reverted error
Browse files Browse the repository at this point in the history
  • Loading branch information
akaladarshi committed Oct 11, 2024
1 parent 6c85b64 commit 103b242
Show file tree
Hide file tree
Showing 7 changed files with 157 additions and 150 deletions.
44 changes: 44 additions & 0 deletions chain/types/ethtypes/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package ethtypes

import (
"fmt"

"golang.org/x/xerrors"
)

var ErrExecutionReverted = xerrors.New("execution reverted")

// ExecutionRevertedError is an error that occurs when a transaction reverts.
type ExecutionRevertedError struct {
Message string
Code int
Meta []byte
Data string
}

// Error implements the error interface.
func (e *ExecutionRevertedError) Error() string {
if e.Message == "" {
return fmt.Sprintf("json-rpc error %d", e.Code)
}
return e.Message
}

// ErrorData returns the error data.
func (e *ExecutionRevertedError) ErrorData() interface{} {
return e.Data
}

// ErrorCode returns the JSON error code for a revert.
func (e *ExecutionRevertedError) ErrorCode() int {
return 3
}

// NewExecutionRevertedWithDataError returns an ExecutionRevertedError with the given code and data.
func NewExecutionRevertedWithDataError(code int, data string) *ExecutionRevertedError {
return &ExecutionRevertedError{
Message: ErrExecutionReverted.Error(),
Code: code,
Data: data,
}
}
34 changes: 0 additions & 34 deletions chain/types/ethtypes/eth_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1165,37 +1165,3 @@ type EthCreateTraceResult struct {
GasUsed EthUint64 `json:"gasUsed"`
Code EthBytes `json:"code"`
}

type EthCallError struct {
Message string
Code int
Meta []byte
Data string
}

func (e *EthCallError) Error() string {
if e.Message == "" {
return fmt.Sprintf("json-rpc error %d", e.Code)
}
return e.Message
}

func (e *EthCallError) ErrorData() interface{} {
return e.Data
}

func EthCallErrorWithDefaultCode(msg string, data string) *EthCallError {
return &EthCallError{
Message: msg,
Code: -32000,
Data: data,
}
}

func EthCallErrorWithCode(msg string, code int, data string) *EthCallError {
return &EthCallError{
Message: msg,
Code: code,
Data: data,
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ replace github.com/filecoin-project/test-vectors => ./extern/test-vectors // pro

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

replace github.com/filecoin-project/go-jsonrpc => github.com/virajbhartiya/go-jsonrpc v0.0.0-20241011111701-53eab64ec154

require (
contrib.go.opencensus.io/exporter/prometheus v0.4.2
github.com/BurntSushi/toml v1.3.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -287,8 +287,6 @@ github.com/filecoin-project/go-hamt-ipld/v3 v3.0.1/go.mod h1:gXpNmr3oQx8l3o7qkGy
github.com/filecoin-project/go-hamt-ipld/v3 v3.1.0/go.mod h1:bxmzgT8tmeVQA1/gvBwFmYdT8SOFUwB3ovSUfG1Ux0g=
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0 h1:nYs6OPUF8KbZ3E8o9p9HJnQaE8iugjHR5WYVMcicDJc=
github.com/filecoin-project/go-hamt-ipld/v3 v3.4.0/go.mod h1:s0qiHRhFyrgW0SvdQMSJFQxNa4xEIG5XvqCBZUEgcbc=
github.com/filecoin-project/go-jsonrpc v0.6.0 h1:/fFJIAN/k6EgY90m7qbyfY28woMwyseZmh2gVs5sYjY=
github.com/filecoin-project/go-jsonrpc v0.6.0/go.mod h1:/n/niXcS4ZQua6i37LcVbY1TmlJR0UIK9mDFQq2ICek=
github.com/filecoin-project/go-padreader v0.0.1 h1:8h2tVy5HpoNbr2gBRr+WD6zV6VD6XHig+ynSGJg8ZOs=
github.com/filecoin-project/go-padreader v0.0.1/go.mod h1:VYVPJqwpsfmtoHnAmPx6MUwmrK6HIcDqZJiuZhtmfLQ=
github.com/filecoin-project/go-paramfetch v0.0.4 h1:H+Me8EL8T5+79z/KHYQQcT8NVOzYVqXIi7nhb48tdm8=
Expand Down Expand Up @@ -1281,6 +1279,8 @@ github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8W
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
github.com/viant/assertly v0.4.8/go.mod h1:aGifi++jvCrUaklKEKT0BU95igDNaqkvz+49uaYMPRU=
github.com/viant/toolbox v0.24.0/go.mod h1:OxMCG57V0PXuIP2HNQrtJf2CjqdmbrOx5EkMILuUhzM=
github.com/virajbhartiya/go-jsonrpc v0.0.0-20241011111701-53eab64ec154 h1:k3+bv8KyRZZXFjNtT5CK2Y8KqIK19ISShIPMqO6uEQI=
github.com/virajbhartiya/go-jsonrpc v0.0.0-20241011111701-53eab64ec154/go.mod h1:lAUpS8BSVtKaA8+/CFUMA5dokMiSM7n0ehf8bHOFdpE=
github.com/warpfork/go-testmark v0.12.1 h1:rMgCpJfwy1sJ50x0M0NgyphxYYPMOODIJHhsXyEHU0s=
github.com/warpfork/go-testmark v0.12.1/go.mod h1:kHwy7wfvGSPh1rQJYKayD4AbtNaeyZdcGi9tNJTaa5Y=
github.com/warpfork/go-wish v0.0.0-20180510122957-5ad1f5abf436/go.mod h1:x6AKhvSSexNrVSrViXSHUEbICjmGXhtgABaHIySUSGw=
Expand Down
Loading

0 comments on commit 103b242

Please sign in to comment.