diff options
author | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-25 02:54:18 +0800 |
---|---|---|
committer | Taylor Gerring <taylor.gerring@gmail.com> | 2015-02-25 02:54:18 +0800 |
commit | 2e3a6e2559d02ba90957eaf333e571dec935e00a (patch) | |
tree | dbc70554c56fe2f23d95df946c87209a5d08b94a | |
parent | c8e9abff53d869f74211e157abcb2827d181e106 (diff) | |
download | dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.tar dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.tar.gz dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.tar.bz2 dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.tar.lz dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.tar.xz dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.tar.zst dexon-2e3a6e2559d02ba90957eaf333e571dec935e00a.zip |
Consolidate related items
-rw-r--r-- | rpc/api.go | 73 |
1 files 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) -} |