diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-13 22:03:19 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-03-13 22:03:19 +0800 |
commit | 0932f843830a30ea3da5d866fbe4e459d2748b1e (patch) | |
tree | 6a65f6e67493f8511e59a27222962eb86a6aabb0 | |
parent | d4ed66c83df40c6d3035e21c705b4ca06e52a0be (diff) | |
download | go-tangerine-0932f843830a30ea3da5d866fbe4e459d2748b1e.tar.gz go-tangerine-0932f843830a30ea3da5d866fbe4e459d2748b1e.tar.zst go-tangerine-0932f843830a30ea3da5d866fbe4e459d2748b1e.zip |
Fix eth_newBlockFilter
-rw-r--r-- | rpc/api.go | 12 | ||||
-rw-r--r-- | rpc/args.go | 9 |
2 files changed, 15 insertions, 6 deletions
diff --git a/rpc/api.go b/rpc/api.go index 05f4d0bc4..630fb32b5 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -176,7 +176,7 @@ func (self *EthereumApi) UninstallFilter(id int, reply *interface{}) error { return nil } -func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error { +func (self *EthereumApi) NewFilterString(args *FilterStringArgs, reply *interface{}) error { var id int filter := core.NewFilter(self.xeth().Backend()) @@ -186,10 +186,14 @@ func (self *EthereumApi) NewFilterString(args string, reply *interface{}) error self.logs[id].add(&state.StateLog{}) } - if args == "pending" { + + switch args.Word { + case "pending": filter.PendingCallback = callback - } else if args == "chain" { + case "latest": filter.BlockCallback = callback + default: + return NewValidationError("Word", "Must be `latest` or `pending`") } id = self.filterManager.InstallFilter(filter) @@ -692,7 +696,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error if err := json.Unmarshal(req.Params, &args); err != nil { return err } - return p.NewFilterString(args.Word, reply) + return p.NewFilterString(args, reply) case "eth_uninstallFilter": args := new(FilterIdArgs) if err := json.Unmarshal(req.Params, &args); err != nil { diff --git a/rpc/args.go b/rpc/args.go index 8d4ad5967..b935c5007 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -503,7 +503,7 @@ type FilterStringArgs struct { } func (args *FilterStringArgs) UnmarshalJSON(b []byte) (err error) { - var obj []string + var obj []interface{} r := bytes.NewReader(b) if err := json.NewDecoder(r).Decode(&obj); err != nil { return NewDecodeParamError(err.Error()) @@ -513,7 +513,12 @@ func (args *FilterStringArgs) UnmarshalJSON(b []byte) (err error) { return NewInsufficientParamsError(len(obj), 1) } - args.Word = obj[0] + var argstr string + argstr, ok := obj[0].(string) + if !ok { + return NewDecodeParamError("Filter is not a string") + } + args.Word = argstr return nil } |