From 83c4a9cad204edcfaf7e896983c71ea7de1c247a Mon Sep 17 00:00:00 2001 From: Zsolt Felfoldi Date: Mon, 9 Aug 2021 11:40:34 +0200 Subject: [PATCH] internal/ethapi: accept both hex and decimal for blockCount --- internal/ethapi/api.go | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index 30f6dd06ab67f..6f2ce35ff004a 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -87,8 +87,23 @@ type feeHistoryResult struct { GasUsedRatio []float64 `json:"gasUsedRatio"` } -func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount hexutil.Uint, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) { - oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, int(blockCount), lastBlock, rewardPercentiles) +func (s *PublicEthereumAPI) FeeHistory(ctx context.Context, blockCount interface{}, lastBlock rpc.BlockNumber, rewardPercentiles []float64) (*feeHistoryResult, error) { + var blockCountInt int + if s, ok := blockCount.(string); ok { + if v, err := hexutil.DecodeUint64(s); err != nil { + return nil, err + } else { + blockCountInt = int(v) + } + } else { + if f, ok := blockCount.(float64); ok && f >= 0 && float64(int(f)) == f { + blockCountInt = int(f) + } else { + return nil, errors.New("invalid type for blockCount parameter") + } + } + + oldest, reward, baseFee, gasUsed, err := s.b.FeeHistory(ctx, blockCountInt, lastBlock, rewardPercentiles) if err != nil { return nil, err }