diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index b51a78be0..11f498185 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -265,6 +265,7 @@ static const CRPCCommand vRPCCommands[] = { "gettxout", &gettxout, true, false }, { "lockunspent", &lockunspent, false, false }, { "listlockunspent", &listlockunspent, false, false }, + { "verifychain", &verifychain, true, false }, }; CRPCTable::CRPCTable() @@ -1192,6 +1193,8 @@ Array RPCConvertValues(const std::string &strMethod, const std::vector 0) ConvertTo(params[0]); if (strMethod == "lockunspent" && n > 1) ConvertTo(params[1]); if (strMethod == "importprivkey" && n > 2) ConvertTo(params[2]); + if (strMethod == "verifychain" && n > 0) ConvertTo(params[0]); + if (strMethod == "verifychain" && n > 1) ConvertTo(params[1]); return params; } diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 36ebb0689..27e8560f2 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -201,5 +201,6 @@ extern json_spirit::Value getblockhash(const json_spirit::Array& params, bool fH extern json_spirit::Value getblock(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxoutsetinfo(const json_spirit::Array& params, bool fHelp); extern json_spirit::Value gettxout(const json_spirit::Array& params, bool fHelp); +extern json_spirit::Value verifychain(const json_spirit::Array& params, bool fHelp); #endif diff --git a/src/main.cpp b/src/main.cpp index aa67acb63..03b6946ed 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2644,7 +2644,7 @@ bool VerifyDB(int nCheckLevel, int nCheckDepth) return true; // Verify blocks in the best chain - if (nCheckDepth == 0) + if (nCheckDepth <= 0) nCheckDepth = 1000000000; // suffices until the year 19000 if (nCheckDepth > nBestHeight) nCheckDepth = nBestHeight; diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index b6e962b89..9d58133df 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -251,4 +251,20 @@ Value gettxout(const Array& params, bool fHelp) return ret; } +Value verifychain(const Array& params, bool fHelp) +{ + if (fHelp || params.size() > 2) + throw runtime_error( + "verifychain [check level] [num blocks]\n" + "Verifies blockchain database."); + + int nCheckLevel = GetArg("-checklevel", 3); + int nCheckDepth = GetArg("-checkblocks", 288); + if (params.size() > 0) + nCheckLevel = params[0].get_int(); + if (params.size() > 1) + nCheckDepth = params[1].get_int(); + + return VerifyDB(nCheckLevel, nCheckDepth); +}