From d23eb894d62ac3cd0dfb87683c8bf5156ff95026 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Thu, 13 Jul 2023 16:03:52 +0200 Subject: [PATCH] Add status field to call result --- internal/ethapi/api.go | 8 ++++++-- internal/ethapi/api_test.go | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index ee8d42a952..1704bad8ab 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1119,6 +1119,7 @@ type callResult struct { Logs []*types.Log `json:"logs"` Transfers []transfer `json:"transfers,omitempty"` GasUsed hexutil.Uint64 `json:"gasUsed"` + Status hexutil.Uint64 `json:"status"` Error string `json:"error,omitempty"` } @@ -1205,7 +1206,7 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, blocks []CallBatch, blo } result, err := doCall(ctx, s.b, call, state, header, timeout, gp, &blockContext, vmConfig) if err != nil { - results[bi].Calls[i] = callResult{Error: err.Error()} + results[bi].Calls[i] = callResult{Error: err.Error(), Status: hexutil.Uint64(types.ReceiptStatusFailed)} continue } // If the result contains a revert reason, try to unpack it. @@ -1222,8 +1223,11 @@ func (s *BlockChainAPI) MulticallV1(ctx context.Context, blocks []CallBatch, blo transfers = vmConfig.Tracer.(*tracer).Transfers() } callRes := callResult{ReturnValue: result.Return(), Logs: logs, Transfers: transfers, GasUsed: hexutil.Uint64(result.UsedGas)} - if result.Err != nil { + if result.Failed() { + callRes.Status = hexutil.Uint64(types.ReceiptStatusFailed) callRes.Error = result.Err.Error() + } else { + callRes.Status = hexutil.Uint64(types.ReceiptStatusSuccessful) } results[bi].Calls[i] = callRes gasUsed += result.UsedGas diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index 09012be4f4..db5c2cdb20 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -647,6 +647,7 @@ func TestMulticallV1(t *testing.T) { Error string Logs []types.Log GasUsed string + Status string Transfers []transfer } type blockRes struct { @@ -695,10 +696,12 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x", GasUsed: "0x5208", Logs: []types.Log{}, + Status: "0x1", }, { ReturnValue: "0x", GasUsed: "0x5208", Logs: []types.Log{}, + Status: "0x1", }}, }}, }, { @@ -745,10 +748,12 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x", GasUsed: "0x5208", Logs: []types.Log{}, + Status: "0x1", }, { ReturnValue: "0x", GasUsed: "0x5208", Logs: []types.Log{}, + Status: "0x1", }}, }, { Number: "0xa", @@ -760,10 +765,12 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x", GasUsed: "0x5208", Logs: []types.Log{}, + Status: "0x1", }, { ReturnValue: "0x", GasUsed: "0x0", Logs: []types.Log{}, + Status: "0x0", Error: fmt.Sprintf("err: insufficient funds for gas * price + value: address %s have 0 want 1000 (supplied gas 9937000)", randomAccounts[3].addr.String()), }}, }}, @@ -807,6 +814,7 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000b", GasUsed: "0xe891", Logs: []types.Log{}, + Status: "0x1", }}, }, { Number: "0xc", @@ -818,6 +826,7 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x000000000000000000000000000000000000000000000000000000000000000c", GasUsed: "0xe891", Logs: []types.Log{}, + Status: "0x1", }}, }}, }, @@ -884,10 +893,12 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x", GasUsed: "0xaacc", Logs: []types.Log{}, + Status: "0x1", }, { ReturnValue: "0x0000000000000000000000000000000000000000000000000000000000000005", GasUsed: "0x5bb7", Logs: []types.Log{}, + Status: "0x1", }}, }}, }, @@ -928,6 +939,7 @@ func TestMulticallV1(t *testing.T) { Data: []byte{}, }}, GasUsed: "0x5508", + Status: "0x1", }}, }}, }, @@ -990,6 +1002,7 @@ func TestMulticallV1(t *testing.T) { ReturnValue: strings.ToLower(randomAccounts[2].addr.String()), GasUsed: "0x52f6", Logs: []types.Log{}, + Status: "0x1", }}, }}, }, @@ -1042,7 +1055,8 @@ func TestMulticallV1(t *testing.T) { Value: big.NewInt(100), }, }, - Logs: []types.Log{}, + Logs: []types.Log{}, + Status: "0x1", }}, }}, }, @@ -1084,10 +1098,12 @@ func TestMulticallV1(t *testing.T) { ReturnValue: "0x", GasUsed: "0xd166", Logs: []types.Log{}, + Status: "0x1", }, { ReturnValue: "0x", GasUsed: "0xe6d9", Logs: []types.Log{}, + Status: "0x1", }}, }}, },