Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/blockchain.cpp
Show First 20 Lines • Show All 141 Lines • ▼ Show 20 Lines | UniValue blockToJSON(const Config &config, const CBlock &block, | ||||
} | } | ||||
CBlockIndex *pnext = chainActive.Next(blockindex); | CBlockIndex *pnext = chainActive.Next(blockindex); | ||||
if (pnext) { | if (pnext) { | ||||
result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | result.pushKV("nextblockhash", pnext->GetBlockHash().GetHex()); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
UniValue getblockcount(const Config &config, const JSONRPCRequest &request) { | static UniValue getblockcount(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getblockcount\n" | "getblockcount\n" | ||||
"\nReturns the number of blocks in the longest blockchain.\n" | "\nReturns the number of blocks in the longest blockchain.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"n (numeric) The current block count\n" | "n (numeric) The current block count\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getblockcount", "") + | HelpExampleCli("getblockcount", "") + | ||||
HelpExampleRpc("getblockcount", "")); | HelpExampleRpc("getblockcount", "")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return chainActive.Height(); | return chainActive.Height(); | ||||
} | } | ||||
UniValue getbestblockhash(const Config &config, const JSONRPCRequest &request) { | static UniValue getbestblockhash(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getbestblockhash\n" | "getbestblockhash\n" | ||||
"\nReturns the hash of the best (tip) block in the " | "\nReturns the hash of the best (tip) block in the " | ||||
"longest blockchain.\n" | "longest blockchain.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"hex\" (string) the block hash hex encoded\n" | "\"hex\" (string) the block hash hex encoded\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
Show All 27 Lines | void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex) { | ||||
if (pindex) { | if (pindex) { | ||||
std::lock_guard<std::mutex> lock(cs_blockchange); | std::lock_guard<std::mutex> lock(cs_blockchange); | ||||
latestblock.hash = pindex->GetBlockHash(); | latestblock.hash = pindex->GetBlockHash(); | ||||
latestblock.height = pindex->nHeight; | latestblock.height = pindex->nHeight; | ||||
} | } | ||||
cond_blockchange.notify_all(); | cond_blockchange.notify_all(); | ||||
} | } | ||||
UniValue waitfornewblock(const Config &config, const JSONRPCRequest &request) { | static UniValue waitfornewblock(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"waitfornewblock (timeout)\n" | "waitfornewblock (timeout)\n" | ||||
"\nWaits for a specific new block and returns " | "\nWaits for a specific new block and returns " | ||||
"useful info about it.\n" | "useful info about it.\n" | ||||
"\nReturns the current block on timeout or exit.\n" | "\nReturns the current block on timeout or exit.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. timeout (int, optional, default=0) Time in " | "1. timeout (int, optional, default=0) Time in " | ||||
Show All 33 Lines | CUpdatedBlock block; | ||||
block = latestblock; | block = latestblock; | ||||
} | } | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("hash", block.hash.GetHex()); | ret.pushKV("hash", block.hash.GetHex()); | ||||
ret.pushKV("height", block.height); | ret.pushKV("height", block.height); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue waitforblock(const Config &config, const JSONRPCRequest &request) { | static UniValue waitforblock(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"waitforblock <blockhash> (timeout)\n" | "waitforblock <blockhash> (timeout)\n" | ||||
"\nWaits for a specific new block and returns useful info about " | "\nWaits for a specific new block and returns useful info about " | ||||
"it.\n" | "it.\n" | ||||
"\nReturns the current block on timeout or exit.\n" | "\nReturns the current block on timeout or exit.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
Show All 39 Lines | static UniValue waitforblock(const Config &config, | ||||
} | } | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("hash", block.hash.GetHex()); | ret.pushKV("hash", block.hash.GetHex()); | ||||
ret.pushKV("height", block.height); | ret.pushKV("height", block.height); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue waitforblockheight(const Config &config, | static UniValue waitforblockheight(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"waitforblockheight <height> (timeout)\n" | "waitforblockheight <height> (timeout)\n" | ||||
"\nWaits for (at least) block height and returns the height and " | "\nWaits for (at least) block height and returns the height and " | ||||
"hash\n" | "hash\n" | ||||
"of the current tip.\n" | "of the current tip.\n" | ||||
"\nReturns the current block on timeout or exit.\n" | "\nReturns the current block on timeout or exit.\n" | ||||
Show All 35 Lines | CUpdatedBlock block; | ||||
block = latestblock; | block = latestblock; | ||||
} | } | ||||
UniValue ret(UniValue::VOBJ); | UniValue ret(UniValue::VOBJ); | ||||
ret.pushKV("hash", block.hash.GetHex()); | ret.pushKV("hash", block.hash.GetHex()); | ||||
ret.pushKV("height", block.height); | ret.pushKV("height", block.height); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue syncwithvalidationinterfacequeue(const Config &config, | static UniValue | ||||
syncwithvalidationinterfacequeue(const Config &config, | |||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"syncwithvalidationinterfacequeue\n" | "syncwithvalidationinterfacequeue\n" | ||||
"\nWaits for the validation interface queue to catch up on " | "\nWaits for the validation interface queue to catch up on " | ||||
"everything that was there when we entered this function.\n" | "everything that was there when we entered this function.\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("syncwithvalidationinterfacequeue", "") + | HelpExampleCli("syncwithvalidationinterfacequeue", "") + | ||||
HelpExampleRpc("syncwithvalidationinterfacequeue", "")); | HelpExampleRpc("syncwithvalidationinterfacequeue", "")); | ||||
} | } | ||||
SyncWithValidationInterfaceQueue(); | SyncWithValidationInterfaceQueue(); | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue getdifficulty(const Config &config, const JSONRPCRequest &request) { | static UniValue getdifficulty(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error("getdifficulty\n" | throw std::runtime_error("getdifficulty\n" | ||||
"\nReturns the proof-of-work difficulty as a " | "\nReturns the proof-of-work difficulty as a " | ||||
"multiple of the minimum difficulty.\n" | "multiple of the minimum difficulty.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"n.nnn (numeric) the proof-of-work " | "n.nnn (numeric) the proof-of-work " | ||||
"difficulty as a multiple of the minimum " | "difficulty as a multiple of the minimum " | ||||
"difficulty.\n" | "difficulty.\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getdifficulty", "") + | HelpExampleCli("getdifficulty", "") + | ||||
HelpExampleRpc("getdifficulty", "")); | HelpExampleRpc("getdifficulty", "")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GetDifficulty(chainActive.Tip()); | return GetDifficulty(chainActive.Tip()); | ||||
} | } | ||||
std::string EntryDescriptionString() { | static std::string EntryDescriptionString() { | ||||
return " \"size\" : n, (numeric) transaction size.\n" | return " \"size\" : n, (numeric) transaction size.\n" | ||||
" \"fee\" : n, (numeric) transaction fee in " + | " \"fee\" : n, (numeric) transaction fee in " + | ||||
CURRENCY_UNIT + | CURRENCY_UNIT + | ||||
"\n" | "\n" | ||||
" \"modifiedfee\" : n, (numeric) transaction fee with fee " | " \"modifiedfee\" : n, (numeric) transaction fee with fee " | ||||
"deltas used for mining priority\n" | "deltas used for mining priority\n" | ||||
" \"time\" : n, (numeric) local time transaction " | " \"time\" : n, (numeric) local time transaction " | ||||
"entered pool in seconds since 1 Jan 1970 GMT\n" | "entered pool in seconds since 1 Jan 1970 GMT\n" | ||||
Show All 16 Lines | return " \"size\" : n, (numeric) transaction size.\n" | ||||
" \"ancestorfees\" : n, (numeric) modified fees (see above) " | " \"ancestorfees\" : n, (numeric) modified fees (see above) " | ||||
"of in-mempool ancestors (including this one)\n" | "of in-mempool ancestors (including this one)\n" | ||||
" \"depends\" : [ (array) unconfirmed transactions " | " \"depends\" : [ (array) unconfirmed transactions " | ||||
"used as inputs for this transaction\n" | "used as inputs for this transaction\n" | ||||
" \"transactionid\", (string) parent transaction id\n" | " \"transactionid\", (string) parent transaction id\n" | ||||
" ... ]\n"; | " ... ]\n"; | ||||
} | } | ||||
void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) { | static void entryToJSON(UniValue &info, const CTxMemPoolEntry &e) { | ||||
AssertLockHeld(g_mempool.cs); | AssertLockHeld(g_mempool.cs); | ||||
info.pushKV("size", (int)e.GetTxSize()); | info.pushKV("size", (int)e.GetTxSize()); | ||||
info.pushKV("fee", ValueFromAmount(e.GetFee())); | info.pushKV("fee", ValueFromAmount(e.GetFee())); | ||||
info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); | info.pushKV("modifiedfee", ValueFromAmount(e.GetModifiedFee())); | ||||
info.pushKV("time", e.GetTime()); | info.pushKV("time", e.GetTime()); | ||||
info.pushKV("height", (int)e.GetHeight()); | info.pushKV("height", (int)e.GetHeight()); | ||||
info.pushKV("startingpriority", e.GetPriority(e.GetHeight())); | info.pushKV("startingpriority", e.GetPriority(e.GetHeight())); | ||||
Show All 39 Lines | if (fVerbose) { | ||||
for (const uint256 &txid : vtxids) { | for (const uint256 &txid : vtxids) { | ||||
a.push_back(txid.ToString()); | a.push_back(txid.ToString()); | ||||
} | } | ||||
return a; | return a; | ||||
} | } | ||||
} | } | ||||
UniValue getrawmempool(const Config &config, const JSONRPCRequest &request) { | static UniValue getrawmempool(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getrawmempool ( verbose )\n" | "getrawmempool ( verbose )\n" | ||||
"\nReturns all transaction ids in memory pool as a json array of " | "\nReturns all transaction ids in memory pool as a json array of " | ||||
"string transaction ids.\n" | "string transaction ids.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. verbose (boolean, optional, default=false) True for a json " | "1. verbose (boolean, optional, default=false) True for a json " | ||||
"object, false for array of transaction ids\n" | "object, false for array of transaction ids\n" | ||||
Show All 16 Lines | static UniValue getrawmempool(const Config &config, | ||||
bool fVerbose = false; | bool fVerbose = false; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
fVerbose = request.params[0].get_bool(); | fVerbose = request.params[0].get_bool(); | ||||
} | } | ||||
return mempoolToJSON(fVerbose); | return mempoolToJSON(fVerbose); | ||||
} | } | ||||
UniValue getmempoolancestors(const Config &config, | static UniValue getmempoolancestors(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolancestors txid (verbose)\n" | "getmempoolancestors txid (verbose)\n" | ||||
"\nIf txid is in the mempool, returns all in-mempool ancestors.\n" | "\nIf txid is in the mempool, returns all in-mempool ancestors.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id " | "1. \"txid\" (string, required) The transaction id " | ||||
"(must be in mempool)\n" | "(must be in mempool)\n" | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | if (!fVerbose) { | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
o.pushKV(_hash.ToString(), info); | o.pushKV(_hash.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
UniValue getmempooldescendants(const Config &config, | static UniValue getmempooldescendants(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempooldescendants txid (verbose)\n" | "getmempooldescendants txid (verbose)\n" | ||||
"\nIf txid is in the mempool, returns all in-mempool descendants.\n" | "\nIf txid is in the mempool, returns all in-mempool descendants.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id " | "1. \"txid\" (string, required) The transaction id " | ||||
"(must be in mempool)\n" | "(must be in mempool)\n" | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | if (!fVerbose) { | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
o.pushKV(_hash.ToString(), info); | o.pushKV(_hash.ToString(), info); | ||||
} | } | ||||
return o; | return o; | ||||
} | } | ||||
} | } | ||||
UniValue getmempoolentry(const Config &config, const JSONRPCRequest &request) { | static UniValue getmempoolentry(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolentry txid\n" | "getmempoolentry txid\n" | ||||
"\nReturns mempool data for given transaction\n" | "\nReturns mempool data for given transaction\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) " | "1. \"txid\" (string, required) " | ||||
"The transaction id (must be in mempool)\n" | "The transaction id (must be in mempool)\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
Show All 16 Lines | static UniValue getmempoolentry(const Config &config, | ||||
} | } | ||||
const CTxMemPoolEntry &e = *it; | const CTxMemPoolEntry &e = *it; | ||||
UniValue info(UniValue::VOBJ); | UniValue info(UniValue::VOBJ); | ||||
entryToJSON(info, e); | entryToJSON(info, e); | ||||
return info; | return info; | ||||
} | } | ||||
UniValue getblockhash(const Config &config, const JSONRPCRequest &request) { | static UniValue getblockhash(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getblockhash height\n" | "getblockhash height\n" | ||||
"\nReturns hash of block in best-block-chain at height provided.\n" | "\nReturns hash of block in best-block-chain at height provided.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. height (numeric, required) The height index\n" | "1. height (numeric, required) The height index\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\"hash\" (string) The block hash\n" | "\"hash\" (string) The block hash\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getblockhash", "1000") + | HelpExampleCli("getblockhash", "1000") + | ||||
HelpExampleRpc("getblockhash", "1000")); | HelpExampleRpc("getblockhash", "1000")); | ||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
int nHeight = request.params[0].get_int(); | int nHeight = request.params[0].get_int(); | ||||
if (nHeight < 0 || nHeight > chainActive.Height()) { | if (nHeight < 0 || nHeight > chainActive.Height()) { | ||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); | throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range"); | ||||
} | } | ||||
CBlockIndex *pblockindex = chainActive[nHeight]; | CBlockIndex *pblockindex = chainActive[nHeight]; | ||||
return pblockindex->GetBlockHash().GetHex(); | return pblockindex->GetBlockHash().GetHex(); | ||||
} | } | ||||
UniValue getblockheader(const Config &config, const JSONRPCRequest &request) { | static UniValue getblockheader(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getblockheader \"hash\" ( verbose )\n" | "getblockheader \"hash\" ( verbose )\n" | ||||
"\nIf verbose is false, returns a string that is serialized, " | "\nIf verbose is false, returns a string that is serialized, " | ||||
"hex-encoded data for blockheader 'hash'.\n" | "hex-encoded data for blockheader 'hash'.\n" | ||||
"If verbose is true, returns an Object with information about " | "If verbose is true, returns an Object with information about " | ||||
"blockheader <hash>.\n" | "blockheader <hash>.\n" | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | if (!fVerbose) { | ||||
ssBlock << pblockindex->GetBlockHeader(); | ssBlock << pblockindex->GetBlockHeader(); | ||||
std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); | std::string strHex = HexStr(ssBlock.begin(), ssBlock.end()); | ||||
return strHex; | return strHex; | ||||
} | } | ||||
return blockheaderToJSON(pblockindex); | return blockheaderToJSON(pblockindex); | ||||
} | } | ||||
UniValue getblock(const Config &config, const JSONRPCRequest &request) { | static UniValue getblock(const Config &config, const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getblock \"blockhash\" ( verbosity )\n" | "getblock \"blockhash\" ( verbosity )\n" | ||||
"\nIf verbosity is 0 or false, returns a string that is " | "\nIf verbosity is 0 or false, returns a string that is " | ||||
"serialized, hex-encoded data for block 'hash'.\n" | "serialized, hex-encoded data for block 'hash'.\n" | ||||
"If verbosity is 1 or true, returns an Object with information " | "If verbosity is 1 or true, returns an Object with information " | ||||
"about block <hash>.\n" | "about block <hash>.\n" | ||||
▲ Show 20 Lines • Show All 167 Lines • ▼ Show 20 Lines | static bool GetUTXOStats(CCoinsView *view, CCoinsStats &stats) { | ||||
if (!outputs.empty()) { | if (!outputs.empty()) { | ||||
ApplyStats(stats, ss, prevkey, outputs); | ApplyStats(stats, ss, prevkey, outputs); | ||||
} | } | ||||
stats.hashSerialized = ss.GetHash(); | stats.hashSerialized = ss.GetHash(); | ||||
stats.nDiskSize = view->EstimateSize(); | stats.nDiskSize = view->EstimateSize(); | ||||
return true; | return true; | ||||
} | } | ||||
UniValue pruneblockchain(const Config &config, const JSONRPCRequest &request) { | static UniValue pruneblockchain(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"pruneblockchain\n" | "pruneblockchain\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"height\" (numeric, required) The block height to prune " | "1. \"height\" (numeric, required) The block height to prune " | ||||
"up to. May be set to a discrete height, or a unix timestamp\n" | "up to. May be set to a discrete height, or a unix timestamp\n" | ||||
" to prune blocks whose block time is at least 2 " | " to prune blocks whose block time is at least 2 " | ||||
"hours older than the provided timestamp.\n" | "hours older than the provided timestamp.\n" | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | if (chainHeight < config.GetChainParams().PruneAfterHeight()) { | ||||
"Retaining the minimum number of blocks."); | "Retaining the minimum number of blocks."); | ||||
height = chainHeight - MIN_BLOCKS_TO_KEEP; | height = chainHeight - MIN_BLOCKS_TO_KEEP; | ||||
} | } | ||||
PruneBlockFilesManual(height); | PruneBlockFilesManual(height); | ||||
return uint64_t(height); | return uint64_t(height); | ||||
} | } | ||||
UniValue gettxoutsetinfo(const Config &config, const JSONRPCRequest &request) { | static UniValue gettxoutsetinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"gettxoutsetinfo\n" | "gettxoutsetinfo\n" | ||||
"\nReturns statistics about the unspent transaction output set.\n" | "\nReturns statistics about the unspent transaction output set.\n" | ||||
"Note this call may take some time.\n" | "Note this call may take some time.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{\n" | "{\n" | ||||
" \"height\":n, (numeric) The current block height (index)\n" | " \"height\":n, (numeric) The current block height (index)\n" | ||||
▲ Show 20 Lines • Show All 116 Lines • ▼ Show 20 Lines | UniValue gettxout(const Config &config, const JSONRPCRequest &request) { | ||||
UniValue o(UniValue::VOBJ); | UniValue o(UniValue::VOBJ); | ||||
ScriptPubKeyToUniv(coin.GetTxOut().scriptPubKey, o, true); | ScriptPubKeyToUniv(coin.GetTxOut().scriptPubKey, o, true); | ||||
ret.pushKV("scriptPubKey", o); | ret.pushKV("scriptPubKey", o); | ||||
ret.pushKV("coinbase", coin.IsCoinBase()); | ret.pushKV("coinbase", coin.IsCoinBase()); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue verifychain(const Config &config, const JSONRPCRequest &request) { | static UniValue verifychain(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
int nCheckLevel = gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL); | int nCheckLevel = gArgs.GetArg("-checklevel", DEFAULT_CHECKLEVEL); | ||||
int nCheckDepth = gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS); | int nCheckDepth = gArgs.GetArg("-checkblocks", DEFAULT_CHECKBLOCKS); | ||||
if (request.fHelp || request.params.size() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"verifychain ( checklevel nblocks )\n" | "verifychain ( checklevel nblocks )\n" | ||||
"\nVerifies blockchain database.\n" | "\nVerifies blockchain database.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. checklevel (numeric, optional, 0-4, default=" + | "1. checklevel (numeric, optional, 0-4, default=" + | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | bool operator()(const CBlockIndex *a, const CBlockIndex *b) const { | ||||
if (a->nHeight != b->nHeight) { | if (a->nHeight != b->nHeight) { | ||||
return (a->nHeight > b->nHeight); | return (a->nHeight > b->nHeight); | ||||
} | } | ||||
return a < b; | return a < b; | ||||
} | } | ||||
}; | }; | ||||
UniValue getchaintips(const Config &config, const JSONRPCRequest &request) { | static UniValue getchaintips(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getchaintips\n" | "getchaintips\n" | ||||
"Return information about all known tips in the block tree," | "Return information about all known tips in the block tree," | ||||
" including the main chain as well as orphaned branches.\n" | " including the main chain as well as orphaned branches.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"[\n" | "[\n" | ||||
" {\n" | " {\n" | ||||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Lines | size_t maxmempool = | ||||
gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | gArgs.GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000; | ||||
ret.pushKV("maxmempool", (int64_t)maxmempool); | ret.pushKV("maxmempool", (int64_t)maxmempool); | ||||
ret.pushKV("mempoolminfee", | ret.pushKV("mempoolminfee", | ||||
ValueFromAmount(g_mempool.GetMinFee(maxmempool).GetFeePerK())); | ValueFromAmount(g_mempool.GetMinFee(maxmempool).GetFeePerK())); | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue getmempoolinfo(const Config &config, const JSONRPCRequest &request) { | static UniValue getmempoolinfo(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getmempoolinfo\n" | "getmempoolinfo\n" | ||||
"\nReturns details on the active state of the TX memory pool.\n" | "\nReturns details on the active state of the TX memory pool.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"{\n" | "{\n" | ||||
" \"size\": xxxxx, (numeric) Current tx count\n" | " \"size\": xxxxx, (numeric) Current tx count\n" | ||||
" \"bytes\": xxxxx, (numeric) Transaction size.\n" | " \"bytes\": xxxxx, (numeric) Transaction size.\n" | ||||
" \"usage\": xxxxx, (numeric) Total memory usage for " | " \"usage\": xxxxx, (numeric) Total memory usage for " | ||||
"the mempool\n" | "the mempool\n" | ||||
" \"maxmempool\": xxxxx, (numeric) Maximum memory usage " | " \"maxmempool\": xxxxx, (numeric) Maximum memory usage " | ||||
"for the mempool\n" | "for the mempool\n" | ||||
" \"mempoolminfee\": xxxxx (numeric) Minimum fee for tx to " | " \"mempoolminfee\": xxxxx (numeric) Minimum fee for tx to " | ||||
"be accepted\n" | "be accepted\n" | ||||
"}\n" | "}\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("getmempoolinfo", "") + | HelpExampleCli("getmempoolinfo", "") + | ||||
HelpExampleRpc("getmempoolinfo", "")); | HelpExampleRpc("getmempoolinfo", "")); | ||||
} | } | ||||
return mempoolInfoToJSON(); | return mempoolInfoToJSON(); | ||||
} | } | ||||
UniValue preciousblock(const Config &config, const JSONRPCRequest &request) { | static UniValue preciousblock(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"preciousblock \"blockhash\"\n" | "preciousblock \"blockhash\"\n" | ||||
"\nTreats a block as if it were received before others with the " | "\nTreats a block as if it were received before others with the " | ||||
"same work.\n" | "same work.\n" | ||||
"\nA later preciousblock call can override the effect of an " | "\nA later preciousblock call can override the effect of an " | ||||
"earlier one.\n" | "earlier one.\n" | ||||
"\nThe effects of preciousblock are not retained across restarts.\n" | "\nThe effects of preciousblock are not retained across restarts.\n" | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | UniValue finalizeblock(const Config &config, const JSONRPCRequest &request) { | ||||
if (!state.IsValid()) { | if (!state.IsValid()) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue invalidateblock(const Config &config, const JSONRPCRequest &request) { | static UniValue invalidateblock(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"invalidateblock \"blockhash\"\n" | "invalidateblock \"blockhash\"\n" | ||||
"\nPermanently marks a block as invalid, as if it " | "\nPermanently marks a block as invalid, as if it " | ||||
"violated a consensus rule.\n" | "violated a consensus rule.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"blockhash\" (string, required) the hash of " | "1. \"blockhash\" (string, required) the hash of " | ||||
"the block to mark as invalid\n" | "the block to mark as invalid\n" | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | UniValue parkblock(const Config &config, const JSONRPCRequest &request) { | ||||
if (!state.IsValid()) { | if (!state.IsValid()) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue reconsiderblock(const Config &config, const JSONRPCRequest &request) { | static UniValue reconsiderblock(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"reconsiderblock \"blockhash\"\n" | "reconsiderblock \"blockhash\"\n" | ||||
"\nRemoves invalidity status of a block and its descendants, " | "\nRemoves invalidity status of a block and its descendants, " | ||||
"reconsider them for activation.\n" | "reconsider them for activation.\n" | ||||
"This can be used to undo the effects of invalidateblock.\n" | "This can be used to undo the effects of invalidateblock.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"blockhash\" (string, required) the hash of the block to " | "1. \"blockhash\" (string, required) the hash of the block to " | ||||
▲ Show 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | UniValue unparkblock(const Config &config, const JSONRPCRequest &request) { | ||||
if (!state.IsValid()) { | if (!state.IsValid()) { | ||||
throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | throw JSONRPCError(RPC_DATABASE_ERROR, state.GetRejectReason()); | ||||
} | } | ||||
return NullUniValue; | return NullUniValue; | ||||
} | } | ||||
UniValue getchaintxstats(const Config &config, const JSONRPCRequest &request) { | static UniValue getchaintxstats(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"getchaintxstats ( nblocks blockhash )\n" | "getchaintxstats ( nblocks blockhash )\n" | ||||
"\nCompute statistics about the total number and rate of " | "\nCompute statistics about the total number and rate of " | ||||
"transactions in the chain.\n" | "transactions in the chain.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. nblocks (numeric, optional) Size of the window in number " | "1. nblocks (numeric, optional) Size of the window in number " | ||||
"of blocks (default: one month).\n" | "of blocks (default: one month).\n" | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | if (blockcount > 0) { | ||||
if (nTimeDiff > 0) { | if (nTimeDiff > 0) { | ||||
ret.pushKV("txrate", double(nTxDiff) / nTimeDiff); | ret.pushKV("txrate", double(nTxDiff) / nTimeDiff); | ||||
} | } | ||||
} | } | ||||
return ret; | return ret; | ||||
} | } | ||||
UniValue savemempool(const Config &config, const JSONRPCRequest &request) { | static UniValue savemempool(const Config &config, | ||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error("savemempool\n" | throw std::runtime_error("savemempool\n" | ||||
"\nDumps the mempool to disk. It will fail " | "\nDumps the mempool to disk. It will fail " | ||||
"until the previous dump is fully loaded.\n" | "until the previous dump is fully loaded.\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("savemempool", "") + | HelpExampleCli("savemempool", "") + | ||||
HelpExampleRpc("savemempool", "")); | HelpExampleRpc("savemempool", "")); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |