Skip to content

Commit 76410df

Browse files
committed
rpc: return an unsupported error when "pending" was used to create a filter
1 parent 56f8699 commit 76410df

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

rpc/api/args_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,13 +1394,10 @@ func TestBlockFilterArgsDefaults(t *testing.T) {
13941394
}
13951395

13961396
func TestBlockFilterArgsWords(t *testing.T) {
1397-
input := `[{
1398-
"fromBlock": "latest",
1399-
"toBlock": "pending"
1400-
}]`
1397+
input := `[{"fromBlock": "latest", "toBlock": "latest"}]`
14011398
expected := new(BlockFilterArgs)
14021399
expected.Earliest = -1
1403-
expected.Latest = -2
1400+
expected.Latest = -1
14041401

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

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

rpc/api/eth_args.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,13 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) {
714714
return err
715715
}
716716
}
717+
718+
if num == -2 {
719+
return fmt.Errorf("\"pending\" is unsupported")
720+
} else if num < -2 {
721+
return fmt.Errorf("Invalid to block number")
722+
}
723+
717724
args.Latest = num
718725

719726
if obj[0].Limit == nil {

0 commit comments

Comments
 (0)