aboutsummaryrefslogtreecommitdiff
path: root/src/rpcblockchain.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpcblockchain.cpp')
-rw-r--r--src/rpcblockchain.cpp54
1 files changed, 43 insertions, 11 deletions
diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp
index 78a92ce1e..253693e62 100644
--- a/src/rpcblockchain.cpp
+++ b/src/rpcblockchain.cpp
@@ -3,8 +3,9 @@
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
-#include "rpcserver.h"
+#include "checkpoints.h"
#include "main.h"
+#include "rpcserver.h"
#include "sync.h"
#include <stdint.h>
@@ -63,9 +64,9 @@ Object blockToJSON(const CBlock& block, const CBlockIndex* blockindex)
BOOST_FOREACH(const CTransaction&tx, block.vtx)
txs.push_back(tx.GetHash().GetHex());
result.push_back(Pair("tx", txs));
- result.push_back(Pair("time", (boost::int64_t)block.GetBlockTime()));
- result.push_back(Pair("nonce", (boost::uint64_t)block.nNonce));
- result.push_back(Pair("bits", HexBits(block.nBits)));
+ result.push_back(Pair("time", block.GetBlockTime()));
+ result.push_back(Pair("nonce", (uint64_t)block.nNonce));
+ result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
@@ -174,7 +175,7 @@ Value getrawmempool(const Array& params, bool fHelp)
Object info;
info.push_back(Pair("size", (int)e.GetTxSize()));
info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
- info.push_back(Pair("time", (boost::int64_t)e.GetTime()));
+ info.push_back(Pair("time", e.GetTime()));
info.push_back(Pair("height", (int)e.GetHeight()));
info.push_back(Pair("startingpriority", e.GetPriority(e.GetHeight())));
info.push_back(Pair("currentpriority", e.GetPriority(chainActive.Height())));
@@ -275,7 +276,9 @@ Value getblock(const Array& params, bool fHelp)
CBlock block;
CBlockIndex* pblockindex = mapBlockIndex[hash];
- ReadBlockFromDisk(block, pblockindex);
+
+ if(!ReadBlockFromDisk(block, pblockindex))
+ throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
if (!fVerbose)
{
@@ -314,11 +317,11 @@ Value gettxoutsetinfo(const Array& params, bool fHelp)
CCoinsStats stats;
if (pcoinsTip->GetStats(stats)) {
- ret.push_back(Pair("height", (boost::int64_t)stats.nHeight));
+ ret.push_back(Pair("height", (int64_t)stats.nHeight));
ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
- ret.push_back(Pair("transactions", (boost::int64_t)stats.nTransactions));
- ret.push_back(Pair("txouts", (boost::int64_t)stats.nTransactionOutputs));
- ret.push_back(Pair("bytes_serialized", (boost::int64_t)stats.nSerializedSize));
+ ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));
+ ret.push_back(Pair("txouts", (int64_t)stats.nTransactionOutputs));
+ ret.push_back(Pair("bytes_serialized", (int64_t)stats.nSerializedSize));
ret.push_back(Pair("hash_serialized", stats.hashSerialized.GetHex()));
ret.push_back(Pair("total_amount", ValueFromAmount(stats.nTotalAmount)));
}
@@ -426,6 +429,35 @@ Value verifychain(const Array& params, bool fHelp)
if (params.size() > 1)
nCheckDepth = params[1].get_int();
- return VerifyDB(nCheckLevel, nCheckDepth);
+ return CVerifyDB().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 network name as defined in BIP70 (main, test, 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", "")
+ );
+
+ Object obj;
+ obj.push_back(Pair("chain", Params().NetworkIDString()));
+ 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;
+}