Commit 6661bc35 authored by Taylor Gerring's avatar Taylor Gerring

Accept number or string for BlockFilterArgs to/fromBlock

parent 745dd5b7
...@@ -424,17 +424,20 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { ...@@ -424,17 +424,20 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
return NewInsufficientParamsError(len(obj), 1) return NewInsufficientParamsError(len(obj), 1)
} }
fromstr, ok := obj[0].FromBlock.(string) var num int64
if !ok { if err := blockHeight(obj[0].FromBlock, &num); err != nil {
return NewInvalidTypeError("fromBlock", "is not a string") return err
}
if num < 0 {
args.Earliest = -1 //latest block
} else {
args.Earliest = num
} }
switch fromstr { if err := blockHeight(obj[0].ToBlock, &num); err != nil {
case "latest": return err
args.Earliest = -1
default:
args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64())
} }
args.Latest = num
tostr, ok := obj[0].ToBlock.(string) tostr, ok := obj[0].ToBlock.(string)
if !ok { if !ok {
......
...@@ -759,10 +759,10 @@ func TestBlockFilterArgsWords(t *testing.T) { ...@@ -759,10 +759,10 @@ func TestBlockFilterArgsWords(t *testing.T) {
} }
} }
func TestBlockFilterArgsNums(t *testing.T) { func TestBlockFilterArgsBool(t *testing.T) {
input := `[{ input := `[{
"fromBlock": 2, "fromBlock": true,
"toBlock": 3 "toBlock": false
}]` }]`
args := new(BlockFilterArgs) args := new(BlockFilterArgs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment