mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
api: accept both hex and decimal for block number
This commit is contained in:
parent
47d4bf4bf6
commit
8d0e24b2e2
1 changed files with 13 additions and 1 deletions
14
rpc/types.go
14
rpc/types.go
|
|
@ -22,6 +22,7 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/XinFinOrg/XDPoSChain/common"
|
||||
|
|
@ -99,10 +100,21 @@ func (bn *BlockNumber) UnmarshalJSON(data []byte) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
blckNum, err := hexutil.DecodeUint64(input)
|
||||
var blckNum uint64
|
||||
var err error
|
||||
|
||||
//Check if input is valid hex string before converting.
|
||||
if hexutil.IsValidHexString(input) {
|
||||
blckNum, err = hexutil.DecodeUint64(input)
|
||||
} else {
|
||||
//Try converting input directly into uint64 value
|
||||
blckNum, err = strconv.ParseUint(input, 10, 64)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if blckNum > math.MaxInt64 {
|
||||
return errors.New("block number larger than int64")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue