Skip to content

Commit

Permalink
[api] fix revert message in eth_call (#3922)
Browse files Browse the repository at this point in the history
  • Loading branch information
millken authored Aug 16, 2023
1 parent 26297f1 commit 55b5a58
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 6 additions & 1 deletion api/web3server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"github.com/tidwall/gjson"
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

"github.com/iotexproject/iotex-core/action"
rewardingabi "github.com/iotexproject/iotex-core/action/protocol/rewarding/ethabi"
Expand Down Expand Up @@ -387,10 +389,13 @@ func (svr *web3Handler) call(in *gjson.Result) (interface{}, error) {
return "0x" + ret, nil
}
exec, _ := action.NewExecution(to, 0, value, gasLimit, big.NewInt(0), data)
ret, _, err := svr.coreService.ReadContract(context.Background(), callerAddr, exec)
ret, receipt, err := svr.coreService.ReadContract(context.Background(), callerAddr, exec)
if err != nil {
return nil, err
}
if receipt != nil && len(receipt.GetExecutionRevertMsg()) > 0 {
return "0x" + ret, status.Error(codes.InvalidArgument, "execution reverted: "+receipt.GetExecutionRevertMsg())
}
return "0x" + ret, nil
}

Expand Down
6 changes: 4 additions & 2 deletions api/web3server_marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ type (
}

errMessage struct {
Code int `json:"code"`
Message string `json:"message"`
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}

streamResponse struct {
Expand Down Expand Up @@ -124,6 +125,7 @@ func (obj *web3Response) MarshalJSON() ([]byte, error) {
Error: errMessage{
Code: errCode,
Message: errMsg,
Data: obj.result,
},
})
}
Expand Down

0 comments on commit 55b5a58

Please sign in to comment.