-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: eth call error to execution reverted error
- Loading branch information
1 parent
6c85b64
commit 103b242
Showing
7 changed files
with
157 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.