From 6994785b39cfbcd023fae6a4e12a622f909a3f5c Mon Sep 17 00:00:00 2001 From: Stephen Buttolph Date: Fri, 19 Aug 2022 02:51:50 -0400 Subject: [PATCH] Expose eth_call error code (#965) --- internal/ethapi/api.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index db561d5103..3a976caf24 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -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) } @@ -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 }