forked from cerc-io/plugeth
Accept number or string for BlockFilterArgs to/fromBlock
This commit is contained in:
parent
745dd5b7a5
commit
6661bc35ef
19
rpc/args.go
19
rpc/args.go
@ -424,17 +424,20 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
|
||||
return NewInsufficientParamsError(len(obj), 1)
|
||||
}
|
||||
|
||||
fromstr, ok := obj[0].FromBlock.(string)
|
||||
if !ok {
|
||||
return NewInvalidTypeError("fromBlock", "is not a string")
|
||||
var num int64
|
||||
if err := blockHeight(obj[0].FromBlock, &num); err != nil {
|
||||
return err
|
||||
}
|
||||
if num < 0 {
|
||||
args.Earliest = -1 //latest block
|
||||
} else {
|
||||
args.Earliest = num
|
||||
}
|
||||
|
||||
switch fromstr {
|
||||
case "latest":
|
||||
args.Earliest = -1
|
||||
default:
|
||||
args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64())
|
||||
if err := blockHeight(obj[0].ToBlock, &num); err != nil {
|
||||
return err
|
||||
}
|
||||
args.Latest = num
|
||||
|
||||
tostr, ok := obj[0].ToBlock.(string)
|
||||
if !ok {
|
||||
|
@ -759,10 +759,10 @@ func TestBlockFilterArgsWords(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestBlockFilterArgsNums(t *testing.T) {
|
||||
func TestBlockFilterArgsBool(t *testing.T) {
|
||||
input := `[{
|
||||
"fromBlock": 2,
|
||||
"toBlock": 3
|
||||
"fromBlock": true,
|
||||
"toBlock": false
|
||||
}]`
|
||||
|
||||
args := new(BlockFilterArgs)
|
||||
|
Loading…
Reference in New Issue
Block a user