aboutsummaryrefslogtreecommitdiffstats
path: root/rpc
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 00:27:29 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 00:27:29 +0800
commit6661bc35efc9c5d5a874e42558d568d9aa183fee (patch)
treebe70091cea5dbaa0d14095f99274b5018bb5d32b /rpc
parent745dd5b7a517cf0930f96a9b162821d0d631dea9 (diff)
downloaddexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.tar
dexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.tar.gz
dexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.tar.bz2
dexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.tar.lz
dexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.tar.xz
dexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.tar.zst
dexon-6661bc35efc9c5d5a874e42558d568d9aa183fee.zip
Accept number or string for BlockFilterArgs to/fromBlock
Diffstat (limited to 'rpc')
-rw-r--r--rpc/args.go19
-rw-r--r--rpc/args_test.go6
2 files changed, 14 insertions, 11 deletions
diff --git a/rpc/args.go b/rpc/args.go
index b23216c98..206472aa2 100644
--- a/rpc/args.go
+++ b/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 {
diff --git a/rpc/args_test.go b/rpc/args_test.go
index 0c7360c53..2622891b9 100644
--- a/rpc/args_test.go
+++ b/rpc/args_test.go
@@ -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)