From eb433731aa535a47c4a828ea15eafabd37a8278b Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Mar 2015 12:06:14 +0100 Subject: Fixed filter and refactored code --- rpc/args.go | 51 ++++++++++++++++++++++++++++----------------------- 1 file changed, 28 insertions(+), 23 deletions(-) (limited to 'rpc') diff --git a/rpc/args.go b/rpc/args.go index 5b655024c..892e3f3e1 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -3,6 +3,8 @@ package rpc import ( "bytes" "encoding/json" + "errors" + "fmt" "math/big" "github.com/ethereum/go-ethereum/common" @@ -442,6 +444,26 @@ type BlockFilterArgs struct { Max int } +func toNumber(v interface{}) (int64, error) { + var str string + if v != nil { + var ok bool + str, ok = v.(string) + if !ok { + return 0, errors.New("is not a string or undefined") + } + } else { + str = "latest" + } + + switch str { + case "latest": + return -1, nil + default: + return int64(common.Big(v.(string)).Int64()), nil + } +} + func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { var obj []struct { FromBlock interface{} `json:"fromBlock"` @@ -460,30 +482,13 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { return NewInsufficientParamsError(len(obj), 1) } - fromstr, ok := obj[0].FromBlock.(string) - if !ok { - return NewDecodeParamError("FromBlock is not a string") + args.Earliest, err = toNumber(obj[0].FromBlock) + if err != nil { + return NewDecodeParamError(fmt.Sprintf("FromBlock %v", err)) } - - switch fromstr { - case "latest": - args.Earliest = -1 - default: - args.Earliest = int64(common.Big(obj[0].FromBlock.(string)).Int64()) - } - - tostr, ok := obj[0].ToBlock.(string) - if !ok { - return NewDecodeParamError("ToBlock is not a string") - } - - switch tostr { - case "latest": - args.Latest = -1 - case "pending": - args.Latest = -2 - default: - args.Latest = int64(common.Big(obj[0].ToBlock.(string)).Int64()) + args.Latest, err = toNumber(obj[0].FromBlock) + if err != nil { + return NewDecodeParamError(fmt.Sprintf("ToBlock %v", err)) } args.Max = int(common.Big(obj[0].Limit).Int64()) -- cgit From 4ba850639ede569bda4413b8e986b26726950d08 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Mar 2015 12:15:12 +0100 Subject: updated web3.js light for console --- rpc/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rpc') diff --git a/rpc/api.go b/rpc/api.go index aa5b54199..230d9ff9c 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -50,7 +50,7 @@ func (api *EthereumApi) Close() { func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/JSON-RPC - rpclogger.Debugf("%s %s", req.Method, req.Params) + rpclogger.Infof("%s %s", req.Method, req.Params) switch req.Method { case "web3_sha3": -- cgit From b8a667deedcd2affcd4095547246c89f4a932af6 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Mar 2015 12:15:25 +0100 Subject: debug log --- rpc/api.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rpc') diff --git a/rpc/api.go b/rpc/api.go index 230d9ff9c..aa5b54199 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -50,7 +50,7 @@ func (api *EthereumApi) Close() { func (api *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { // Spec at https://github.com/ethereum/wiki/wiki/JSON-RPC - rpclogger.Infof("%s %s", req.Method, req.Params) + rpclogger.Debugf("%s %s", req.Method, req.Params) switch req.Method { case "web3_sha3": -- cgit From 83b0cad76667c570a1be81653b531e6a9d513928 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Mar 2015 12:34:59 +0100 Subject: fixed block filter args --- rpc/args.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'rpc') diff --git a/rpc/args.go b/rpc/args.go index 892e3f3e1..61331d993 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -482,7 +482,7 @@ func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { return NewInsufficientParamsError(len(obj), 1) } - args.Earliest, err = toNumber(obj[0].FromBlock) + args.Earliest, err = toNumber(obj[0].ToBlock) if err != nil { return NewDecodeParamError(fmt.Sprintf("FromBlock %v", err)) } -- cgit From c33dc3e328c791be8c82b514ba07523f065402e1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 26 Mar 2015 12:40:09 +0100 Subject: moved helper --- rpc/args.go | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'rpc') diff --git a/rpc/args.go b/rpc/args.go index 61331d993..1928ec218 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -36,6 +36,26 @@ func blockHeight(raw interface{}, number *int64) (err error) { return nil } +func toNumber(v interface{}) (int64, error) { + var str string + if v != nil { + var ok bool + str, ok = v.(string) + if !ok { + return 0, errors.New("is not a string or undefined") + } + } else { + str = "latest" + } + + switch str { + case "latest": + return -1, nil + default: + return int64(common.Big(v.(string)).Int64()), nil + } +} + type GetBlockByHashArgs struct { BlockHash string IncludeTxs bool @@ -444,26 +464,6 @@ type BlockFilterArgs struct { Max int } -func toNumber(v interface{}) (int64, error) { - var str string - if v != nil { - var ok bool - str, ok = v.(string) - if !ok { - return 0, errors.New("is not a string or undefined") - } - } else { - str = "latest" - } - - switch str { - case "latest": - return -1, nil - default: - return int64(common.Big(v.(string)).Int64()), nil - } -} - func (args *BlockFilterArgs) UnmarshalJSON(b []byte) (err error) { var obj []struct { FromBlock interface{} `json:"fromBlock"` -- cgit