Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions api/api_errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,22 +170,28 @@ func (e *ErrExecutionReverted) ToJSONRPCError() (jsonrpc.JSONRPCError, error) {

// NewErrExecutionReverted creates a new ErrExecutionReverted with the given reason.
func NewErrExecutionReverted(exitCode exitcode.ExitCode, error, reason string, data []byte) *ErrExecutionReverted {
revertReason := ""
if reason != "" {
revertReason = fmt.Sprintf(", revert reason=[%s]", reason)
}
return &ErrExecutionReverted{
Message: fmt.Sprintf("message execution failed (exit=[%s], revert reason=[%s], vm error=[%s])", exitCode, reason, error),
Message: fmt.Sprintf("message execution failed (exit=[%s]%s, vm error=[%s])", exitCode, revertReason, error),
Data: fmt.Sprintf("0x%x", data),
}
}

// NewErrExecutionRevertedFromResult creates an ErrExecutionReverted from an InvocResult.
// It decodes the CBOR-encoded return data and parses any Ethereum revert reason.
func NewErrExecutionRevertedFromResult(res *InvocResult) error {
reason := "none"
reason := ""
var cbytes abi.CborBytes
if err := cbytes.UnmarshalCBOR(bytes.NewReader(res.MsgRct.Return)); err != nil {
reason = "ERROR: revert reason is not cbor encoded bytes"
} else if len(cbytes) > 0 {
reason = ethtypes.ParseEthRevert(cbytes)
}
if err := cbytes.UnmarshalCBOR(bytes.NewReader(res.MsgRct.Return)); err == nil {
if len(cbytes) > 0 {
reason = ethtypes.ParseEthRevert(cbytes)
} else {
reason = "none"
}
} // else likely a non-ethereum error
Comment thread
rvagg marked this conversation as resolved.
return NewErrExecutionReverted(res.MsgRct.ExitCode, res.Error, reason, cbytes)
}

Expand Down
Loading