forked from ethereum-optimism/optimism
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
l2geth/rpc: support solidity custom errors (#97)
* l2geth/rpc: support solidity custom errors * Add execution reverted error
- Loading branch information
Showing
6 changed files
with
135 additions
and
23 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package ethapi | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/ethereum-optimism/optimism/l2geth/accounts/abi" | ||
"github.com/ethereum-optimism/optimism/l2geth/common/hexutil" | ||
) | ||
|
||
// revertError is an API error that encompasses an EVM revert with JSON error | ||
// code and a binary data blob. | ||
type revertError struct { | ||
error | ||
reason string // revert reason hex encoded | ||
} | ||
|
||
// ErrorCode returns the JSON error code for a revert. | ||
// See: https://github.com/ethereum/wiki/wiki/JSON-RPC-Error-Codes-Improvement-Proposal | ||
func (e *revertError) ErrorCode() int { | ||
return 3 | ||
} | ||
|
||
// ErrorData returns the hex encoded revert reason. | ||
func (e *revertError) ErrorData() interface{} { | ||
return e.reason | ||
} | ||
|
||
// newRevertError creates a revertError instance with the provided revert data. | ||
func newRevertError(revert []byte) *revertError { | ||
err := errors.New("execution reverted") | ||
|
||
reason, errUnpack := abi.UnpackRevert(revert) | ||
if errUnpack == nil { | ||
err = fmt.Errorf("execution reverted: %s", reason) | ||
} | ||
return &revertError{ | ||
error: err, | ||
reason: hexutil.Encode(revert), | ||
} | ||
} |
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