From 32312912c935288cd911a39ca5e6b7cd1a24e695 Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Wed, 20 Sep 2023 17:06:21 +0200 Subject: [PATCH] optional block param --- internal/ethapi/api.go | 8 ++++++-- internal/ethapi/api_test.go | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 13ac8cb273..cc3f7d09ad 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -1243,8 +1243,12 @@ type multicallOpts struct { // // Note, this function doesn't make any changes in the state/blockchain and is // useful to execute and retrieve values. -func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash rpc.BlockNumberOrHash) ([]blockResult, error) { - state, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, blockNrOrHash) +func (s *BlockChainAPI) MulticallV1(ctx context.Context, opts multicallOpts, blockNrOrHash *rpc.BlockNumberOrHash) ([]blockResult, error) { + if blockNrOrHash == nil { + n := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber) + blockNrOrHash = &n + } + state, header, err := s.b.StateAndHeaderByNumberOrHash(ctx, *blockNrOrHash) if state == nil || err != nil { return nil, err } diff --git a/internal/ethapi/api_test.go b/internal/ethapi/api_test.go index b1894ad80d..6766dff434 100644 --- a/internal/ethapi/api_test.go +++ b/internal/ethapi/api_test.go @@ -1659,7 +1659,7 @@ func TestMulticallV1(t *testing.T) { if tc.validation != nil && *tc.validation { opts.Validation = true } - result, err := api.MulticallV1(context.Background(), opts, tc.tag) + result, err := api.MulticallV1(context.Background(), opts, &tc.tag) if tc.expectErr != nil { if err == nil { t.Fatalf("test %s: want error %v, have nothing", tc.name, tc.expectErr)