From 0a7d059b6a4365c671386855289bfdc3178e2d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Wed, 9 Sep 2015 19:02:54 +0300 Subject: eth, rpc: standardize the chain sync progress counters --- rpc/api/eth.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'rpc/api/eth.go') 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 } -- cgit v1.2.3