Skip to content

Commit adb9b31

Browse files
authored
internal/ethapi: eth_call block parameter is optional (#28165)
So apparently in the spec the base block parameter of eth_call is optional. I agree that "latest" is a sane default for this that most people would use.
1 parent 2b7bc2c commit adb9b31

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

internal/ethapi/api.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,8 +1158,12 @@ func (e *revertError) ErrorData() interface{} {
11581158
//
11591159
// Note, this function doesn't make and changes in the state/blockchain and is
11601160
// useful to execute and retrieve values.
1161-
func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) {
1162-
result, err := DoCall(ctx, s.b, args, blockNrOrHash, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
1161+
func (s *BlockChainAPI) Call(ctx context.Context, args TransactionArgs, blockNrOrHash *rpc.BlockNumberOrHash, overrides *StateOverride, blockOverrides *BlockOverrides) (hexutil.Bytes, error) {
1162+
if blockNrOrHash == nil {
1163+
latest := rpc.BlockNumberOrHashWithNumber(rpc.LatestBlockNumber)
1164+
blockNrOrHash = &latest
1165+
}
1166+
result, err := DoCall(ctx, s.b, args, *blockNrOrHash, overrides, blockOverrides, s.b.RPCEVMTimeout(), s.b.RPCGasCap())
11631167
if err != nil {
11641168
return nil, err
11651169
}

internal/ethapi/api_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ func TestCall(t *testing.T) {
846846
},
847847
}
848848
for i, tc := range testSuite {
849-
result, err := api.Call(context.Background(), tc.call, rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides)
849+
result, err := api.Call(context.Background(), tc.call, &rpc.BlockNumberOrHash{BlockNumber: &tc.blockNumber}, &tc.overrides, &tc.blockOverrides)
850850
if tc.expectErr != nil {
851851
if err == nil {
852852
t.Errorf("test %d: want error %v, have nothing", i, tc.expectErr)

0 commit comments

Comments
 (0)