diff options
author | Péter Szilágyi <peterke@gmail.com> | 2015-09-10 00:02:54 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2015-09-15 19:45:53 +0800 |
commit | 0a7d059b6a4365c671386855289bfdc3178e2d60 (patch) | |
tree | 41a01bf186506d820f652fa7b5c2bebb081ea999 /rpc/api | |
parent | 071e2cd08e5492b5f4bae4f7dda03c5d47a0cd1d (diff) | |
download | go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.tar go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.tar.gz go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.tar.bz2 go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.tar.lz go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.tar.xz go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.tar.zst go-tangerine-0a7d059b6a4365c671386855289bfdc3178e2d60.zip |
eth, rpc: standardize the chain sync progress counters
Diffstat (limited to 'rpc/api')
-rw-r--r-- | rpc/api/admin.go | 12 | ||||
-rw-r--r-- | rpc/api/admin_js.go | 4 | ||||
-rw-r--r-- | rpc/api/eth.go | 15 | ||||
-rw-r--r-- | rpc/api/eth_js.go | 4 | ||||
-rw-r--r-- | rpc/api/utils.go | 2 |
5 files changed, 20 insertions, 17 deletions
diff --git a/rpc/api/admin.go b/rpc/api/admin.go index 5e392ae32..8af69b189 100644 --- a/rpc/api/admin.go +++ b/rpc/api/admin.go @@ -55,7 +55,6 @@ var ( "admin_exportChain": (*adminApi).ExportChain, "admin_importChain": (*adminApi).ImportChain, "admin_verbosity": (*adminApi).Verbosity, - "admin_chainSyncStatus": (*adminApi).ChainSyncStatus, "admin_setSolc": (*adminApi).SetSolc, "admin_datadir": (*adminApi).DataDir, "admin_startRPC": (*adminApi).StartRPC, @@ -232,17 +231,6 @@ func (self *adminApi) Verbosity(req *shared.Request) (interface{}, error) { return true, nil } -func (self *adminApi) ChainSyncStatus(req *shared.Request) (interface{}, error) { - pending, cached, importing, estimate := self.ethereum.Downloader().Stats() - - return map[string]interface{}{ - "blocksAvailable": pending, - "blocksWaitingForImport": cached, - "importing": importing, - "estimate": estimate.String(), - }, nil -} - func (self *adminApi) SetSolc(req *shared.Request) (interface{}, error) { args := new(SetSolcArgs) if err := self.coder.Decode(req.Params, &args); err != nil { diff --git a/rpc/api/admin_js.go b/rpc/api/admin_js.go index 25dbb4a8d..413ea8d47 100644 --- a/rpc/api/admin_js.go +++ b/rpc/api/admin_js.go @@ -143,10 +143,6 @@ web3._extend({ new web3._extend.Property({ name: 'datadir', getter: 'admin_datadir' - }), - new web3._extend.Property({ - name: 'chainSyncStatus', - getter: 'admin_chainSyncStatus' }) ] }); diff --git a/rpc/api/eth.go b/rpc/api/eth.go index a93e41157..9680536c6 100644 --- a/rpc/api/eth.go +++ b/rpc/api/eth.go @@ -55,6 +55,7 @@ var ( "eth_protocolVersion": (*ethApi).ProtocolVersion, "eth_coinbase": (*ethApi).Coinbase, "eth_mining": (*ethApi).IsMining, + "eth_syncing": (*ethApi).IsSyncing, "eth_gasPrice": (*ethApi).GasPrice, "eth_getStorage": (*ethApi).GetStorage, "eth_storageAt": (*ethApi).GetStorage, @@ -166,6 +167,20 @@ func (self *ethApi) IsMining(req *shared.Request) (interface{}, error) { return self.xeth.IsMining(), nil } +func (self *ethApi) IsSyncing(req *shared.Request) (interface{}, error) { + current := self.ethereum.ChainManager().CurrentBlock().NumberU64() + origin, height := self.ethereum.Downloader().Boundaries() + + if current < height { + return map[string]interface{}{ + "startingBlock": origin, + "currentBlock": current, + "highestBlock": height, + }, nil + } + return false, nil +} + func (self *ethApi) GasPrice(req *shared.Request) (interface{}, error) { return newHexNum(self.xeth.DefaultGasPrice().Bytes()), nil } diff --git a/rpc/api/eth_js.go b/rpc/api/eth_js.go index 393dac22f..81bb341bf 100644 --- a/rpc/api/eth_js.go +++ b/rpc/api/eth_js.go @@ -42,6 +42,10 @@ web3._extend({ new web3._extend.Property({ name: 'pendingTransactions', getter: 'eth_pendingTransactions' + }), + new web3._extend.Property({ + name: 'syncing', + getter: 'eth_syncing' }) ] }); diff --git a/rpc/api/utils.go b/rpc/api/utils.go index 5072dc2cd..76b2c531d 100644 --- a/rpc/api/utils.go +++ b/rpc/api/utils.go @@ -32,7 +32,6 @@ var ( AutoCompletion = map[string][]string{ "admin": []string{ "addPeer", - "chainSyncStatus", "datadir", "exportChain", "getContractInfo", @@ -99,6 +98,7 @@ var ( "sendRawTransaction", "sendTransaction", "sign", + "syncing", }, "miner": []string{ "hashrate", |