From d2d45169542f438a0cab38955e4c41da345eb0e3 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi <1591639+s1na@users.noreply.github.com> Date: Tue, 26 Sep 2023 14:22:11 +0200 Subject: [PATCH] internal/ethapi: eth_call block parameter is optional (#28165) commit https://github.com/ethereum/go-ethereum/commit/adb9b319c9c61f092755000bf0fc4b3349f5cbbc. Make the block parameter in eth_call is optional following the specification. The default value when block parameter is not provided is "latest". --- consensus/consortium/common/contract.go | 4 ++-- internal/ethapi/api.go | 8 ++++++-- internal/ethapi/api_test.go | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/consensus/consortium/common/contract.go b/consensus/consortium/common/contract.go index 7f6f5a56a..f5292dc10 100644 --- a/consensus/consortium/common/contract.go +++ b/consensus/consortium/common/contract.go @@ -435,7 +435,7 @@ func (c *ContractIntegrator) contractCall( Gas: &gas, To: &to, Data: &msgData, - }, blockNrOrHash, nil, nil) + }, &blockNrOrHash, nil, nil) if err != nil { return err } @@ -635,7 +635,7 @@ func (b *ConsortiumBackend) CallContract(ctx context.Context, call ethereum.Call Gas: &gas, To: call.To, Data: &data, - }, block, nil, nil) + }, &block, nil, nil) if err != nil { return nil, err } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 99866884d..b2d255cbc 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1147,8 +1147,12 @@ func (e *revertError) ErrorData() interface{} { // // Note, this function doesn't make and changes in the state/blockchain and is // useful to execute and retrieve values. -func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) { - result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) +func (s *PublicBlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) { + if blockNrOrHash == nil { + latest := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) + blockNrOrHash = &latest + } + result, err := DoCall(ctx, s.b, args, *blockNrOrHash, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap()) if err != nil { return nil, err } diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index af82715b8..219e5003a 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -922,7 +922,7 @@ func TestCall(t *testing.T) { }, } for i, tc := range testSuite { - result, err := api.Call(context.Background(), tc.call, rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides) + result, err := api.Call(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides) if tc.expectErr != nil { if err == nil { t.Errorf("test %d: want error %v, have nothing", i, tc.expectErr)