Skip to content

Commit

Permalink
rpc: return an unsupported error when "pending" was used to create a …
Browse files Browse the repository at this point in the history
…filter
  • Loading branch information
bas-vk committed Oct 29, 2015
1 parent 56f8699 commit 76410df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
12 changes: 5 additions & 7 deletions rpc/api/args_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1394,13 +1394,10 @@ func TestBlockFilterArgsDefaults(t *testing.T) {
}

func TestBlockFilterArgsWords(t *testing.T) {
input := `[{
"fromBlock": "latest",
"toBlock": "pending"
}]`
input := `[{"fromBlock": "latest", "toBlock": "latest"}]`
expected := new(BlockFilterArgs)
expected.Earliest = -1
expected.Latest = -2
expected.Latest = -1

args := new(BlockFilterArgs)
if err := json.Unmarshal([]byte(input), &args); err != nil {
Expand All @@ -1411,8 +1408,9 @@ func TestBlockFilterArgsWords(t *testing.T) {
t.Errorf("Earliest shoud be %#v but is %#v", expected.Earliest, args.Earliest)
}

if expected.Latest != args.Latest {
t.Errorf("Latest shoud be %#v but is %#v", expected.Latest, args.Latest)
input = `[{"toBlock": "pending"}]`
if err := json.Unmarshal([]byte(input), &args); err == nil {
t.Errorf("Pending isn't currently supported and should raise an unsupported error")
}
}

Expand Down
7 changes: 7 additions & 0 deletions rpc/api/eth_args.go
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,13 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
return err
}
}

if num == -2 {
return fmt.Errorf("\"pending\" is unsupported")
} else if num < -2 {
return fmt.Errorf("Invalid to block number")
}

args.Latest = num

if obj[0].Limit == nil {
Expand Down

0 comments on commit 76410df

Please sign in to comment.