diff options
| author | Wladimir J. van der Laan <[email protected]> | 2014-05-06 16:34:31 +0200 |
|---|---|---|
| committer | Wladimir J. van der Laan <[email protected]> | 2014-05-06 16:36:55 +0200 |
| commit | acc2d2ca5f7dadcf9807ed1bfcac6c010fe3649d (patch) | |
| tree | 0a60cf794c0f9568b9ced1797c137b2878819c51 /src/rpcblockchain.cpp | |
| parent | qt: periodic translations update (diff) | |
| parent | rpc: add `getblockchaininfo` and `getnetworkinfo` (diff) | |
| download | discoin-acc2d2ca5f7dadcf9807ed1bfcac6c010fe3649d.tar.xz discoin-acc2d2ca5f7dadcf9807ed1bfcac6c010fe3649d.zip | |
Merge pull request #4127
d387b8e rpc: add `getblockchaininfo` and `getnetworkinfo` (Wladimir J. van der Laan)
Diffstat (limited to 'src/rpcblockchain.cpp')
| -rw-r--r-- | src/rpcblockchain.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 78a92ce1e..1ed8a8e86 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -6,6 +6,7 @@ #include "rpcserver.h" #include "main.h" #include "sync.h" +#include "checkpoints.h" #include <stdint.h> @@ -429,3 +430,38 @@ Value verifychain(const Array& params, bool fHelp) return VerifyDB(nCheckLevel, nCheckDepth); } +Value getblockchaininfo(const Array& params, bool fHelp) +{ + if (fHelp || params.size() != 0) + throw runtime_error( + "getblockchaininfo\n" + "Returns an object containing various state info regarding block chain processing.\n" + "\nResult:\n" + "{\n" + " \"chain\": \"xxxx\", (string) current chain (main, testnet3, regtest)\n" + " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" + " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n" + " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" + " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" + " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" + "}\n" + "\nExamples:\n" + + HelpExampleCli("getblockchaininfo", "") + + HelpExampleRpc("getblockchaininfo", "") + ); + + proxyType proxy; + GetProxy(NET_IPV4, proxy); + + Object obj; + std::string chain = Params().DataDir(); + if(chain.empty()) + chain = "main"; + obj.push_back(Pair("chain", chain)); + obj.push_back(Pair("blocks", (int)chainActive.Height())); + obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex())); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); + obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip()))); + obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex())); + return obj; +} |