Skip to content

Commit

Permalink
internal/ethapi: accept both hex and decimal for blockCount
Browse files Browse the repository at this point in the history
  • Loading branch information
zsfelfoldi committed Aug 9, 2021
1 parent 9e59474 commit 83c4a9c
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions internal/ethapi/api.go
Expand Up @@ -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
}
Expand Down

0 comments on commit 83c4a9c

Please sign in to comment.