39 #include <boost/thread/thread.hpp> 42 #include <condition_variable> 50 static std::mutex cs_blockchange;
51 static std::condition_variable cond_blockchange;
58 if (blockindex ==
nullptr)
66 int nShift = (blockindex->
nBits >> 24) & 0xff;
69 (double)0x0000ffff / (
double)(blockindex->
nBits & 0x00ffffff);
89 int confirmations = -1;
93 result.
push_back(Pair(
"confirmations", confirmations));
105 if (blockindex->
pprev)
117 int confirmations = -1;
124 result.
push_back(Pair(
"confirmations", confirmations));
132 for (
unsigned int i = 0; i < block.
vtx.size(); i++) {
144 for (
size_t j = 0; j < tx.
vin.size(); j++) {
177 for (
unsigned int k = 0; k < tx.
vout.size(); k++) {
199 entry.
push_back(Pair(
"outputs", outputs));
203 result.
push_back(Pair(
"deltas", deltas));
211 if (blockindex->
pprev)
223 int confirmations = -1;
227 result.
push_back(Pair(
"confirmations", confirmations));
230 result.
push_back(Pair(
"weight", (
int)::GetBlockWeight(block)));
236 for(
const auto& tx : block.
vtx)
255 if (blockindex->
pprev)
266 throw std::runtime_error(
268 "\nReturns the number of blocks in the longest blockchain.\n" 270 "n (numeric) The current block count\n" 283 throw std::runtime_error(
285 "\nReturns the hash of the best (tip) block in the longest blockchain.\n" 287 "\"hex\" (string) the block hash hex encoded\n" 300 std::lock_guard<std::mutex> lock(cs_blockchange);
304 cond_blockchange.notify_all();
310 throw std::runtime_error(
311 "waitfornewblock (timeout)\n" 312 "\nWaits for a specific new block and returns useful info about it.\n" 313 "\nReturns the current block on timeout or exit.\n" 315 "1. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n" 318 " \"hash\" : { (string) The blockhash\n" 319 " \"height\" : { (int) Block height\n" 331 std::unique_lock<std::mutex> lock(cs_blockchange);
334 cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]{
return latestblock.
height != block.
height || latestblock.
hash != block.
hash || !
IsRPCRunning(); });
348 throw std::runtime_error(
349 "waitforblock <blockhash> (timeout)\n" 350 "\nWaits for a specific new block and returns useful info about it.\n" 351 "\nReturns the current block on timeout or exit.\n" 353 "1. \"blockhash\" (required, string) Block hash to wait for.\n" 354 "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n" 357 " \"hash\" : { (string) The blockhash\n" 358 " \"height\" : { (int) Block height\n" 361 +
HelpExampleCli(
"waitforblock",
"\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
362 +
HelpExampleRpc(
"waitforblock",
"\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
373 std::unique_lock<std::mutex> lock(cs_blockchange);
375 cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&hash]{
return latestblock.
hash == hash || !
IsRPCRunning();});
377 cond_blockchange.wait(lock, [&hash]{
return latestblock.
hash == hash || !
IsRPCRunning(); });
390 throw std::runtime_error(
391 "waitforblockheight <height> (timeout)\n" 392 "\nWaits for (at least) block height and returns the height and hash\n" 393 "of the current tip.\n" 394 "\nReturns the current block on timeout or exit.\n" 396 "1. height (required, int) Block height to wait for (int)\n" 397 "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n" 400 " \"hash\" : { (string) The blockhash\n" 401 " \"height\" : { (int) Block height\n" 416 std::unique_lock<std::mutex> lock(cs_blockchange);
418 cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]{
return latestblock.
height >= height || !
IsRPCRunning();});
420 cond_blockchange.wait(lock, [&height]{
return latestblock.
height >= height || !
IsRPCRunning(); });
432 throw std::runtime_error(
434 "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n" 436 "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n" 448 return " \"size\" : n, (numeric) virtual transaction size as defined in BIP 141. This is different from actual serialized size for witness transactions as witness data is discounted.\n" 449 " \"fee\" : n, (numeric) transaction fee in " +
CURRENCY_UNIT +
"\n" 450 " \"modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority\n" 451 " \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n" 452 " \"height\" : n, (numeric) block height when transaction entered pool\n" 453 " \"descendantcount\" : n, (numeric) number of in-mempool descendant transactions (including this one)\n" 454 " \"descendantsize\" : n, (numeric) virtual transaction size of in-mempool descendants (including this one)\n" 455 " \"descendantfees\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one)\n" 456 " \"ancestorcount\" : n, (numeric) number of in-mempool ancestor transactions (including this one)\n" 457 " \"ancestorsize\" : n, (numeric) virtual transaction size of in-mempool ancestors (including this one)\n" 458 " \"ancestorfees\" : n, (numeric) modified fees (see above) of in-mempool ancestors (including this one)\n" 459 " \"wtxid\" : hash, (string) hash of serialized transaction, including witness data\n" 460 " \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n" 461 " \"transactionid\", (string) parent transaction id\n" 482 std::set<std::string> setDepends;
490 for (
const std::string& dep : setDepends)
495 info.
push_back(Pair(
"depends", depends));
515 std::vector<uint256> vtxid;
529 throw std::runtime_error(
530 "getrawmempool ( verbose )\n" 531 "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n" 532 "\nHint: use getmempoolentry to fetch a specific transaction from the mempool.\n" 534 "1. verbose (boolean, optional, default=false) True for a json object, false for array of transaction ids\n" 535 "\nResult: (for verbose = false):\n" 536 "[ (json array of string)\n" 537 " \"transactionid\" (string) The transaction id\n" 540 "\nResult: (for verbose = true):\n" 542 " \"transactionid\" : { (json object)\n" 551 bool fVerbose =
false;
561 throw std::runtime_error(
562 "getmempoolancestors txid (verbose)\n" 563 "\nIf txid is in the mempool, returns all in-mempool ancestors.\n" 565 "1. \"txid\" (string, required) The transaction id (must be in mempool)\n" 566 "2. verbose (boolean, optional, default=false) True for a json object, false for array of transaction ids\n" 567 "\nResult (for verbose=false):\n" 568 "[ (json array of strings)\n" 569 " \"transactionid\" (string) The transaction id of an in-mempool ancestor transaction\n" 572 "\nResult (for verbose=true):\n" 574 " \"transactionid\" : { (json object)\n" 584 bool fVerbose =
false;
598 uint64_t noLimit = std::numeric_limits<uint64_t>::max();
605 o.
push_back(ancestorIt->GetTx().GetHash().ToString());
625 throw std::runtime_error(
626 "getmempooldescendants txid (verbose)\n" 627 "\nIf txid is in the mempool, returns all in-mempool descendants.\n" 629 "1. \"txid\" (string, required) The transaction id (must be in mempool)\n" 630 "2. verbose (boolean, optional, default=false) True for a json object, false for array of transaction ids\n" 631 "\nResult (for verbose=false):\n" 632 "[ (json array of strings)\n" 633 " \"transactionid\" (string) The transaction id of an in-mempool descendant transaction\n" 636 "\nResult (for verbose=true):\n" 638 " \"transactionid\" : { (json object)\n" 648 bool fVerbose =
false;
664 setDescendants.erase(it);
669 o.
push_back(descendantIt->GetTx().GetHash().ToString());
689 throw std::runtime_error(
690 "getmempoolentry txid\n" 691 "\nReturns mempool data for given transaction\n" 693 "1. \"txid\" (string, required) The transaction id (must be in mempool)\n" 722 throw std::runtime_error(
"");
745 throw std::runtime_error(
746 "getblockhashes timestamp\n" 747 "\nReturns array of hashes of blocks within the timestamp range provided.\n" 749 "1. high (numeric, required) The newer block timestamp\n" 750 "2. low (numeric, required) The older block timestamp\n" 751 "3. options (string, required) A json object\n" 753 " \"noOrphans\":true (boolean) will only include blocks on the main chain\n" 754 " \"logicalTimes\":true (boolean) will include logical timestamps with hashes\n" 758 " \"hash\" (string) The block hash\n" 762 " \"blockhash\": (string) The block hash\n" 763 " \"logicalts\": (numeric) The logical timestamp\n" 769 +
HelpExampleCli(
"getblockhashes",
"1231614698 1231024505 '{\"noOrphans\":false, \"logicalTimes\":true}'")
774 bool fActiveOnly =
false;
775 bool fLogicalTS =
false;
785 if (returnLogical.isBool())
786 fLogicalTS = returnLogical.get_bool();
790 std::vector<std::pair<uint256, unsigned int> > blockHashes;
801 for (std::vector<std::pair<uint256, unsigned int> >::const_iterator it=blockHashes.begin(); it!=blockHashes.end(); it++) {
804 item.
push_back(Pair(
"blockhash", it->first.GetHex()));
805 item.
push_back(Pair(
"logicalts", (
int)it->second));
818 throw std::runtime_error(
819 "getblockhash height\n" 820 "\nReturns hash of block in best-block-chain at height provided.\n" 822 "1. height (numeric, required) The height index\n" 824 "\"hash\" (string) The block hash\n" 843 throw std::runtime_error(
844 "getblockheader \"hash\" ( verbose )\n" 845 "\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n" 846 "If verbose is true, returns an Object with information about blockheader <hash>.\n" 848 "1. \"hash\" (string, required) The block hash\n" 849 "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n" 850 "\nResult (for verbose = true):\n" 852 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n" 853 " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" 854 " \"height\" : n, (numeric) The block height or index\n" 855 " \"version\" : n, (numeric) The block version\n" 856 " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n" 857 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" 858 " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" 859 " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" 860 " \"nonce\" : n, (numeric) The nonce\n" 861 " \"bits\" : \"1d00ffff\", (string) The bits\n" 862 " \"difficulty\" : x.xxx, (numeric) The difficulty\n" 863 " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n" 864 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" 865 " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n" 867 "\nResult (for verbose=false):\n" 868 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" 870 +
HelpExampleCli(
"getblockheader",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
871 +
HelpExampleRpc(
"getblockheader",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
879 bool fVerbose =
true;
902 throw std::runtime_error(
903 "getblock \"blockhash\" ( verbosity ) \n" 904 "\nIf verbosity is 0, returns a string that is serialized, hex-encoded data for block 'hash'.\n" 905 "If verbosity is 1, returns an Object with information about block <hash>.\n" 906 "If verbosity is 2, returns an Object with information about block <hash> and information about each transaction. \n" 908 "1. \"blockhash\" (string, required) The block hash\n" 909 "2. verbosity (numeric, optional, default=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data\n" 910 "\nResult (for verbosity = 0):\n" 911 "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n" 912 "\nResult (for verbosity = 1):\n" 914 " \"hash\" : \"hash\", (string) the block hash (same as provided)\n" 915 " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n" 916 " \"size\" : n, (numeric) The block size\n" 917 " \"strippedsize\" : n, (numeric) The block size excluding witness data\n" 918 " \"weight\" : n (numeric) The block weight as defined in BIP 141\n" 919 " \"height\" : n, (numeric) The block height or index\n" 920 " \"version\" : n, (numeric) The block version\n" 921 " \"versionHex\" : \"00000000\", (string) The block version formatted in hexadecimal\n" 922 " \"merkleroot\" : \"xxxx\", (string) The merkle root\n" 923 " \"tx\" : [ (array of string) The transaction ids\n" 924 " \"transactionid\" (string) The transaction id\n" 927 " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n" 928 " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n" 929 " \"nonce\" : n, (numeric) The nonce\n" 930 " \"bits\" : \"1d00ffff\", (string) The bits\n" 931 " \"difficulty\" : x.xxx, (numeric) The difficulty\n" 932 " \"chainwork\" : \"xxxx\", (string) Expected number of hashes required to produce the chain up to this block (in hex)\n" 933 " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n" 934 " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n" 936 "\nResult (for verbosity = 2):\n" 938 " ..., Same output as verbosity = 1.\n" 939 " \"tx\" : [ (array of Objects) The transactions in the format of the getrawtransaction RPC. Different from verbosity = 1 \"tx\" result.\n" 942 " ,... Same output as verbosity = 1.\n" 945 +
HelpExampleCli(
"getblock",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
946 +
HelpExampleRpc(
"getblock",
"\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
987 return blockToJSON(block, pblockindex, verbosity >= 2);
1001 CCoinsStats() : nHeight(0), nTransactions(0), nTransactionOutputs(0), nBogoSize(0), nDiskSize(0), nTotalAmount(0) {}
1006 assert(!outputs.empty());
1008 ss <<
VARINT(outputs.begin()->second.nHeight * 2 + outputs.begin()->second.fCoinBase);
1010 for (
const auto output : outputs) {
1011 ss <<
VARINT(output.first + 1);
1012 ss << output.second.out.scriptPubKey;
1013 ss <<
VARINT(output.second.out.nValue);
1017 2 + output.second.out.scriptPubKey.size() ;
1025 std::unique_ptr<CCoinsViewCursor> pcursor(view->
Cursor());
1029 stats.
hashBlock = pcursor->GetBestBlock();
1036 std::map<uint32_t, Coin> outputs;
1037 while (pcursor->Valid()) {
1038 boost::this_thread::interruption_point();
1041 if (pcursor->GetKey(key) && pcursor->GetValue(coin)) {
1042 if (!outputs.empty() && key.
hash != prevkey) {
1043 ApplyStats(stats, ss, prevkey, outputs);
1047 outputs[key.
n] = std::move(coin);
1049 return error(
"%s: unable to read value", __func__);
1053 if (!outputs.empty()) {
1054 ApplyStats(stats, ss, prevkey, outputs);
1064 throw std::runtime_error(
1067 "1. \"height\" (numeric, required) The block height to prune up to. May be set to a discrete height, or a unix timestamp\n" 1068 " to prune blocks whose block time is at least 2 hours older than the provided timestamp.\n" 1070 "n (numeric) Height of the last block pruned.\n" 1081 if (heightParam < 0)
1086 if (heightParam > 1000000000) {
1092 heightParam = pindex->
nHeight;
1095 unsigned int height = (
unsigned int) heightParam;
1097 if (chainHeight <
Params().PruneAfterHeight())
1099 else if (height > chainHeight)
1101 else if (height > chainHeight - MIN_BLOCKS_TO_KEEP) {
1102 LogPrint(
BCLog::RPC,
"Attempt to prune blocks close to the tip. Retaining the minimum number of blocks.");
1103 height = chainHeight - MIN_BLOCKS_TO_KEEP;
1107 return uint64_t(height);
1113 throw std::runtime_error(
1115 "\nReturns statistics about the unspent transaction output set.\n" 1116 "Note this call may take some time.\n" 1119 " \"height\":n, (numeric) The current block height (index)\n" 1120 " \"bestblock\": \"hex\", (string) the best block hash hex\n" 1121 " \"transactions\": n, (numeric) The number of transactions\n" 1122 " \"txouts\": n, (numeric) The number of output transactions\n" 1123 " \"bogosize\": n, (numeric) A meaningless metric for UTXO set size\n" 1124 " \"hash_serialized_2\": \"hash\", (string) The serialized hash\n" 1125 " \"disk_size\": n, (numeric) The estimated size of the chainstate on disk\n" 1126 " \"total_amount\": x.xxx (numeric) The total amount\n" 1155 throw std::runtime_error(
1156 "gettxout \"txid\" n ( include_mempool )\n" 1157 "\nReturns details about an unspent transaction output.\n" 1159 "1. \"txid\" (string, required) The transaction id\n" 1160 "2. \"n\" (numeric, required) vout number\n" 1161 "3. \"include_mempool\" (boolean, optional) Whether to include the mempool. Default: true." 1162 " Note that an unspent output that is spent in the mempool won't appear.\n" 1165 " \"bestblock\" : \"hash\", (string) the block hash\n" 1166 " \"confirmations\" : n, (numeric) The number of confirmations\n" 1167 " \"value\" : x.xxx, (numeric) The transaction value in " +
CURRENCY_UNIT +
"\n" 1168 " \"scriptPubKey\" : { (json object)\n" 1169 " \"asm\" : \"code\", (string) \n" 1170 " \"hex\" : \"hex\", (string) \n" 1171 " \"reqSigs\" : n, (numeric) Number of required signatures\n" 1172 " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n" 1173 " \"addresses\" : [ (array of string) array of raven addresses\n" 1174 " \"address\" (string) raven address\n" 1178 " \"coinbase\" : true|false (boolean) Coinbase or not\n" 1182 "\nGet unspent transactions\n" 1184 "\nView the details\n" 1186 "\nAs a json rpc call\n" 1198 bool fMempool =
true;
1218 if (coin.
nHeight == MEMPOOL_HEIGHT) {
1219 ret.
push_back(Pair(
"confirmations", 0));
1234 int nCheckLevel =
gArgs.
GetArg(
"-checklevel", DEFAULT_CHECKLEVEL);
1235 int nCheckDepth =
gArgs.
GetArg(
"-checkblocks", DEFAULT_CHECKBLOCKS);
1237 throw std::runtime_error(
1238 "verifychain ( checklevel nblocks )\n" 1239 "\nVerifies blockchain database.\n" 1241 "1. checklevel (numeric, optional, 0-4, default=" +
strprintf(
"%d", nCheckLevel) +
") How thorough the block verification is.\n" 1242 "2. nblocks (numeric, optional, default=" +
strprintf(
"%d", nCheckDepth) +
", 0=all) The number of blocks to check.\n" 1244 "true|false (boolean) Verified or not\n" 1294 switch (thresholdState) {
1317 rv.
push_back(Pair(
"statistics", statsUV));
1328 bip9_softforks.
push_back(Pair(name, BIP9SoftForkDesc(consensusParams,
id)));
1334 throw std::runtime_error(
1335 "getblockchaininfo\n" 1336 "Returns an object containing various state info regarding blockchain processing.\n" 1339 " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" 1340 " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n" 1341 " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n" 1342 " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n" 1343 " \"difficulty\": xxxxxx, (numeric) the current difficulty\n" 1344 " \"mediantime\": xxxxxx, (numeric) median time for the current best block\n" 1345 " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n" 1346 " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n" 1347 " \"size_on_disk\": xxxxxx, (numeric) the estimated size of the block and undo files on disk\n" 1348 " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n" 1349 " \"pruneheight\": xxxxxx, (numeric) lowest-height complete block stored (only present if pruning is enabled)\n" 1350 " \"automatic_pruning\": xx, (boolean) whether automatic pruning is enabled (only present if pruning is enabled)\n" 1351 " \"prune_target_size\": xxxxxx, (numeric) the target size used by pruning (only present if automatic pruning is enabled)\n" 1352 " \"softforks\": [ (array) status of softforks in progress\n" 1354 " \"id\": \"xxxx\", (string) name of softfork\n" 1355 " \"version\": xx, (numeric) block version\n" 1356 " \"reject\": { (object) progress toward rejecting pre-softfork blocks\n" 1357 " \"status\": xx, (boolean) true if threshold reached\n" 1361 " \"bip9_softforks\": { (object) status of BIP9 softforks in progress\n" 1362 " \"xxxx\" : { (string) name of the softfork\n" 1363 " \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"locked_in\", \"active\", \"failed\"\n" 1364 " \"bit\": xx, (numeric) the bit (0-28) in the block version field used to signal this softfork (only for \"started\" status)\n" 1365 " \"startTime\": xx, (numeric) the minimum median time past of a block at which the bit gains its meaning\n" 1366 " \"timeout\": xx, (numeric) the median time past of a block at which the deployment is considered failed if not yet locked in\n" 1367 " \"since\": xx, (numeric) height of the first block to which the status applies\n" 1368 " \"statistics\": { (object) numeric statistics about BIP9 signalling for a softfork (only for \"started\" status)\n" 1369 " \"period\": xx, (numeric) the length in blocks of the BIP9 signalling period \n" 1370 " \"threshold\": xx, (numeric) the number of blocks with the version bit set required to activate the feature \n" 1371 " \"elapsed\": xx, (numeric) the number of blocks elapsed since the beginning of the current period \n" 1372 " \"count\": xx, (numeric) the number of blocks with the version bit set in the current period \n" 1373 " \"possible\": xx (boolean) returns false if there are not enough blocks left in this period to pass activation threshold \n" 1377 " \"warnings\" : \"...\", (string) any network and blockchain warnings.\n" 1393 obj.
push_back(Pair(
"difficulty_algorithm",
"DGW-180"));
1395 obj.
push_back(Pair(
"difficulty_algorithm",
"BTC"));
1396 obj.
push_back(Pair(
"DGW_activation_height", (
int)
Params().DGWActivationBlock()));
1407 block = block->
pprev;
1413 bool automatic_pruning = (
gArgs.
GetArg(
"-prune", 0) != 1);
1414 obj.
push_back(Pair(
"automatic_pruning", automatic_pruning));
1415 if (automatic_pruning) {
1434 obj.
push_back(Pair(
"softforks", softforks));
1435 obj.
push_back(Pair(
"bip9_softforks", bip9_softforks));
1459 throw std::runtime_error(
1461 "Return information about all known tips in the block tree," 1462 " including the main chain as well as orphaned branches.\n" 1466 " \"height\": xxxx, (numeric) height of the chain tip\n" 1467 " \"hash\": \"xxxx\", (string) block hash of the tip\n" 1468 " \"branchlen\": 0 (numeric) zero for main chain\n" 1469 " \"status\": \"active\" (string) \"active\" for the main chain\n" 1472 " \"height\": xxxx,\n" 1473 " \"hash\": \"xxxx\",\n" 1474 " \"branchlen\": 1 (numeric) length of branch connecting the tip to the main chain\n" 1475 " \"status\": \"xxxx\" (string) status of the chain (active, valid-fork, valid-headers, headers-only, invalid)\n" 1478 "Possible values for status:\n" 1479 "1. \"invalid\" This branch contains at least one invalid block\n" 1480 "2. \"headers-only\" Not all blocks for this branch are available, but the headers are valid\n" 1481 "3. \"valid-headers\" All blocks are available for this branch, but they were never fully validated\n" 1482 "4. \"valid-fork\" This branch is not part of the active chain, but is fully validated\n" 1483 "5. \"active\" This is the tip of the active main chain, which is certainly valid\n" 1498 std::set<const CBlockIndex*, CompareBlocksByHeight> setTips;
1499 std::set<const CBlockIndex*> setOrphans;
1500 std::set<const CBlockIndex*> setPrevs;
1502 for (
const std::pair<const uint256, CBlockIndex*>& item :
mapBlockIndex)
1505 setOrphans.insert(item.second);
1506 setPrevs.insert(item.second->pprev);
1510 for (std::set<const CBlockIndex*>::iterator it = setOrphans.begin(); it != setOrphans.end(); ++it)
1512 if (setPrevs.erase(*it) == 0) {
1513 setTips.insert(*it);
1525 obj.
push_back(Pair(
"height", block->nHeight));
1526 obj.
push_back(Pair(
"hash", block->phashBlock->GetHex()));
1529 obj.
push_back(Pair(
"branchlen", branchLen));
1538 }
else if (block->nChainTx == 0) {
1540 status =
"headers-only";
1543 status =
"valid-fork";
1546 status =
"valid-headers";
1565 size_t maxmempool =
gArgs.
GetArg(
"-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
1566 ret.
push_back(Pair(
"maxmempool", (int64_t) maxmempool));
1575 throw std::runtime_error(
1577 "\nReturns details on the active state of the TX memory pool.\n" 1580 " \"size\": xxxxx, (numeric) Current tx count\n" 1581 " \"bytes\": xxxxx, (numeric) Sum of all virtual transaction sizes as defined in BIP 141. Differs from actual serialized size because witness data is discounted\n" 1582 " \"usage\": xxxxx, (numeric) Total memory usage for the mempool\n" 1583 " \"maxmempool\": xxxxx, (numeric) Maximum memory usage for the mempool\n" 1584 " \"mempoolminfee\": xxxxx (numeric) Minimum fee rate in " +
CURRENCY_UNIT +
"/kB for tx to be accepted\n" 1597 throw std::runtime_error(
1598 "preciousblock \"blockhash\"\n" 1599 "\nTreats a block as if it were received before others with the same work.\n" 1600 "\nA later preciousblock call can override the effect of an earlier one.\n" 1601 "\nThe effects of preciousblock are not retained across restarts.\n" 1603 "1. \"blockhash\" (string, required) the hash of the block to mark as precious\n" 1635 throw std::runtime_error(
1636 "invalidateblock \"blockhash\"\n" 1637 "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n" 1639 "1. \"blockhash\" (string, required) the hash of the block to mark as invalid\n" 1673 throw std::runtime_error(
1674 "reconsiderblock \"blockhash\"\n" 1675 "\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n" 1676 "This can be used to undo the effects of invalidateblock.\n" 1678 "1. \"blockhash\" (string, required) the hash of the block to reconsider\n" 1710 throw std::runtime_error(
1711 "getchaintxstats ( nblocks blockhash )\n" 1712 "\nCompute statistics about the total number and rate of transactions in the chain.\n" 1714 "1. nblocks (numeric, optional) Size of the window in number of blocks (default: one month).\n" 1715 "2. \"blockhash\" (string, optional) The hash of the block that ends the window.\n" 1718 " \"time\": xxxxx, (numeric) The timestamp for the final block in the window in UNIX format.\n" 1719 " \"txcount\": xxxxx, (numeric) The total number of transactions in the chain up to that point.\n" 1720 " \"window_block_count\": xxxxx, (numeric) Size of the window in number of blocks.\n" 1721 " \"window_tx_count\": xxxxx, (numeric) The number of transactions in the window. Only returned if \"window_block_count\" is > 0.\n" 1722 " \"window_interval\": xxxxx, (numeric) The elapsed time in the window in seconds. Only returned if \"window_block_count\" is > 0.\n" 1723 " \"txrate\": x.xx, (numeric) The average rate of transactions per second in the window. Only returned if \"window_interval\" is > 0.\n" 1746 pindex = it->second;
1755 assert(pindex !=
nullptr);
1758 blockcount = std::max(0, std::min(blockcount, pindex->
nHeight - 1));
1762 if (blockcount < 0 || (blockcount > 0 && blockcount >= pindex->
nHeight)) {
1774 ret.
push_back(Pair(
"window_block_count", blockcount));
1775 if (blockcount > 0) {
1776 ret.
push_back(Pair(
"window_tx_count", nTxDiff));
1777 ret.
push_back(Pair(
"window_interval", nTimeDiff));
1778 if (nTimeDiff > 0) {
1779 ret.
push_back(Pair(
"txrate", ((
double)nTxDiff) / nTimeDiff));
1789 throw std::runtime_error(
1791 "\nDumps the mempool to disk.\n" 1809 {
"blockchain",
"getchaintxstats", &
getchaintxstats, {
"nblocks",
"blockhash"} },
1812 {
"blockchain",
"getblock", &
getblock, {
"blockhash",
"verbosity|verbose"} },
1815 {
"blockchain",
"getblockhash", &
getblockhash, {
"height"} },
1816 {
"blockchain",
"getblockheader", &
getblockheader, {
"blockhash",
"verbose"} },
1823 {
"blockchain",
"getrawmempool", &
getrawmempool, {
"verbose"} },
1824 {
"blockchain",
"gettxout", &
gettxout, {
"txid",
"n",
"include_mempool"} },
1827 {
"blockchain",
"savemempool", &
savemempool, {} },
1828 {
"blockchain",
"verifychain", &
verifychain, {
"checklevel",
"nblocks"} },
1830 {
"blockchain",
"preciousblock", &
preciousblock, {
"blockhash"} },
1836 {
"hidden",
"waitforblock", &
waitforblock, {
"blockhash",
"timeout"} },
1842 for (
unsigned int vcidx = 0; vcidx <
ARRAYLEN(commands); vcidx++)
CAmount GetModFeesWithAncestors() const
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
size_t vTxHashesIdx
Index in mempool's vTxHashes.
uint64_t nTransactionOutputs
uint64_t GetSizeWithAncestors() const
bool fPruneMode
True if we're running in -prune mode.
bool DumpMempool(void)
Dump the mempool to disk.
UniValue getmempoolancestors(const JSONRPCRequest &request)
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, const bool fActiveOnly, std::vector< std::pair< uint256, unsigned int > > &hashes)
Raven RPC command dispatcher.
UniValue getblock(const JSONRPCRequest &request)
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
bool IsRPCRunning()
Query whether RPC is running.
UniValue getbestblockhash(const JSONRPCRequest &request)
UniValue reconsiderblock(const JSONRPCRequest &request)
UniValue blockToDeltasJSON(const CBlock &block, const CBlockIndex *blockindex)
bool IsPayToScriptHash() const
bool VerifyDB(const CChainParams &chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
Mark a block as invalid.
size_t DynamicMemoryUsage() const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
bool fHavePruned
Pruning-related variables and constants.
bool isSpent(const COutPoint &outpoint)
UniValue preciousblock(const JSONRPCRequest &request)
size_t GetSerializeSize(const T &t, int nType, int nVersion=0)
UniValue mempoolInfoToJSON()
Mempool information to JSON.
Comparison function for sorting the getchaintips heads.
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
CBlockHeader GetBlockHeader() const
int Height() const
Return the maximal height in the chain.
CCriticalSection cs_main
Global state.
CTxOut out
unspent transaction output
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
CAmount GetModFeesWithDescendants() const
unsigned int fCoinBase
whether containing transaction was a coinbase
uint64_t GetTotalTxSize() const
UniValue blockheaderToJSON(const CBlockIndex *blockindex)
Block header to JSON.
BIP9Stats VersionBitsTipStatistics(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the numerical statistics for the BIP9 state for a given deployment at the current tip...
uint64_t GetSizeWithDescendants() const
virtual CCoinsViewCursor * Cursor() const
Get a cursor to iterate over the whole state.
std::set< txiter, CompareIteratorByHash > setEntries
const std::string & get_str() const
void queryHashes(std::vector< uint256 > &vtxid)
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
const std::string CURRENCY_UNIT
Double ended buffer combining vector and stream-like interfaces.
double GetDifficulty(const CBlockIndex *blockindex)
Get the difficulty of the net wrt to the given block index, or the chain tip if not provided...
UniValue verifychain(const JSONRPCRequest &request)
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
UniValue ValueFromAmount(const CAmount &amount, const int8_t units)
UniValue getblockcount(const JSONRPCRequest &request)
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
bool appendCommand(const std::string &name, const CRPCCommand *pcmd)
Appends a CRPCCommand to the dispatch table.
UniValue waitfornewblock(const JSONRPCRequest &request)
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex)
Guess how far we are in the verification process at the given block index.
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block. ...
UniValue getchaintips(const JSONRPCRequest &request)
bool ActivateBestChain(CValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock)
Make the best chain active, in multiple steps.
UniValue getmempooldescendants(const JSONRPCRequest &request)
const std::vector< CTxIn > vin
Invalid, missing or duplicate parameter.
uint256 ParseHashV(const UniValue &v, std::string strName)
Utilities: convert hex-encoded Values (throws error if not hex).
ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
const UniValue & find_value(const UniValue &obj, const std::string &name)
UniValue waitforblock(const JSONRPCRequest &request)
CTxMemPoolEntry stores data about the corresponding transaction, as well as data about all in-mempool...
void entryToJSON(UniValue &info, const CTxMemPoolEntry &e)
std::string ToString() const
UniValue getblockdeltas(const JSONRPCRequest &request)
indexed_transaction_set mapTx
int64_t CAmount
Amount in corbies (Can be negative)
uint256 GetBlockHash() const
#define AssertLockHeld(cs)
uint32_t nHeight
at which height this containing transaction was included in the active block chain ...
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
std::vector< std::pair< uint256, txiter > > vTxHashes
All tx witness hashes/entries in mapTx, in random order.
bool push_back(const UniValue &val)
bool operator()(const CBlockIndex *a, const CBlockIndex *b) const
UniValue pruneblockchain(const JSONRPCRequest &request)
UniValue waitforblockheight(const JSONRPCRequest &request)
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry)
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
base58-encoded Raven addresses.
void RegisterBlockchainRPCCommands(CRPCTable &t)
Register block chain RPC commands.
Abstract view on the open txout dataset.
unsigned int GetHeight() const
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
An input of a transaction.
const uint256 & GetHash() const
const CAmount & GetFee() const
UniValue getmempoolinfo(const JSONRPCRequest &request)
bool IsDGWActive(unsigned int nBlockNumber)
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
uint256 uint256S(const char *str)
int64_t nStartTime
Start MedianTime for version bits miner confirmation.
CBlockIndex * FindEarliestAtLeast(int64_t nTime) const
Find the earliest block with timestamp equal or greater than the given.
void CalculateDescendants(txiter it, setEntries &setDescendants)
Populate setDescendants with all in-mempool descendants of hash.
int64_t nPowTargetSpacing
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip...
UniValue getdifficulty(const JSONRPCRequest &request)
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
std::string GetRejectReason() const
const std::vector< CTxOut > vout
UniValue getchaintxstats(const JSONRPCRequest &request)
UniValue gettxoutsetinfo(const JSONRPCRequest &request)
UniValue getblockhash(const JSONRPCRequest &request)
General application defined errors.
int VersionBitsTipStateSinceHeight(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the block height at which the BIP9 deployment switched into the state for the block building on t...
bool exists(uint256 hash) const
An output of a transaction.
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
bool CalculateMemPoolAncestors(const CTxMemPoolEntry &entry, setEntries &setAncestors, uint64_t limitAncestorCount, uint64_t limitAncestorSize, uint64_t limitDescendantCount, uint64_t limitDescendantSize, std::string &errString, bool fSearchForParents=true) const
Try to calculate all in-mempool ancestors of entry.
std::string ToString() const
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
UniValue getmempoolentry(const JSONRPCRequest &request)
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
Parameters that influence chain consensus.
An outpoint - a combination of a transaction hash and an index n into its vout.
UniValue getblockhashes(const JSONRPCRequest &request)
uint64_t GetCountWithDescendants() const
CFeeRate GetMinFee(size_t sizelimit) const
The minimum fee to get into the mempool, which may itself not be enough for larger-sized transactions...
UniValue gettxout(const JSONRPCRequest &request)
void BIP9SoftForkDescPushBack(UniValue &bip9_softforks, const std::string &name, const Consensus::Params &consensusParams, Consensus::DeploymentPos id)
int64_t GetMedianTimePast() const
indexed_transaction_set::nth_index< 0 >::type::iterator txiter
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
UniValue mempoolToJSON(bool fVerbose)
Mempool to JSON.
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
#define LogPrint(category,...)
uint64_t GetCountWithAncestors() const
int32_t nVersion
block header
int64_t nTimeout
Timeout/expiry MedianTime for the deployment attempt.
std::vector< CTransactionRef > vtx
UniValue invalidateblock(const JSONRPCRequest &request)
const_iterator end() const
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
const_iterator begin() const
bool ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
UniValue getrawmempool(const JSONRPCRequest &request)
UniValue savemempool(const JSONRPCRequest &request)
virtual size_t EstimateSize() const
Estimate database size (0 if not implemented)
The block chain is a tree shaped structure starting with the genesis block at the root...
const CChainParams & Params()
Return the currently selected parameters.
int RPCSerializationFlags()
const CTransaction & GetTx() const
const UniValue & get_obj() const
UniValue getblockchaininfo(const JSONRPCRequest &request)
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
int64_t GetModifiedFee() const
UniValue getblockheader(const JSONRPCRequest &request)
bool PreciousBlock(CValidationState &state, const CChainParams ¶ms, CBlockIndex *pindex)
Mark a block as precious and reorganize.
A reference to a CKey: the Hash160 of its serialized public key.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
std::string GetHex() const
const UniValue NullUniValue
bool error(const char *fmt, const Args &... args)
void ScriptPubKeyToUniv(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
A reference to a CScript: the Hash160 of its serialization (see script.h)
A writer stream (for serialization) that computes a 256-bit hash.
void RPCNotifyBlockChange(bool ibd, const CBlockIndex *pindex)
Callback for when block tip changed.
void TxToUniv(const CTransaction &tx, const uint256 &hashBlock, UniValue &entry, bool include_hex=true, int serialize_flags=0)
UniValue JSONRPCError(int code, const std::string &message)
std::string GetHex() const
The basic transaction that is broadcasted on the network and contained in blocks. ...
int nHeight
height of the entry in the chain. The genesis block has height 0
const Consensus::Params & GetConsensus() const
std::string EntryDescriptionString()
int bit
Bit position to select the particular bit in nVersion.
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
CCoinsViewDB * pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
full block available in blk*.dat
uint64_t CalculateCurrentUsage()
BLOCK PRUNING CODE.
UniValue blockToJSON(const CBlock &block, const CBlockIndex *blockindex, bool txDetails)
Block description to JSON.
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
CCoinsView that brings transactions from a memorypool into view.
bool IsPayToPublicKeyHash() const
CAmount GetFeePerK() const
Return the fee in satoshis for a size of 1000 bytes.
unsigned int nTx
Number of transactions in this block.
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]