Skip to content

Commit

Permalink
Expose eth_call error code (#965)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Aug 19, 2022
1 parent cc9ae69 commit 6994785
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,7 @@ func (e *revertError) ErrorData() interface{} {

type ExecutionResult struct {
UsedGas uint64 `json:"gas"` // Total used gas but include the refunded gas
ErrCode int `json:"errCode"` // EVM error code
Err string `json:"err"` // Any error encountered during the execution(listed in core/vm/errors.go)
ReturnData hexutil.Bytes `json:"returnData"` // Data from evm(function result or data supplied with revert opcode)
}
Expand All @@ -1042,11 +1043,16 @@ func (s *BlockChainAPI) CallDetailed(ctx context.Context, args TransactionArgs,
ReturnData: result.ReturnData,
}
if result.Err != nil {
if err, ok := result.Err.(rpc.Error); ok {
reply.ErrCode = err.ErrorCode()
}
reply.Err = result.Err.Error()
}
// If the result contains a revert reason, try to unpack and return it.
if len(result.Revert()) > 0 {
reply.Err = newRevertError(result).Error()
err := newRevertError(result)
reply.ErrCode = err.ErrorCode()
reply.Err = err.Error()
}
return reply, nil
}
Expand Down

0 comments on commit 6994785

Please sign in to comment.