aboutsummaryrefslogtreecommitdiff
path: root/src/rpcblockchain.cpp
diff options
context:
space:
mode:
authorWladimir J. van der Laan <laanwj@gmail.com>2014-05-05 13:22:28 +0200
committerWladimir J. van der Laan <laanwj@gmail.com>2014-05-06 09:34:54 +0200
commitd387b8ec15e553db9b9c370314ee359e981fb374 (patch)
tree9d1b3a161e60aff59f00ee0e9ad1fcc75ccd5056 /src/rpcblockchain.cpp
parentd4ffe4e425b5a3f6fe4ff0ce7297608dfe6c7417 (diff)
rpc: add `getblockchaininfo` and `getnetworkinfo`
Adds two new info query commands that take over information from hodge-podge `getinfo`. Also some new information is added: - `getblockchaininfo` - `chain`: (string) current chain (main, testnet3, regtest) - `verificationprogress: (numeric) estimated verification progress - `chainwork` - `getnetworkinfo` - `localaddresses`: (array) local addresses, from mapLocalHost (fixes #1734)
Diffstat (limited to 'src/rpcblockchain.cpp')
-rw-r--r--src/rpcblockchain.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
index 78a92ce1e9..1ed8a8e866 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;
+}