From 21becb0febdf11132a40ff69c6145d9babf8458d Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 24 Feb 2015 19:05:03 +0100 Subject: [PATCH 1/4] Cleanup RPC packcage --- rpc/args.go | 66 ++++++--------------- rpc/message.go | 150 ++++++++++++++++++++++-------------------------- rpc/packages.go | 5 +- 3 files changed, 90 insertions(+), 131 deletions(-) diff --git a/rpc/args.go b/rpc/args.go index 347f60410..e839da8bf 100644 --- a/rpc/args.go +++ b/rpc/args.go @@ -19,7 +19,7 @@ func (obj *GetBlockArgs) UnmarshalJSON(b []byte) (err error) { obj.Hash = argstr return } - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } type NewTxArgs struct { @@ -57,7 +57,7 @@ func (obj *NewTxArgs) UnmarshalJSON(b []byte) (err error) { return } - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } type PushTxArgs struct { @@ -70,12 +70,12 @@ func (obj *PushTxArgs) UnmarshalJSON(b []byte) (err error) { obj.Tx = arg0 return } - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } func (a *PushTxArgs) requirementsPushTx() error { if a.Tx == "" { - return NewErrorResponse("PushTx requires a 'tx' as argument") + return NewErrorWithMessage(errArguments, "PushTx requires a 'tx' as argument") } return nil } @@ -86,14 +86,14 @@ type GetStorageArgs struct { func (obj *GetStorageArgs) UnmarshalJSON(b []byte) (err error) { if err = json.Unmarshal(b, &obj.Address); err != nil { - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } return } func (a *GetStorageArgs) requirements() error { if len(a.Address) == 0 { - return NewErrorResponse("GetStorageAt requires an 'address' value as argument") + return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument") } return nil } @@ -109,64 +109,39 @@ func (obj *GetStateArgs) UnmarshalJSON(b []byte) (err error) { obj.Address = arg0 return } - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } func (a *GetStateArgs) requirements() error { if a.Address == "" { - return NewErrorResponse("GetStorageAt requires an 'address' value as argument") + return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'address' value as argument") } if a.Key == "" { - return NewErrorResponse("GetStorageAt requires an 'key' value as argument") + return NewErrorWithMessage(errArguments, "GetStorageAt requires an 'key' value as argument") } return nil } -type GetStorageAtRes struct { - Key string `json:"key"` - Value string `json:"value"` -} - type GetTxCountArgs struct { Address string `json:"address"` } -// type GetTxCountRes struct { -// Nonce int `json:"nonce"` -// } - func (obj *GetTxCountArgs) UnmarshalJSON(b []byte) (err error) { arg0 := "" if err = json.Unmarshal(b, &arg0); err == nil { obj.Address = arg0 return } - return NewErrorResponse("Could not determine JSON parameters") + return errDecodeArgs } func (a *GetTxCountArgs) requirements() error { if a.Address == "" { - return NewErrorResponse("GetTxCountAt requires an 'address' value as argument") + return NewErrorWithMessage(errArguments, "GetTxCountAt requires an 'address' value as argument") } return nil } -// type GetPeerCountRes struct { -// PeerCount int `json:"peerCount"` -// } - -// type GetListeningRes struct { -// IsListening bool `json:"isListening"` -// } - -// type GetCoinbaseRes struct { -// Coinbase string `json:"coinbase"` -// } - -// type GetMiningRes struct { -// IsMining bool `json:"isMining"` -// } - type GetBalanceArgs struct { Address string } @@ -177,21 +152,16 @@ func (obj *GetBalanceArgs) UnmarshalJSON(b []byte) (err error) { obj.Address = arg0 return } - return NewErrorResponse("Could not determine JSON parameters") + return errDecodeArgs } func (a *GetBalanceArgs) requirements() error { if a.Address == "" { - return NewErrorResponse("GetBalanceAt requires an 'address' value as argument") + return NewErrorWithMessage(errArguments, "GetBalanceAt requires an 'address' value as argument") } return nil } -type BalanceRes struct { - Balance string `json:"balance"` - Address string `json:"address"` -} - type GetCodeAtArgs struct { Address string } @@ -202,12 +172,12 @@ func (obj *GetCodeAtArgs) UnmarshalJSON(b []byte) (err error) { obj.Address = arg0 return } - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } func (a *GetCodeAtArgs) requirements() error { if a.Address == "" { - return NewErrorResponse("GetCodeAt requires an 'address' value as argument") + return NewErrorWithMessage(errArguments, "GetCodeAt requires an 'address' value as argument") } return nil } @@ -218,7 +188,7 @@ type Sha3Args struct { func (obj *Sha3Args) UnmarshalJSON(b []byte) (err error) { if err = json.Unmarshal(b, &obj.Data); err != nil { - return NewErrorResponse(ErrorDecodeArgs) + return errDecodeArgs } return } @@ -270,10 +240,10 @@ type DbArgs struct { func (a *DbArgs) requirements() error { if len(a.Database) == 0 { - return NewErrorResponse("DbPutArgs requires an 'Database' value as argument") + return NewErrorWithMessage(errArguments, "DbPutArgs requires an 'Database' value as argument") } if len(a.Key) == 0 { - return NewErrorResponse("DbPutArgs requires an 'Key' value as argument") + return NewErrorWithMessage(errArguments, "DbPutArgs requires an 'Key' value as argument") } return nil } diff --git a/rpc/message.go b/rpc/message.go index 825ede05b..18fbec931 100644 --- a/rpc/message.go +++ b/rpc/message.go @@ -25,12 +25,12 @@ import ( "github.com/ethereum/go-ethereum/xeth" ) -const ( - ErrorArguments = "Error: Insufficient arguments" - ErrorNotImplemented = "Error: Method not implemented" - ErrorUnknown = "Error: Unknown error" - ErrorParseRequest = "Error: Could not parse request" - ErrorDecodeArgs = "Error: Could not decode arguments" +var ( + errArguments = errors.New("Error: Insufficient arguments") + errNotImplemented = errors.New("Error: Method not implemented") + errUnknown = errors.New("Error: Unknown error") + errParseRequest = errors.New("Error: Could not parse request") + errDecodeArgs = errors.New("Error: Could not decode arguments") ) type RpcRequest struct { @@ -58,76 +58,72 @@ type RpcErrorObject struct { // Data interface{} `json:"data"` } -func NewErrorResponse(msg string) error { - return errors.New(msg) -} - -func NewErrorResponseWithError(msg string, err error) error { - return fmt.Errorf("%s: %v", msg, err) +func NewErrorWithMessage(err error, msg string) error { + return fmt.Errorf("%s: %s", err.Error(), msg) } func (req *RpcRequest) ToSha3Args() (*Sha3Args, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(Sha3Args) r := bytes.NewReader(req.Params[0]) if err := json.NewDecoder(r).Decode(args); err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToGetBlockArgs() (*GetBlockArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(GetBlockArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToNewTxArgs() (*NewTxArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(NewTxArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToPushTxArgs() (*PushTxArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(PushTxArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(GetStateArgs) @@ -135,234 +131,228 @@ func (req *RpcRequest) ToGetStateArgs() (*GetStateArgs, error) { r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToStorageAtArgs() (*GetStorageArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(GetStorageArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToGetTxCountArgs() (*GetTxCountArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(GetTxCountArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToGetBalanceArgs() (*GetBalanceArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(GetBalanceArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToGetCodeAtArgs() (*GetCodeAtArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(GetCodeAtArgs) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToBoolArgs() (bool, error) { if len(req.Params) < 1 { - return false, NewErrorResponse(ErrorArguments) + return false, errArguments } var args bool err := json.Unmarshal(req.Params[0], &args) if err != nil { - return false, NewErrorResponse(ErrorDecodeArgs) + return false, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) return args, nil } func (req *RpcRequest) ToCompileArgs() (string, error) { if len(req.Params) < 1 { - return "", NewErrorResponse(ErrorArguments) + return "", errArguments } var args string err := json.Unmarshal(req.Params[0], &args) if err != nil { - return "", NewErrorResponse(ErrorDecodeArgs) + return "", errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) return args, nil } func (req *RpcRequest) ToFilterArgs() (*FilterOptions, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } args := new(FilterOptions) r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(args) if err != nil { - return nil, NewErrorResponse(ErrorDecodeArgs) + return nil, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) return args, nil } func (req *RpcRequest) ToFilterStringArgs() (string, error) { if len(req.Params) < 1 { - return "", NewErrorResponse(ErrorArguments) + return "", errArguments } var args string err := json.Unmarshal(req.Params[0], &args) if err != nil { - return "", NewErrorResponse(ErrorDecodeArgs) + return "", errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) return args, nil } func (req *RpcRequest) ToUninstallFilterArgs() (int, error) { if len(req.Params) < 1 { - return 0, NewErrorResponse(ErrorArguments) + return 0, errArguments } var args int err := json.Unmarshal(req.Params[0], &args) if err != nil { - return 0, NewErrorResponse(ErrorDecodeArgs) + return 0, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", args, args) return args, nil } func (req *RpcRequest) ToFilterChangedArgs() (int, error) { if len(req.Params) < 1 { - return 0, NewErrorResponse(ErrorArguments) + return 0, errArguments } var id int r := bytes.NewReader(req.Params[0]) err := json.NewDecoder(r).Decode(&id) if err != nil { - return 0, NewErrorResponse(ErrorDecodeArgs) + return 0, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", id, id) return id, nil } func (req *RpcRequest) ToDbPutArgs() (*DbArgs, error) { if len(req.Params) < 3 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } var args DbArgs err := json.Unmarshal(req.Params[0], &args.Database) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } err = json.Unmarshal(req.Params[1], &args.Key) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } err = json.Unmarshal(req.Params[2], &args.Value) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } - rpclogger.DebugDetailf("%T %v", args, args) + return &args, nil } func (req *RpcRequest) ToDbGetArgs() (*DbArgs, error) { if len(req.Params) < 2 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } var args DbArgs err := json.Unmarshal(req.Params[0], &args.Database) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } err = json.Unmarshal(req.Params[1], &args.Key) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } - rpclogger.DebugDetailf("%T %v", args, args) + return &args, nil } func (req *RpcRequest) ToWhisperFilterArgs() (*xeth.Options, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } var args xeth.Options err := json.Unmarshal(req.Params[0], &args) if err != nil { - return nil, NewErrorResponseWithError(ErrorDecodeArgs, err) + return nil, NewErrorWithMessage(errDecodeArgs, err.Error()) } - rpclogger.DebugDetailf("%T %v", args, args) + return &args, nil } func (req *RpcRequest) ToIdArgs() (int, error) { if len(req.Params) < 1 { - return 0, NewErrorResponse(ErrorArguments) + return 0, errArguments } var id int err := json.Unmarshal(req.Params[0], &id) if err != nil { - return 0, NewErrorResponse(ErrorDecodeArgs) + return 0, errDecodeArgs } - rpclogger.DebugDetailf("%T %v", id, id) + return id, nil } func (req *RpcRequest) ToWhisperPostArgs() (*WhisperMessageArgs, error) { if len(req.Params) < 1 { - return nil, NewErrorResponse(ErrorArguments) + return nil, errArguments } var args WhisperMessageArgs @@ -370,13 +360,13 @@ func (req *RpcRequest) ToWhisperPostArgs() (*WhisperMessageArgs, error) { if err != nil { return nil, err } - rpclogger.DebugDetailf("%T %v", args, args) + return &args, nil } func (req *RpcRequest) ToWhisperHasIdentityArgs() (string, error) { if len(req.Params) < 1 { - return "", NewErrorResponse(ErrorArguments) + return "", errArguments } var args string @@ -384,13 +374,13 @@ func (req *RpcRequest) ToWhisperHasIdentityArgs() (string, error) { if err != nil { return "", err } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToRegisterArgs() (string, error) { if len(req.Params) < 1 { - return "", NewErrorResponse(ErrorArguments) + return "", errArguments } var args string @@ -398,13 +388,13 @@ func (req *RpcRequest) ToRegisterArgs() (string, error) { if err != nil { return "", err } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } func (req *RpcRequest) ToWatchTxArgs() (string, error) { if len(req.Params) < 1 { - return "", NewErrorResponse(ErrorArguments) + return "", errArguments } var args string @@ -412,6 +402,6 @@ func (req *RpcRequest) ToWatchTxArgs() (string, error) { if err != nil { return "", err } - rpclogger.DebugDetailf("%T %v", args, args) + return args, nil } diff --git a/rpc/packages.go b/rpc/packages.go index 0f00441d2..813fef949 100644 --- a/rpc/packages.go +++ b/rpc/packages.go @@ -9,7 +9,6 @@ For each request type, define the following: package rpc import ( - "fmt" "math/big" "strings" "sync" @@ -410,7 +409,7 @@ func (p *EthereumApi) WhisperMessages(id int, reply *interface{}) error { } func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error { - // Spec at https://github.com/ethereum/wiki/wiki/Generic-ON-RPC + // Spec at https://github.com/ethereum/wiki/wiki/Generic-JSON-RPC rpclogger.DebugDetailf("%T %s", req.Params, req.Params) switch req.Method { case "eth_coinbase": @@ -595,7 +594,7 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error } return p.WhisperMessages(args, reply) default: - return NewErrorResponse(fmt.Sprintf("%v %s", ErrorNotImplemented, req.Method)) + return NewErrorWithMessage(errNotImplemented, req.Method) } rpclogger.DebugDetailf("Reply: %T %s", reply, reply) From 43acad81b3fbee608bf19e6ba32ba27b98d9a7ff Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 24 Feb 2015 19:11:01 +0100 Subject: [PATCH 2/4] Rename files --- rpc/{packages.go => api.go} | 0 rpc/{packages_test.go => api_test.go} | 0 rpc/{message.go => messages.go} | 0 3 files changed, 0 insertions(+), 0 deletions(-) rename rpc/{packages.go => api.go} (100%) rename rpc/{packages_test.go => api_test.go} (100%) rename rpc/{message.go => messages.go} (100%) diff --git a/rpc/packages.go b/rpc/api.go similarity index 100% rename from rpc/packages.go rename to rpc/api.go diff --git a/rpc/packages_test.go b/rpc/api_test.go similarity index 100% rename from rpc/packages_test.go rename to rpc/api_test.go diff --git a/rpc/message.go b/rpc/messages.go similarity index 100% rename from rpc/message.go rename to rpc/messages.go From c8e9abff53d869f74211e157abcb2827d181e106 Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 24 Feb 2015 19:22:08 +0100 Subject: [PATCH 3/4] Remove errParseRequest --- rpc/http/server.go | 2 +- rpc/messages.go | 1 - rpc/ws/server.go | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/rpc/http/server.go b/rpc/http/server.go index dd6ba68e3..fa66eed48 100644 --- a/rpc/http/server.go +++ b/rpc/http/server.go @@ -92,7 +92,7 @@ func (s *RpcHttpServer) apiHandler(api *rpc.EthereumApi) http.Handler { reqParsed, reqerr := JSON.ParseRequestBody(req) if reqerr != nil { - jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest} + jsonerr := &rpc.RpcErrorObject{-32700, "Error: Could not parse request"} JSON.Send(w, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) return } diff --git a/rpc/messages.go b/rpc/messages.go index 18fbec931..044f07545 100644 --- a/rpc/messages.go +++ b/rpc/messages.go @@ -29,7 +29,6 @@ var ( errArguments = errors.New("Error: Insufficient arguments") errNotImplemented = errors.New("Error: Method not implemented") errUnknown = errors.New("Error: Unknown error") - errParseRequest = errors.New("Error: Could not parse request") errDecodeArgs = errors.New("Error: Could not decode arguments") ) diff --git a/rpc/ws/server.go b/rpc/ws/server.go index b8cc2fa6b..2c2988f5d 100644 --- a/rpc/ws/server.go +++ b/rpc/ws/server.go @@ -99,7 +99,7 @@ func sockHandler(api *rpc.EthereumApi) websocket.Handler { // reqParsed, reqerr := JSON.ParseRequestBody(conn.Request()) if err := websocket.JSON.Receive(conn, &reqParsed); err != nil { - jsonerr := &rpc.RpcErrorObject{-32700, rpc.ErrorParseRequest} + jsonerr := &rpc.RpcErrorObject{-32700, "Error: Could not parse request"} JSON.Send(conn, &rpc.RpcErrorResponse{JsonRpc: jsonrpcver, ID: nil, Error: jsonerr}) continue } From 2e3a6e2559d02ba90957eaf333e571dec935e00a Mon Sep 17 00:00:00 2001 From: Taylor Gerring Date: Tue, 24 Feb 2015 19:54:18 +0100 Subject: [PATCH 4/4] Consolidate related items --- rpc/api.go | 73 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/rpc/api.go b/rpc/api.go index 813fef949..21c85bbcc 100644 --- a/rpc/api.go +++ b/rpc/api.go @@ -25,8 +25,9 @@ import ( ) var ( - defaultGasPrice = big.NewInt(10000000000000) - defaultGas = big.NewInt(10000) + defaultGasPrice = big.NewInt(10000000000000) + defaultGas = big.NewInt(10000) + filterTickerTime = 15 * time.Second ) type EthereumApi struct { @@ -62,6 +63,39 @@ func NewEthereumApi(eth *xeth.XEth) *EthereumApi { return api } +func (self *EthereumApi) start() { + timer := time.NewTicker(filterTickerTime) +done: + for { + select { + case <-timer.C: + self.logMut.Lock() + self.messagesMut.Lock() + for id, filter := range self.logs { + if time.Since(filter.timeout) > 20*time.Second { + self.filterManager.UninstallFilter(id) + delete(self.logs, id) + } + } + + for id, filter := range self.messages { + if time.Since(filter.timeout) > 20*time.Second { + self.xeth.Whisper().Unwatch(id) + delete(self.messages, id) + } + } + self.logMut.Unlock() + self.messagesMut.Unlock() + case <-self.quit: + break done + } + } +} + +func (self *EthereumApi) stop() { + close(self.quit) +} + func (self *EthereumApi) Register(args string, reply *interface{}) error { self.regmut.Lock() defer self.regmut.Unlock() @@ -600,38 +634,3 @@ func (p *EthereumApi) GetRequestReply(req *RpcRequest, reply *interface{}) error rpclogger.DebugDetailf("Reply: %T %s", reply, reply) return nil } - -var filterTickerTime = 15 * time.Second - -func (self *EthereumApi) start() { - timer := time.NewTicker(filterTickerTime) -done: - for { - select { - case <-timer.C: - self.logMut.Lock() - self.messagesMut.Lock() - for id, filter := range self.logs { - if time.Since(filter.timeout) > 20*time.Second { - self.filterManager.UninstallFilter(id) - delete(self.logs, id) - } - } - - for id, filter := range self.messages { - if time.Since(filter.timeout) > 20*time.Second { - self.xeth.Whisper().Unwatch(id) - delete(self.messages, id) - } - } - self.logMut.Unlock() - self.messagesMut.Unlock() - case <-self.quit: - break done - } - } -} - -func (self *EthereumApi) stop() { - close(self.quit) -}