Dash Core  0.12.2.1
P2P Digital Currency
blockchain.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2017 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "amount.h"
8 #include "chain.h"
9 #include "chainparams.h"
10 #include "checkpoints.h"
11 #include "coins.h"
12 #include "consensus/validation.h"
13 #include "validation.h"
14 #include "policy/policy.h"
15 #include "primitives/transaction.h"
16 #include "rpc/server.h"
17 #include "streams.h"
18 #include "sync.h"
19 #include "txmempool.h"
20 #include "util.h"
21 #include "utilstrencodings.h"
22 
23 #include <stdint.h>
24 
25 #include <univalue.h>
26 
27 using namespace std;
28 
29 extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
30 void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
31 
32 double GetDifficulty(const CBlockIndex* blockindex)
33 {
34  // Floating point number that is a multiple of the minimum difficulty,
35  // minimum difficulty = 1.0.
36  if (blockindex == NULL)
37  {
38  if (chainActive.Tip() == NULL)
39  return 1.0;
40  else
41  blockindex = chainActive.Tip();
42  }
43 
44  int nShift = (blockindex->nBits >> 24) & 0xff;
45 
46  double dDiff =
47  (double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff);
48 
49  while (nShift < 29)
50  {
51  dDiff *= 256.0;
52  nShift++;
53  }
54  while (nShift > 29)
55  {
56  dDiff /= 256.0;
57  nShift--;
58  }
59 
60  return dDiff;
61 }
62 
64 {
66  result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
67  int confirmations = -1;
68  // Only report confirmations if the block is on the main chain
69  if (chainActive.Contains(blockindex))
70  confirmations = chainActive.Height() - blockindex->nHeight + 1;
71  result.push_back(Pair("confirmations", confirmations));
72  result.push_back(Pair("height", blockindex->nHeight));
73  result.push_back(Pair("version", blockindex->nVersion));
74  result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
75  result.push_back(Pair("time", (int64_t)blockindex->nTime));
76  result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
77  result.push_back(Pair("nonce", (uint64_t)blockindex->nNonce));
78  result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
79  result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
80  result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
81 
82  if (blockindex->pprev)
83  result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
84  CBlockIndex *pnext = chainActive.Next(blockindex);
85  if (pnext)
86  result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
87  return result;
88 }
89 
90 UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
91 {
93  result.push_back(Pair("hash", block.GetHash().GetHex()));
94  int confirmations = -1;
95  // Only report confirmations if the block is on the main chain
96  if (chainActive.Contains(blockindex))
97  confirmations = chainActive.Height() - blockindex->nHeight + 1;
98  result.push_back(Pair("confirmations", confirmations));
99  result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
100  result.push_back(Pair("height", blockindex->nHeight));
101  result.push_back(Pair("version", block.nVersion));
102  result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
104  BOOST_FOREACH(const CTransaction&tx, block.vtx)
105  {
106  if(txDetails)
107  {
108  UniValue objTx(UniValue::VOBJ);
109  TxToJSON(tx, uint256(), objTx);
110  txs.push_back(objTx);
111  }
112  else
113  txs.push_back(tx.GetHash().GetHex());
114  }
115  result.push_back(Pair("tx", txs));
116  result.push_back(Pair("time", block.GetBlockTime()));
117  result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
118  result.push_back(Pair("nonce", (uint64_t)block.nNonce));
119  result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
120  result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
121  result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
122 
123  if (blockindex->pprev)
124  result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
125  CBlockIndex *pnext = chainActive.Next(blockindex);
126  if (pnext)
127  result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
128  return result;
129 }
130 
131 UniValue getblockcount(const UniValue& params, bool fHelp)
132 {
133  if (fHelp || params.size() != 0)
134  throw runtime_error(
135  "getblockcount\n"
136  "\nReturns the number of blocks in the longest block chain.\n"
137  "\nResult:\n"
138  "n (numeric) The current block count\n"
139  "\nExamples:\n"
140  + HelpExampleCli("getblockcount", "")
141  + HelpExampleRpc("getblockcount", "")
142  );
143 
144  LOCK(cs_main);
145  return chainActive.Height();
146 }
147 
148 UniValue getbestblockhash(const UniValue& params, bool fHelp)
149 {
150  if (fHelp || params.size() != 0)
151  throw runtime_error(
152  "getbestblockhash\n"
153  "\nReturns the hash of the best (tip) block in the longest block chain.\n"
154  "\nResult\n"
155  "\"hex\" (string) the block hash hex encoded\n"
156  "\nExamples\n"
157  + HelpExampleCli("getbestblockhash", "")
158  + HelpExampleRpc("getbestblockhash", "")
159  );
160 
161  LOCK(cs_main);
162  return chainActive.Tip()->GetBlockHash().GetHex();
163 }
164 
165 UniValue getdifficulty(const UniValue& params, bool fHelp)
166 {
167  if (fHelp || params.size() != 0)
168  throw runtime_error(
169  "getdifficulty\n"
170  "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
171  "\nResult:\n"
172  "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
173  "\nExamples:\n"
174  + HelpExampleCli("getdifficulty", "")
175  + HelpExampleRpc("getdifficulty", "")
176  );
177 
178  LOCK(cs_main);
179  return GetDifficulty();
180 }
181 
182 UniValue mempoolToJSON(bool fVerbose = false)
183 {
184  if (fVerbose)
185  {
186  LOCK(mempool.cs);
188  BOOST_FOREACH(const CTxMemPoolEntry& e, mempool.mapTx)
189  {
190  const uint256& hash = e.GetTx().GetHash();
191  UniValue info(UniValue::VOBJ);
192  info.push_back(Pair("size", (int)e.GetTxSize()));
193  info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
194  info.push_back(Pair("modifiedfee", ValueFromAmount(e.GetModifiedFee())));
195  info.push_back(Pair("time", e.GetTime()));
196  info.push_back(Pair("height", (int)e.GetHeight()));
197  info.push_back(Pair("startingpriority", e.GetPriority(e.GetHeight())));
198  info.push_back(Pair("currentpriority", e.GetPriority(chainActive.Height())));
199  info.push_back(Pair("descendantcount", e.GetCountWithDescendants()));
200  info.push_back(Pair("descendantsize", e.GetSizeWithDescendants()));
201  info.push_back(Pair("descendantfees", e.GetModFeesWithDescendants()));
202  const CTransaction& tx = e.GetTx();
203  set<string> setDepends;
204  BOOST_FOREACH(const CTxIn& txin, tx.vin)
205  {
206  if (mempool.exists(txin.prevout.hash))
207  setDepends.insert(txin.prevout.hash.ToString());
208  }
209 
210  UniValue depends(UniValue::VARR);
211  BOOST_FOREACH(const string& dep, setDepends)
212  {
213  depends.push_back(dep);
214  }
215 
216  info.push_back(Pair("depends", depends));
217  o.push_back(Pair(hash.ToString(), info));
218  }
219  return o;
220  }
221  else
222  {
223  vector<uint256> vtxid;
224  mempool.queryHashes(vtxid);
225 
227  BOOST_FOREACH(const uint256& hash, vtxid)
228  a.push_back(hash.ToString());
229 
230  return a;
231  }
232 }
233 
234 UniValue getrawmempool(const UniValue& params, bool fHelp)
235 {
236  if (fHelp || params.size() > 1)
237  throw runtime_error(
238  "getrawmempool ( verbose )\n"
239  "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
240  "\nArguments:\n"
241  "1. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n"
242  "\nResult: (for verbose = false):\n"
243  "[ (json array of string)\n"
244  " \"transactionid\" (string) The transaction id\n"
245  " ,...\n"
246  "]\n"
247  "\nResult: (for verbose = true):\n"
248  "{ (json object)\n"
249  " \"transactionid\" : { (json object)\n"
250  " \"size\" : n, (numeric) transaction size in bytes\n"
251  " \"fee\" : n, (numeric) transaction fee in " + CURRENCY_UNIT + "\n"
252  " \"modifiedfee\" : n, (numeric) transaction fee with fee deltas used for mining priority\n"
253  " \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
254  " \"height\" : n, (numeric) block height when transaction entered pool\n"
255  " \"startingpriority\" : n, (numeric) priority when transaction entered pool\n"
256  " \"currentpriority\" : n, (numeric) transaction priority now\n"
257  " \"descendantcount\" : n, (numeric) number of in-mempool descendant transactions (including this one)\n"
258  " \"descendantsize\" : n, (numeric) size of in-mempool descendants (including this one)\n"
259  " \"descendantfees\" : n, (numeric) modified fees (see above) of in-mempool descendants (including this one)\n"
260  " \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
261  " \"transactionid\", (string) parent transaction id\n"
262  " ... ]\n"
263  " }, ...\n"
264  "}\n"
265  "\nExamples\n"
266  + HelpExampleCli("getrawmempool", "true")
267  + HelpExampleRpc("getrawmempool", "true")
268  );
269 
270  bool fVerbose = false;
271  if (params.size() > 0)
272  fVerbose = params[0].get_bool();
273 
274  return mempoolToJSON(fVerbose);
275 }
276 
277 UniValue getblockhashes(const UniValue& params, bool fHelp)
278 {
279  if (fHelp || params.size() != 2)
280  throw runtime_error(
281  "getblockhashes timestamp\n"
282  "\nReturns array of hashes of blocks within the timestamp range provided.\n"
283  "\nArguments:\n"
284  "1. high (numeric, required) The newer block timestamp\n"
285  "2. low (numeric, required) The older block timestamp\n"
286  "\nResult:\n"
287  "[\n"
288  " \"hash\" (string) The block hash\n"
289  "]\n"
290  "\nExamples:\n"
291  + HelpExampleCli("getblockhashes", "1231614698 1231024505")
292  + HelpExampleRpc("getblockhashes", "1231614698, 1231024505")
293  );
294 
295  unsigned int high = params[0].get_int();
296  unsigned int low = params[1].get_int();
297  std::vector<uint256> blockHashes;
298 
299  if (!GetTimestampIndex(high, low, blockHashes)) {
300  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "No information available for block hashes");
301  }
302 
304  for (std::vector<uint256>::const_iterator it=blockHashes.begin(); it!=blockHashes.end(); it++) {
305  result.push_back(it->GetHex());
306  }
307 
308  return result;
309 }
310 
311 UniValue getblockhash(const UniValue& params, bool fHelp)
312 {
313  if (fHelp || params.size() != 1)
314  throw runtime_error(
315  "getblockhash index\n"
316  "\nReturns hash of block in best-block-chain at index provided.\n"
317  "\nArguments:\n"
318  "1. index (numeric, required) The block index\n"
319  "\nResult:\n"
320  "\"hash\" (string) The block hash\n"
321  "\nExamples:\n"
322  + HelpExampleCli("getblockhash", "1000")
323  + HelpExampleRpc("getblockhash", "1000")
324  );
325 
326  LOCK(cs_main);
327 
328  int nHeight = params[0].get_int();
329  if (nHeight < 0 || nHeight > chainActive.Height())
330  throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
331 
332  CBlockIndex* pblockindex = chainActive[nHeight];
333  return pblockindex->GetBlockHash().GetHex();
334 }
335 
336 UniValue getblockheader(const UniValue& params, bool fHelp)
337 {
338  if (fHelp || params.size() < 1 || params.size() > 2)
339  throw runtime_error(
340  "getblockheader \"hash\" ( verbose )\n"
341  "\nIf verbose is false, returns a string that is serialized, hex-encoded data for blockheader 'hash'.\n"
342  "If verbose is true, returns an Object with information about blockheader <hash>.\n"
343  "\nArguments:\n"
344  "1. \"hash\" (string, required) The block hash\n"
345  "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
346  "\nResult (for verbose = true):\n"
347  "{\n"
348  " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
349  " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
350  " \"height\" : n, (numeric) The block height or index\n"
351  " \"version\" : n, (numeric) The block version\n"
352  " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
353  " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
354  " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
355  " \"nonce\" : n, (numeric) The nonce\n"
356  " \"bits\" : \"1d00ffff\", (string) The bits\n"
357  " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
358  " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
359  " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
360  " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n"
361  "}\n"
362  "\nResult (for verbose=false):\n"
363  "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
364  "\nExamples:\n"
365  + HelpExampleCli("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
366  + HelpExampleRpc("getblockheader", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\"")
367  );
368 
369  LOCK(cs_main);
370 
371  std::string strHash = params[0].get_str();
372  uint256 hash(uint256S(strHash));
373 
374  bool fVerbose = true;
375  if (params.size() > 1)
376  fVerbose = params[1].get_bool();
377 
378  if (mapBlockIndex.count(hash) == 0)
379  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
380 
381  CBlockIndex* pblockindex = mapBlockIndex[hash];
382 
383  if (!fVerbose)
384  {
386  ssBlock << pblockindex->GetBlockHeader();
387  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
388  return strHex;
389  }
390 
391  return blockheaderToJSON(pblockindex);
392 }
393 
394 UniValue getblockheaders(const UniValue& params, bool fHelp)
395 {
396  if (fHelp || params.size() < 1 || params.size() > 3)
397  throw runtime_error(
398  "getblockheaders \"hash\" ( count verbose )\n"
399  "\nReturns an array of items with information about <count> blockheaders starting from <hash>.\n"
400  "\nIf verbose is false, each item is a string that is serialized, hex-encoded data for a single blockheader.\n"
401  "If verbose is true, each item is an Object with information about a single blockheader.\n"
402  "\nArguments:\n"
403  "1. \"hash\" (string, required) The block hash\n"
404  "2. count (numeric, optional, default/max=" + strprintf("%s", MAX_HEADERS_RESULTS) +")\n"
405  "3. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
406  "\nResult (for verbose = true):\n"
407  "[ {\n"
408  " \"hash\" : \"hash\", (string) The block hash\n"
409  " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
410  " \"height\" : n, (numeric) The block height or index\n"
411  " \"version\" : n, (numeric) The block version\n"
412  " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
413  " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
414  " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
415  " \"nonce\" : n, (numeric) The nonce\n"
416  " \"bits\" : \"1d00ffff\", (string) The bits\n"
417  " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
418  " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
419  " \"nextblockhash\" : \"hash\", (string) The hash of the next block\n"
420  " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n"
421  "}, {\n"
422  " ...\n"
423  " },\n"
424  "...\n"
425  "]\n"
426  "\nResult (for verbose=false):\n"
427  "[\n"
428  " \"data\", (string) A string that is serialized, hex-encoded data for block header.\n"
429  " ...\n"
430  "]\n"
431  "\nExamples:\n"
432  + HelpExampleCli("getblockheaders", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 2000")
433  + HelpExampleRpc("getblockheaders", "\"00000000c937983704a73af28acdec37b049d214adbda81d7e2a3dd146f6ed09\" 2000")
434  );
435 
436  LOCK(cs_main);
437 
438  std::string strHash = params[0].get_str();
439  uint256 hash(uint256S(strHash));
440 
441  if (mapBlockIndex.count(hash) == 0)
442  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
443 
444  int nCount = MAX_HEADERS_RESULTS;
445  if (params.size() > 1)
446  nCount = params[1].get_int();
447 
448  if (nCount <= 0 || nCount > (int)MAX_HEADERS_RESULTS)
449  throw JSONRPCError(RPC_INVALID_PARAMETER, "Count is out of range");
450 
451  bool fVerbose = true;
452  if (params.size() > 2)
453  fVerbose = params[2].get_bool();
454 
455  CBlockIndex* pblockindex = mapBlockIndex[hash];
456 
457  UniValue arrHeaders(UniValue::VARR);
458 
459  if (!fVerbose)
460  {
461  for (; pblockindex; pblockindex = chainActive.Next(pblockindex))
462  {
464  ssBlock << pblockindex->GetBlockHeader();
465  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
466  arrHeaders.push_back(strHex);
467  if (--nCount <= 0)
468  break;
469  }
470  return arrHeaders;
471  }
472 
473  for (; pblockindex; pblockindex = chainActive.Next(pblockindex))
474  {
475  arrHeaders.push_back(blockheaderToJSON(pblockindex));
476  if (--nCount <= 0)
477  break;
478  }
479 
480  return arrHeaders;
481 }
482 
483 UniValue getblock(const UniValue& params, bool fHelp)
484 {
485  if (fHelp || params.size() < 1 || params.size() > 2)
486  throw runtime_error(
487  "getblock \"hash\" ( verbose )\n"
488  "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
489  "If verbose is true, returns an Object with information about block <hash>.\n"
490  "\nArguments:\n"
491  "1. \"hash\" (string, required) The block hash\n"
492  "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
493  "\nResult (for verbose = true):\n"
494  "{\n"
495  " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
496  " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
497  " \"size\" : n, (numeric) The block size\n"
498  " \"height\" : n, (numeric) The block height or index\n"
499  " \"version\" : n, (numeric) The block version\n"
500  " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
501  " \"tx\" : [ (array of string) The transaction ids\n"
502  " \"transactionid\" (string) The transaction id\n"
503  " ,...\n"
504  " ],\n"
505  " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
506  " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
507  " \"nonce\" : n, (numeric) The nonce\n"
508  " \"bits\" : \"1d00ffff\", (string) The bits\n"
509  " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
510  " \"chainwork\" : \"xxxx\", (string) Expected number of hashes required to produce the chain up to this block (in hex)\n"
511  " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
512  " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
513  "}\n"
514  "\nResult (for verbose=false):\n"
515  "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
516  "\nExamples:\n"
517  + HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
518  + HelpExampleRpc("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"")
519  );
520 
521  LOCK(cs_main);
522 
523  std::string strHash = params[0].get_str();
524  uint256 hash(uint256S(strHash));
525 
526  bool fVerbose = true;
527  if (params.size() > 1)
528  fVerbose = params[1].get_bool();
529 
530  if (mapBlockIndex.count(hash) == 0)
531  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
532 
533  CBlock block;
534  CBlockIndex* pblockindex = mapBlockIndex[hash];
535 
536  if (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0)
537  throw JSONRPCError(RPC_INTERNAL_ERROR, "Block not available (pruned data)");
538 
539  if(!ReadBlockFromDisk(block, pblockindex, Params().GetConsensus()))
540  throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
541 
542  if (!fVerbose)
543  {
545  ssBlock << block;
546  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
547  return strHex;
548  }
549 
550  return blockToJSON(block, pblockindex);
551 }
552 
553 UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
554 {
555  if (fHelp || params.size() != 0)
556  throw runtime_error(
557  "gettxoutsetinfo\n"
558  "\nReturns statistics about the unspent transaction output set.\n"
559  "Note this call may take some time.\n"
560  "\nResult:\n"
561  "{\n"
562  " \"height\":n, (numeric) The current block height (index)\n"
563  " \"bestblock\": \"hex\", (string) the best block hash hex\n"
564  " \"transactions\": n, (numeric) The number of transactions\n"
565  " \"txouts\": n, (numeric) The number of output transactions\n"
566  " \"bytes_serialized\": n, (numeric) The serialized size\n"
567  " \"hash_serialized\": \"hash\", (string) The serialized hash\n"
568  " \"total_amount\": x.xxx (numeric) The total amount\n"
569  "}\n"
570  "\nExamples:\n"
571  + HelpExampleCli("gettxoutsetinfo", "")
572  + HelpExampleRpc("gettxoutsetinfo", "")
573  );
574 
576 
577  CCoinsStats stats;
579  if (pcoinsTip->GetStats(stats)) {
580  ret.push_back(Pair("height", (int64_t)stats.nHeight));
581  ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
582  ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));
583  ret.push_back(Pair("txouts", (int64_t)stats.nTransactionOutputs));
584  ret.push_back(Pair("bytes_serialized", (int64_t)stats.nSerializedSize));
585  ret.push_back(Pair("hash_serialized", stats.hashSerialized.GetHex()));
586  ret.push_back(Pair("total_amount", ValueFromAmount(stats.nTotalAmount)));
587  }
588  return ret;
589 }
590 
591 UniValue gettxout(const UniValue& params, bool fHelp)
592 {
593  if (fHelp || params.size() < 2 || params.size() > 3)
594  throw runtime_error(
595  "gettxout \"txid\" n ( includemempool )\n"
596  "\nReturns details about an unspent transaction output.\n"
597  "\nArguments:\n"
598  "1. \"txid\" (string, required) The transaction id\n"
599  "2. n (numeric, required) vout value\n"
600  "3. includemempool (boolean, optional) Whether to included the mem pool\n"
601  "\nResult:\n"
602  "{\n"
603  " \"bestblock\" : \"hash\", (string) the block hash\n"
604  " \"confirmations\" : n, (numeric) The number of confirmations\n"
605  " \"value\" : x.xxx, (numeric) The transaction value in " + CURRENCY_UNIT + "\n"
606  " \"scriptPubKey\" : { (json object)\n"
607  " \"asm\" : \"code\", (string) \n"
608  " \"hex\" : \"hex\", (string) \n"
609  " \"reqSigs\" : n, (numeric) Number of required signatures\n"
610  " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n"
611  " \"addresses\" : [ (array of string) array of dash addresses\n"
612  " \"dashaddress\" (string) dash address\n"
613  " ,...\n"
614  " ]\n"
615  " },\n"
616  " \"version\" : n, (numeric) The version\n"
617  " \"coinbase\" : true|false (boolean) Coinbase or not\n"
618  "}\n"
619 
620  "\nExamples:\n"
621  "\nGet unspent transactions\n"
622  + HelpExampleCli("listunspent", "") +
623  "\nView the details\n"
624  + HelpExampleCli("gettxout", "\"txid\" 1") +
625  "\nAs a json rpc call\n"
626  + HelpExampleRpc("gettxout", "\"txid\", 1")
627  );
628 
629  LOCK(cs_main);
630 
632 
633  std::string strHash = params[0].get_str();
634  uint256 hash(uint256S(strHash));
635  int n = params[1].get_int();
636  bool fMempool = true;
637  if (params.size() > 2)
638  fMempool = params[2].get_bool();
639 
640  CCoins coins;
641  if (fMempool) {
642  LOCK(mempool.cs);
644  if (!view.GetCoins(hash, coins))
645  return NullUniValue;
646  mempool.pruneSpent(hash, coins); // TODO: this should be done by the CCoinsViewMemPool
647  } else {
648  if (!pcoinsTip->GetCoins(hash, coins))
649  return NullUniValue;
650  }
651  if (n<0 || (unsigned int)n>=coins.vout.size() || coins.vout[n].IsNull())
652  return NullUniValue;
653 
654  BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
655  CBlockIndex *pindex = it->second;
656  ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
657  if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
658  ret.push_back(Pair("confirmations", 0));
659  else
660  ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
661  ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue)));
663  ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
664  ret.push_back(Pair("scriptPubKey", o));
665  ret.push_back(Pair("version", coins.nVersion));
666  ret.push_back(Pair("coinbase", coins.fCoinBase));
667 
668  return ret;
669 }
670 
671 UniValue verifychain(const UniValue& params, bool fHelp)
672 {
673  int nCheckLevel = GetArg("-checklevel", DEFAULT_CHECKLEVEL);
674  int nCheckDepth = GetArg("-checkblocks", DEFAULT_CHECKBLOCKS);
675  if (fHelp || params.size() > 2)
676  throw runtime_error(
677  "verifychain ( checklevel numblocks )\n"
678  "\nVerifies blockchain database.\n"
679  "\nArguments:\n"
680  "1. checklevel (numeric, optional, 0-4, default=" + strprintf("%d", nCheckLevel) + ") How thorough the block verification is.\n"
681  "2. numblocks (numeric, optional, default=" + strprintf("%d", nCheckDepth) + ", 0=all) The number of blocks to check.\n"
682  "\nResult:\n"
683  "true|false (boolean) Verified or not\n"
684  "\nExamples:\n"
685  + HelpExampleCli("verifychain", "")
686  + HelpExampleRpc("verifychain", "")
687  );
688 
689  LOCK(cs_main);
690 
691  if (params.size() > 0)
692  nCheckLevel = params[0].get_int();
693  if (params.size() > 1)
694  nCheckDepth = params[1].get_int();
695 
696  return CVerifyDB().VerifyDB(Params(), pcoinsTip, nCheckLevel, nCheckDepth);
697 }
698 
700 static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired, const Consensus::Params& consensusParams)
701 {
702  int nFound = 0;
703  CBlockIndex* pstart = pindex;
704  for (int i = 0; i < consensusParams.nMajorityWindow && pstart != NULL; i++)
705  {
706  if (pstart->nVersion >= minVersion)
707  ++nFound;
708  pstart = pstart->pprev;
709  }
710 
712  rv.push_back(Pair("status", nFound >= nRequired));
713  rv.push_back(Pair("found", nFound));
714  rv.push_back(Pair("required", nRequired));
715  rv.push_back(Pair("window", consensusParams.nMajorityWindow));
716  return rv;
717 }
718 
719 static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex, const Consensus::Params& consensusParams)
720 {
722  rv.push_back(Pair("id", name));
723  rv.push_back(Pair("version", version));
724  rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, consensusParams.nMajorityEnforceBlockUpgrade, consensusParams)));
725  rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, consensusParams.nMajorityRejectBlockOutdated, consensusParams)));
726  return rv;
727 }
728 
729 static UniValue BIP9SoftForkDesc(const std::string& name, const Consensus::Params& consensusParams, Consensus::DeploymentPos id)
730 {
732  rv.push_back(Pair("id", name));
733  switch (VersionBitsTipState(consensusParams, id)) {
734  case THRESHOLD_DEFINED: rv.push_back(Pair("status", "defined")); break;
735  case THRESHOLD_STARTED: rv.push_back(Pair("status", "started")); break;
736  case THRESHOLD_LOCKED_IN: rv.push_back(Pair("status", "locked_in")); break;
737  case THRESHOLD_ACTIVE: rv.push_back(Pair("status", "active")); break;
738  case THRESHOLD_FAILED: rv.push_back(Pair("status", "failed")); break;
739  }
740  return rv;
741 }
742 
743 UniValue getblockchaininfo(const UniValue& params, bool fHelp)
744 {
745  if (fHelp || params.size() != 0)
746  throw runtime_error(
747  "getblockchaininfo\n"
748  "Returns an object containing various state info regarding block chain processing.\n"
749  "\nResult:\n"
750  "{\n"
751  " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n"
752  " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
753  " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n"
754  " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
755  " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
756  " \"mediantime\": xxxxxx, (numeric) median time for the current best block\n"
757  " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
758  " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
759  " \"pruned\": xx, (boolean) if the blocks are subject to pruning\n"
760  " \"pruneheight\": xxxxxx, (numeric) heighest block available\n"
761  " \"softforks\": [ (array) status of softforks in progress\n"
762  " {\n"
763  " \"id\": \"xxxx\", (string) name of softfork\n"
764  " \"version\": xx, (numeric) block version\n"
765  " \"enforce\": { (object) progress toward enforcing the softfork rules for new-version blocks\n"
766  " \"status\": xx, (boolean) true if threshold reached\n"
767  " \"found\": xx, (numeric) number of blocks with the new version found\n"
768  " \"required\": xx, (numeric) number of blocks required to trigger\n"
769  " \"window\": xx, (numeric) maximum size of examined window of recent blocks\n"
770  " },\n"
771  " \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
772  " }, ...\n"
773  " ],\n"
774  " \"bip9_softforks\": [ (array) status of BIP9 softforks in progress\n"
775  " {\n"
776  " \"id\": \"xxxx\", (string) name of the softfork\n"
777  " \"status\": \"xxxx\", (string) one of \"defined\", \"started\", \"lockedin\", \"active\", \"failed\"\n"
778  " }\n"
779  " ]\n"
780  "}\n"
781  "\nExamples:\n"
782  + HelpExampleCli("getblockchaininfo", "")
783  + HelpExampleRpc("getblockchaininfo", "")
784  );
785 
786  LOCK(cs_main);
787 
789  obj.push_back(Pair("chain", Params().NetworkIDString()));
790  obj.push_back(Pair("blocks", (int)chainActive.Height()));
791  obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
792  obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
793  obj.push_back(Pair("difficulty", (double)GetDifficulty()));
794  obj.push_back(Pair("mediantime", (int64_t)chainActive.Tip()->GetMedianTimePast()));
796  obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
797  obj.push_back(Pair("pruned", fPruneMode));
798 
799  const Consensus::Params& consensusParams = Params().GetConsensus();
800  CBlockIndex* tip = chainActive.Tip();
801  UniValue softforks(UniValue::VARR);
802  UniValue bip9_softforks(UniValue::VARR);
803  softforks.push_back(SoftForkDesc("bip34", 2, tip, consensusParams));
804  softforks.push_back(SoftForkDesc("bip66", 3, tip, consensusParams));
805  softforks.push_back(SoftForkDesc("bip65", 4, tip, consensusParams));
806  bip9_softforks.push_back(BIP9SoftForkDesc("csv", consensusParams, Consensus::DEPLOYMENT_CSV));
807  bip9_softforks.push_back(BIP9SoftForkDesc("dip0001", consensusParams, Consensus::DEPLOYMENT_DIP0001));
808  obj.push_back(Pair("softforks", softforks));
809  obj.push_back(Pair("bip9_softforks", bip9_softforks));
810 
811  if (fPruneMode)
812  {
813  CBlockIndex *block = chainActive.Tip();
814  while (block && block->pprev && (block->pprev->nStatus & BLOCK_HAVE_DATA))
815  block = block->pprev;
816 
817  obj.push_back(Pair("pruneheight", block->nHeight));
818  }
819  return obj;
820 }
821 
824 {
825  bool operator()(const CBlockIndex* a, const CBlockIndex* b) const
826  {
827  /* Make sure that unequal blocks with the same height do not compare
828  equal. Use the pointers themselves to make a distinction. */
829 
830  if (a->nHeight != b->nHeight)
831  return (a->nHeight > b->nHeight);
832 
833  return a < b;
834  }
835 };
836 
837 UniValue getchaintips(const UniValue& params, bool fHelp)
838 {
839  if (fHelp || params.size() > 2)
840  throw runtime_error(
841  "getchaintips ( count branchlen )\n"
842  "Return information about all known tips in the block tree,"
843  " including the main chain as well as orphaned branches.\n"
844  "\nArguments:\n"
845  "1. count (numeric, optional) only show this much of latest tips\n"
846  "2. branchlen (numeric, optional) only show tips that have equal or greater length of branch\n"
847  "\nResult:\n"
848  "[\n"
849  " {\n"
850  " \"height\": xxxx, (numeric) height of the chain tip\n"
851  " \"hash\": \"xxxx\", (string) block hash of the tip\n"
852  " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
853  " \"chainwork\" : \"0000...1f3\" (string) Expected number of hashes required to produce the current chain (in hex)\n"
854  " \"branchlen\": 0 (numeric) zero for main chain\n"
855  " \"status\": \"active\" (string) \"active\" for the main chain\n"
856  " },\n"
857  " {\n"
858  " \"height\": xxxx,\n"
859  " \"hash\": \"xxxx\",\n"
860  " \"difficulty\" : x.xxx,\n"
861  " \"chainwork\" : \"0000...1f3\"\n"
862  " \"branchlen\": 1 (numeric) length of branch connecting the tip to the main chain\n"
863  " \"status\": \"xxxx\" (string) status of the chain (active, valid-fork, valid-headers, headers-only, invalid)\n"
864  " }\n"
865  "]\n"
866  "Possible values for status:\n"
867  "1. \"invalid\" This branch contains at least one invalid block\n"
868  "2. \"headers-only\" Not all blocks for this branch are available, but the headers are valid\n"
869  "3. \"valid-headers\" All blocks are available for this branch, but they were never fully validated\n"
870  "4. \"valid-fork\" This branch is not part of the active chain, but is fully validated\n"
871  "5. \"active\" This is the tip of the active main chain, which is certainly valid\n"
872  "\nExamples:\n"
873  + HelpExampleCli("getchaintips", "")
874  + HelpExampleRpc("getchaintips", "")
875  );
876 
877  LOCK(cs_main);
878 
879  /* Build up a list of chain tips. We start with the list of all
880  known blocks, and successively remove blocks that appear as pprev
881  of another block. */
882  std::set<const CBlockIndex*, CompareBlocksByHeight> setTips;
883  BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
884  setTips.insert(item.second);
885  BOOST_FOREACH(const PAIRTYPE(const uint256, CBlockIndex*)& item, mapBlockIndex)
886  {
887  const CBlockIndex* pprev = item.second->pprev;
888  if (pprev)
889  setTips.erase(pprev);
890  }
891 
892  // Always report the currently active tip.
893  setTips.insert(chainActive.Tip());
894 
895  int nBranchMin = -1;
896  int nCountMax = INT_MAX;
897 
898  if(params.size() >= 1)
899  nCountMax = params[0].get_int();
900 
901  if(params.size() == 2)
902  nBranchMin = params[1].get_int();
903 
904  /* Construct the output array. */
906  BOOST_FOREACH(const CBlockIndex* block, setTips)
907  {
908  const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
909  if(branchLen < nBranchMin) continue;
910 
911  if(nCountMax-- < 1) break;
912 
914  obj.push_back(Pair("height", block->nHeight));
915  obj.push_back(Pair("hash", block->phashBlock->GetHex()));
916  obj.push_back(Pair("difficulty", GetDifficulty(block)));
917  obj.push_back(Pair("chainwork", block->nChainWork.GetHex()));
918  obj.push_back(Pair("branchlen", branchLen));
919 
920  string status;
921  if (chainActive.Contains(block)) {
922  // This block is part of the currently active chain.
923  status = "active";
924  } else if (block->nStatus & BLOCK_FAILED_MASK) {
925  // This block or one of its ancestors is invalid.
926  status = "invalid";
927  } else if (block->nChainTx == 0) {
928  // This block cannot be connected because full block data for it or one of its parents is missing.
929  status = "headers-only";
930  } else if (block->IsValid(BLOCK_VALID_SCRIPTS)) {
931  // This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized.
932  status = "valid-fork";
933  } else if (block->IsValid(BLOCK_VALID_TREE)) {
934  // The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain.
935  status = "valid-headers";
936  } else {
937  // No clue.
938  status = "unknown";
939  }
940  obj.push_back(Pair("status", status));
941 
942  res.push_back(obj);
943  }
944 
945  return res;
946 }
947 
949 {
951  ret.push_back(Pair("size", (int64_t) mempool.size()));
952  ret.push_back(Pair("bytes", (int64_t) mempool.GetTotalTxSize()));
953  ret.push_back(Pair("usage", (int64_t) mempool.DynamicMemoryUsage()));
954  size_t maxmempool = GetArg("-maxmempool", DEFAULT_MAX_MEMPOOL_SIZE) * 1000000;
955  ret.push_back(Pair("maxmempool", (int64_t) maxmempool));
956  ret.push_back(Pair("mempoolminfee", ValueFromAmount(mempool.GetMinFee(maxmempool).GetFeePerK())));
957 
958  return ret;
959 }
960 
961 UniValue getmempoolinfo(const UniValue& params, bool fHelp)
962 {
963  if (fHelp || params.size() != 0)
964  throw runtime_error(
965  "getmempoolinfo\n"
966  "\nReturns details on the active state of the TX memory pool.\n"
967  "\nResult:\n"
968  "{\n"
969  " \"size\": xxxxx, (numeric) Current tx count\n"
970  " \"bytes\": xxxxx, (numeric) Sum of all tx sizes\n"
971  " \"usage\": xxxxx, (numeric) Total memory usage for the mempool\n"
972  " \"maxmempool\": xxxxx, (numeric) Maximum memory usage for the mempool\n"
973  " \"mempoolminfee\": xxxxx (numeric) Minimum fee for tx to be accepted\n"
974  "}\n"
975  "\nExamples:\n"
976  + HelpExampleCli("getmempoolinfo", "")
977  + HelpExampleRpc("getmempoolinfo", "")
978  );
979 
980  return mempoolInfoToJSON();
981 }
982 
983 UniValue invalidateblock(const UniValue& params, bool fHelp)
984 {
985  if (fHelp || params.size() != 1)
986  throw runtime_error(
987  "invalidateblock \"hash\"\n"
988  "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n"
989  "\nArguments:\n"
990  "1. hash (string, required) the hash of the block to mark as invalid\n"
991  "\nResult:\n"
992  "\nExamples:\n"
993  + HelpExampleCli("invalidateblock", "\"blockhash\"")
994  + HelpExampleRpc("invalidateblock", "\"blockhash\"")
995  );
996 
997  std::string strHash = params[0].get_str();
998  uint256 hash(uint256S(strHash));
999  CValidationState state;
1000 
1001  {
1002  LOCK(cs_main);
1003  if (mapBlockIndex.count(hash) == 0)
1004  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1005 
1006  CBlockIndex* pblockindex = mapBlockIndex[hash];
1007  InvalidateBlock(state, Params().GetConsensus(), pblockindex);
1008  }
1009 
1010  if (state.IsValid()) {
1011  ActivateBestChain(state, Params(), NULL);
1012  }
1013 
1014  if (!state.IsValid()) {
1016  }
1017 
1018  return NullUniValue;
1019 }
1020 
1021 UniValue reconsiderblock(const UniValue& params, bool fHelp)
1022 {
1023  if (fHelp || params.size() != 1)
1024  throw runtime_error(
1025  "reconsiderblock \"hash\"\n"
1026  "\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n"
1027  "This can be used to undo the effects of invalidateblock.\n"
1028  "\nArguments:\n"
1029  "1. hash (string, required) the hash of the block to reconsider\n"
1030  "\nResult:\n"
1031  "\nExamples:\n"
1032  + HelpExampleCli("reconsiderblock", "\"blockhash\"")
1033  + HelpExampleRpc("reconsiderblock", "\"blockhash\"")
1034  );
1035 
1036  std::string strHash = params[0].get_str();
1037  uint256 hash(uint256S(strHash));
1038  CValidationState state;
1039 
1040  {
1041  LOCK(cs_main);
1042  if (mapBlockIndex.count(hash) == 0)
1043  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1044 
1045  CBlockIndex* pblockindex = mapBlockIndex[hash];
1046  ReconsiderBlock(state, pblockindex);
1047  }
1048 
1049  if (state.IsValid()) {
1050  ActivateBestChain(state, Params(), NULL);
1051  }
1052 
1053  if (!state.IsValid()) {
1055  }
1056 
1057  return NullUniValue;
1058 }
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: chain.h:125
bool ActivateBestChain(CValidationState &state, const CChainParams &chainparams, const CBlock *pblock)
bool fPruneMode
Definition: validation.cpp:77
unsigned long size()
Definition: txmempool.h:551
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: coins.cpp:90
Definition: coins.h:73
CAmount nTotalAmount
Definition: coins.h:308
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
Definition: coins.cpp:57
void queryHashes(std::vector< uint256 > &vtxid)
Definition: txmempool.cpp:859
unsigned int GetHeight() const
Definition: txmempool.h:119
std::string GetRejectReason() const
Definition: validation.h:81
UniValue getblockheader(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:336
uint256 hashMerkleRoot
Definition: block.h:26
size_t GetTxSize() const
Definition: txmempool.h:117
static const unsigned int DEFAULT_MAX_MEMPOOL_SIZE
Definition: policy.h:29
UniValue getdifficulty(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:165
#define strprintf
Definition: tinyformat.h:1011
uint256 hashSerialized
Definition: coins.h:307
descends from failed block
Definition: chain.h:92
bool fHavePruned
Definition: validation.cpp:76
unsigned int nBits
Definition: chain.h:143
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:55
uint64_t nTransactionOutputs
Definition: coins.h:305
UniValue mempoolInfoToJSON()
Definition: blockchain.cpp:948
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
Definition: chain.h:253
CBlockHeader GetBlockHeader() const
Definition: chain.h:205
const std::string CURRENCY_UNIT
Definition: amount.cpp:10
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: txmempool.cpp:984
CCriticalSection cs_main
Definition: validation.cpp:62
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
UniValue reconsiderblock(const UniValue &params, bool fHelp)
int64_t GetBlockTime() const
Definition: block.h:66
sph_u32 high
Definition: keccak.c:370
UniValue blockheaderToJSON(const CBlockIndex *blockindex)
Definition: blockchain.cpp:63
int nVersion
Definition: coins.h:87
bool fCoinBase
whether transaction is a coinbase
Definition: coins.h:77
const_iterator end() const
Definition: streams.h:120
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
Definition: server.cpp:586
UniValue getblockheaders(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:394
unsigned int nNonce
Definition: chain.h:144
uint64_t GetCountWithDescendants() const
Definition: txmempool.h:141
double GetDifficulty(const CBlockIndex *blockindex)
Definition: blockchain.cpp:32
UniValue gettxout(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:591
indexed_transaction_set mapTx
Definition: txmempool.h:403
unsigned int nTx
Definition: chain.h:129
uint64_t GetTotalTxSize()
Definition: txmempool.h:557
UniValue getblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:483
bool push_back(const UniValue &val)
Definition: univalue.cpp:176
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:122
Ran out of memory during operation.
Definition: protocol.h:46
UniValue getblockhashes(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:277
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
const CAmount & GetFee() const
Definition: txmempool.h:116
std::vector< CTransaction > vtx
Definition: block.h:77
DeploymentPos
Definition: params.h:15
bool Contains(const CBlockIndex *pindex) const
Definition: chain.h:384
bool exists(uint256 hash) const
Definition: txmempool.h:563
int nHeight
Definition: coins.h:302
CCoinsViewCache * pcoinsTip
Definition: validation.cpp:187
UniValue verifychain(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:671
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
Definition: coins.h:80
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
Definition: chain.h:104
CCriticalSection cs
Definition: txmempool.h:402
UniValue getmempoolinfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:961
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry)
COutPoint prevout
Definition: transaction.h:61
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:202
CBlockIndex * pindexBestHeader
Definition: validation.cpp:66
UniValue getblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:311
bool operator()(const CBlockIndex *a, const CBlockIndex *b) const
Definition: blockchain.cpp:825
const_iterator begin() const
Definition: streams.h:118
#define LOCK(cs)
Definition: sync.h:168
UniValue getblockcount(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:131
const char * name
Definition: rest.cpp:37
uint256 hashMerkleRoot
Definition: chain.h:141
const CTransaction & GetTx() const
Definition: txmempool.h:110
size_t DynamicMemoryUsage() const
Definition: txmempool.cpp:1000
static const unsigned int MAX_HEADERS_RESULTS
Definition: validation.h:92
uint256 uint256S(const char *str)
Definition: uint256.h:140
CAmount GetFeePerK() const
Definition: amount.h:47
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Definition: chain.cpp:53
static UniValue BIP9SoftForkDesc(const std::string &name, const Consensus::Params &consensusParams, Consensus::DeploymentPos id)
Definition: blockchain.cpp:729
int Height() const
Definition: chain.h:397
int nMajorityRejectBlockOutdated
Definition: params.h:61
uint32_t nBits
Definition: block.h:28
unsigned int nTime
Definition: chain.h:142
uint256 hashBlock
Definition: coins.h:303
CChain chainActive
Definition: validation.cpp:65
std::string ToString() const
Definition: uint256.cpp:65
Unexpected type was passed as parameter.
Definition: protocol.h:44
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
Definition: server.cpp:581
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
Definition: univalue.h:166
int nMajorityEnforceBlockUpgrade
Definition: params.h:60
double GuessVerificationProgress(const CCheckpointData &data, CBlockIndex *pindex, bool fSigchecks)
Guess how far we are in the verification process at the given block index.
Definition: checkpoints.cpp:30
static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex *pindex, const Consensus::Params &consensusParams)
Definition: blockchain.cpp:719
version
Definition: setup.py:3
int64_t GetTime() const
Definition: txmempool.h:118
bool IsValid() const
Definition: validation.h:61
static bool FlushStateToDisk(CValidationState &state, FlushStateMode mode)
Invalid, missing or duplicate parameter.
Definition: protocol.h:47
CAmount GetModFeesWithDescendants() const
Definition: txmempool.h:143
const std::vector< CTxIn > vin
Definition: transaction.h:233
UniValue blockToJSON(const CBlock &block, const CBlockIndex *blockindex, bool txDetails=false)
Definition: blockchain.cpp:90
int64_t GetModifiedFee() const
Definition: txmempool.h:122
CTxMemPool mempool
uint32_t nNonce
Definition: block.h:29
UniValue gettxoutsetinfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:553
bool InvalidateBlock(CValidationState &state, const Consensus::Params &consensusParams, CBlockIndex *pindex)
CBlockIndex * Next(const CBlockIndex *pindex) const
Definition: chain.h:389
uint64_t nSerializedSize
Definition: coins.h:306
UniValue getrawmempool(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:234
const CChainParams & Params()
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:190
static const int PROTOCOL_VERSION
Definition: version.h:13
const uint256 & GetHash() const
Definition: transaction.h:262
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:137
uint256 GetBlockHash() const
Definition: chain.h:218
UniValue getbestblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:148
UniValue invalidateblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:983
std::string GetHex() const
Definition: uint256.cpp:21
sph_u32 low
Definition: keccak.c:370
int32_t nVersion
Definition: block.h:24
void pruneSpent(const uint256 &hash, CCoins &coins)
Definition: txmempool.cpp:347
const UniValue NullUniValue
Definition: univalue.cpp:78
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:152
CFeeRate GetMinFee(size_t sizelimit) const
Definition: txmempool.cpp:1076
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:80
unsigned int nChainTx
Definition: chain.h:134
int get_int() const
Definition: univalue.cpp:317
CBlockIndex * Tip() const
Definition: chain.h:366
uint64_t nTransactions
Definition: coins.h:304
bool VerifyDB(const CChainParams &chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
int64_t GetMedianTimePast() const
Definition: chain.h:230
bool ReconsiderBlock(CValidationState &state, CBlockIndex *pindex)
double GetPriority(unsigned int currentHeight) const
Definition: txmempool.cpp:50
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Definition: util.cpp:441
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:107
std::string GetHex() const
static const unsigned int MEMPOOL_HEIGHT
Definition: txmempool.h:40
int nMajorityWindow
Definition: params.h:62
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
UniValue mempoolToJSON(bool fVerbose=false)
Definition: blockchain.cpp:182
Definition: block.h:73
uint256 GetHash() const
Definition: block.cpp:13
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:113
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
int nVersion
block header
Definition: chain.h:140
#define PAIRTYPE(t1, t2)
uint256 hash
Definition: transaction.h:18
uint64_t GetSizeWithDescendants() const
Definition: txmempool.h:142
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector< uint256 > &hashes)
UniValue JSONRPCError(int code, const string &message)
Definition: protocol.cpp:57
BlockMap mapBlockIndex
Definition: validation.cpp:64
size_t size() const
Definition: univalue.h:69
UniValue getchaintips(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:837
UniValue getblockchaininfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:743
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:191
std::string get_str() const
Definition: univalue.cpp:310
int nHeight
at which height this transaction was included in the active block chain
Definition: coins.h:83
result
Definition: rpcuser.py:37
static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex *pindex, int nRequired, const Consensus::Params &consensusParams)
Definition: blockchain.cpp:700