PRCYCoin  2.0.0.7rc1
P2P Digital Currency
blockchain.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2014-2015 The Dash developers
4 // Copyright (c) 2015-2018 The PIVX developers
5 // Copyright (c) 2018-2020 The DAPS Project developers
6 // Distributed under the MIT software license, see the accompanying
7 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
8 
9 #include "checkpoints.h"
10 #include "main.h"
11 #include "rpc/server.h"
12 #include "sync.h"
13 #include "util.h"
14 #include "utilmoneystr.h"
15 #include "base58.h"
16 
17 #include <stdint.h>
18 
19 #include <univalue.h>
20 #include <mutex>
21 #include <numeric>
22 #include <condition_variable>
23 #include "clientversion.h"
24 
25 
27 {
29  int height;
30 };
31 static std::mutex cs_blockchange;
32 static std::condition_variable cond_blockchange;
33 static CUpdatedBlock latestblock;
34 
35 extern void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry);
36 extern void PoSBlockInfoToJSON(const uint256 hashBlock, int64_t nTime, int height, UniValue& entry);
37 void ScriptPubKeyToJSON(const CScript& scriptPubKey, UniValue& out, bool fIncludeHex);
38 
39 double GetDifficulty(const CBlockIndex* blockindex)
40 {
41  // Floating point number that is a multiple of the minimum difficulty,
42  // minimum difficulty = 1.0.
43  if (blockindex == NULL) {
44  if (chainActive.Tip() == NULL)
45  return 1.0;
46  else
47  blockindex = chainActive.Tip();
48  }
49 
50  int nShift = (blockindex->nBits >> 24) & 0xff;
51 
52  double dDiff =
53  (double)0x0000ffff / (double)(blockindex->nBits & 0x00ffffff);
54 
55  while (nShift < 29) {
56  dDiff *= 256.0;
57  nShift++;
58  }
59  while (nShift > 29) {
60  dDiff /= 256.0;
61  nShift--;
62  }
63 
64  return dDiff;
65 }
66 
68 {
69  UniValue result(UniValue::VOBJ);
70  result.push_back(Pair("hash", blockindex->GetBlockHash().GetHex()));
71  int confirmations = -1;
72  // Only report confirmations if the block is on the main chain
73  if (chainActive.Contains(blockindex))
74  confirmations = chainActive.Height() - blockindex->nHeight + 1;
75  result.push_back(Pair("confirmations", confirmations));
76  result.push_back(Pair("height", blockindex->nHeight));
77  result.push_back(Pair("version", blockindex->nVersion));
78  result.push_back(Pair("merkleroot", blockindex->hashMerkleRoot.GetHex()));
79  result.push_back(Pair("time", (int64_t)blockindex->nTime));
80  result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
81  result.push_back(Pair("nonce", (uint64_t)blockindex->nNonce));
82  result.push_back(Pair("bits", strprintf("%08x", blockindex->nBits)));
83  result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
84  result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
85  result.push_back(Pair("acc_checkpoint", blockindex->nAccumulatorCheckpoint.GetHex()));
86 
87  if (blockindex->pprev)
88  result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
89  CBlockIndex *pnext = chainActive.Next(blockindex);
90  if (pnext)
91  result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
92  return result;
93 }
94 
95 UniValue blockToJSON(const CBlock& block, const CBlockIndex* blockindex, bool txDetails = false)
96 {
97  UniValue result(UniValue::VOBJ);
98  result.push_back(Pair("hash", block.GetHash().GetHex()));
99  int confirmations = -1;
100  // Only report confirmations if the block is on the main chain
101  if (chainActive.Contains(blockindex))
102  confirmations = chainActive.Height() - blockindex->nHeight + 1;
103  result.push_back(Pair("confirmations", confirmations));
104  result.push_back(Pair("size", (int)::GetSerializeSize(block, SER_NETWORK, PROTOCOL_VERSION)));
105  result.push_back(Pair("height", blockindex->nHeight));
106  result.push_back(Pair("version", block.nVersion));
107  result.push_back(Pair("merkleroot", block.hashMerkleRoot.GetHex()));
108  result.push_back(Pair("acc_checkpoint", block.nAccumulatorCheckpoint.GetHex()));
110  for (const CTransaction& tx : block.vtx) {
111  if (txDetails) {
112  UniValue objTx(UniValue::VOBJ);
113  TxToJSON(tx, UINT256_ZERO, objTx);
114  txs.push_back(objTx);
115  } else
116  txs.push_back(tx.GetHash().GetHex());
117  }
118  result.push_back(Pair("tx", txs));
119  result.push_back(Pair("time", block.GetBlockTime()));
120  result.push_back(Pair("mediantime", (int64_t)blockindex->GetMedianTimePast()));
121  result.push_back(Pair("nonce", (uint64_t)block.nNonce));
122  result.push_back(Pair("bits", strprintf("%08x", block.nBits)));
123  result.push_back(Pair("difficulty", GetDifficulty(blockindex)));
124  result.push_back(Pair("chainwork", blockindex->nChainWork.GetHex()));
125 
126  if (blockindex->pprev)
127  result.push_back(Pair("previousblockhash", blockindex->pprev->GetBlockHash().GetHex()));
128  CBlockIndex* pnext = chainActive.Next(blockindex);
129  if (pnext)
130  result.push_back(Pair("nextblockhash", pnext->GetBlockHash().GetHex()));
131 
132  result.push_back(Pair("modifier", strprintf("%016x", blockindex->nStakeModifier)));
133 
134  result.push_back(Pair("moneysupply",ValueFromAmount(blockindex->nMoneySupply)));
135  std::string minetype = "PoW";
136  if (blockindex->IsProofOfStake()) {
137  minetype = "PoS";
138  } else if (blockindex->IsProofOfAudit()) {
139  minetype = "PoA";
140  }
141 
142  result.push_back(Pair("minetype", minetype));
143 
144  if (blockindex->IsProofOfAudit()) {
145  //This is a PoA block
146  //Read information of PoS blocks audited by this PoA block
147  result.push_back(Pair("previouspoahash", block.hashPrevPoABlock.GetHex()));
148  UniValue posBlockInfos(UniValue::VARR);
149  bool auditResult = true;
150  for (int i = 0; i < block.posBlocksAudited.size(); i++) {
151  UniValue objPoSBlockInfo(UniValue::VOBJ);
152  PoSBlockInfoToJSON(block.posBlocksAudited[i].hash,
153  block.posBlocksAudited[i].nTime, block.posBlocksAudited[i].height, objPoSBlockInfo);
154  posBlockInfos.push_back(objPoSBlockInfo);
155  auditResult = auditResult & (block.posBlocksAudited[i].nTime > 0);
156  }
157  result.push_back(Pair("auditsuccess", auditResult? "true": "false"));
158  result.push_back(Pair("posblocks", posBlockInfos));
159  result.push_back(Pair("poscount", (int)block.posBlocksAudited.size()));
160  }
161 
162  return result;
163 }
164 
165 UniValue getsupply(const UniValue& params, bool fHelp)
166 {
167  if (fHelp || params.size() != 0)
168  throw std::runtime_error(
169  "getsupply\n"
170  "\nReturns the current supply.\n"
171  "\nResult:\n"
172  "n (numeric) The current supply\n"
173  "\nExamples:\n" +
174  HelpExampleCli("getsupply", "") + HelpExampleRpc("getsupply", ""));
175 
176  LOCK(cs_main);
178 }
179 
180 UniValue getmaxsupply(const UniValue& params, bool fHelp)
181 {
182  if (fHelp || params.size() != 0)
183  throw std::runtime_error(
184  "getmaxsupply\n"
185  "\nReturns the max supply.\n"
186  "\nResult:\n"
187  "n (numeric) The maximum supply\n"
188  "\nExamples:\n" +
189  HelpExampleCli("getmaxsupply", "") + HelpExampleRpc("getmaxsupply", ""));
190 
191  return ValueFromAmount(Params().TOTAL_SUPPLY);
192 }
193 
194 UniValue getblockcount(const UniValue& params, bool fHelp)
195 {
196  if (fHelp || params.size() != 0)
197  throw std::runtime_error(
198  "getblockcount\n"
199  "\nReturns the number of blocks in the longest block chain.\n"
200  "\nResult:\n"
201  "n (numeric) The current block count\n"
202  "\nExamples:\n" +
203  HelpExampleCli("getblockcount", "") + HelpExampleRpc("getblockcount", ""));
204 
205  LOCK(cs_main);
206  return chainActive.Height();
207 }
208 
209 UniValue getbestblockhash(const UniValue& params, bool fHelp)
210 {
211  if (fHelp || params.size() != 0)
212  throw std::runtime_error(
213  "getbestblockhash\n"
214  "\nReturns the hash of the best (tip) block in the longest block chain.\n"
215  "\nResult\n"
216  "\"hex\" (string) the block hash hex encoded\n"
217  "\nExamples\n" +
218  HelpExampleCli("getbestblockhash", "") + HelpExampleRpc("getbestblockhash", ""));
219 
220  LOCK(cs_main);
221  return chainActive.Tip()->GetBlockHash().GetHex();
222 }
223 
224 void RPCNotifyBlockChange(bool fInitialDownload, const CBlockIndex* pindex)
225 {
226  if(pindex) {
227  std::lock_guard<std::mutex> lock(cs_blockchange);
228  latestblock.hash = pindex->GetBlockHash();
229  latestblock.height = pindex->nHeight;
230  }
231  cond_blockchange.notify_all();
232 }
233 
234 UniValue waitfornewblock(const UniValue& params, bool fHelp)
235 {
236  if (fHelp || params.size() > 1)
237  throw std::runtime_error(
238  "waitfornewblock ( timeout )\n"
239  "\nWaits for a specific new block and returns useful info about it.\n"
240  "\nReturns the current block on timeout or exit.\n"
241 
242  "\nArguments:\n"
243  "1. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
244 
245  "\nResult:\n"
246  "{ (json object)\n"
247  " \"hash\" : { (string) The blockhash\n"
248  " \"height\" : { (int) Block height\n"
249  "}\n"
250 
251  "\nExamples:\n"
252  + HelpExampleCli("waitfornewblock", "1000")
253  + HelpExampleRpc("waitfornewblock", "1000")
254  );
255  int timeout = 0;
256  if (params.size() > 0)
257  timeout = params[0].get_int();
258  CUpdatedBlock block;
259  {
260  std::unique_lock<std::mutex> lock(cs_blockchange);
261  block = latestblock;
262  if(timeout)
263  cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
264  else
265  cond_blockchange.wait(lock, [&block]{return latestblock.height != block.height || latestblock.hash != block.hash || !IsRPCRunning(); });
266  block = latestblock;
267  }
269  ret.push_back(Pair("hash", block.hash.GetHex()));
270  ret.push_back(Pair("height", block.height));
271  return ret;
272 }
273 
274 UniValue waitforblock(const UniValue& params, bool fHelp)
275 {
276  if (fHelp || params.size() < 1 || params.size() > 2)
277  throw std::runtime_error(
278  "waitforblock blockhash ( timeout )\n"
279  "\nWaits for a specific new block and returns useful info about it.\n"
280  "\nReturns the current block on timeout or exit.\n"
281 
282  "\nArguments:\n"
283  "1. \"blockhash\" (required, std::string) Block hash to wait for.\n"
284  "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
285 
286  "\nResult:\n"
287  "{ (json object)\n"
288  " \"hash\" : { (string) The blockhash\n"
289  " \"height\" : { (int) Block height\n"
290  "}\n"
291 
292  "\nExamples:\n"
293  + HelpExampleCli("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
294  + HelpExampleRpc("waitforblock", "\"0000000000079f8ef3d2c688c244eb7a4570b24c9ed7b4a8c619eb02596f8862\", 1000")
295  );
296  int timeout = 0;
297 
298  uint256 hash = uint256S(params[0].get_str());
299 
300  if (params.size() > 1)
301  timeout = params[1].get_int();
302 
303  CUpdatedBlock block;
304  {
305  std::unique_lock<std::mutex> lock(cs_blockchange);
306  if(timeout)
307  cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&hash]{return latestblock.hash == hash || !IsRPCRunning();});
308  else
309  cond_blockchange.wait(lock, [&hash]{return latestblock.hash == hash || !IsRPCRunning(); });
310  block = latestblock;
311  }
312 
314  ret.push_back(Pair("hash", block.hash.GetHex()));
315  ret.push_back(Pair("height", block.height));
316  return ret;
317 }
318 
319 UniValue waitforblockheight(const UniValue& params, bool fHelp)
320 {
321  if (fHelp || params.size() < 1 || params.size() > 2)
322  throw std::runtime_error(
323  "waitforblockheight height ( timeout )\n"
324  "\nWaits for (at least) block height and returns the height and hash\n"
325  "of the current tip.\n"
326  "\nReturns the current block on timeout or exit.\n"
327 
328  "\nArguments:\n"
329  "1. height (required, int) Block height to wait for (int)\n"
330  "2. timeout (int, optional, default=0) Time in milliseconds to wait for a response. 0 indicates no timeout.\n"
331 
332  "\nResult:\n"
333  "{ (json object)\n"
334  " \"hash\" : { (string) The blockhash\n"
335  " \"height\" : { (int) Block height\n"
336  "}\n"
337 
338  "\nExamples:\n"
339  + HelpExampleCli("waitforblockheight", "\"100\", 1000")
340  + HelpExampleRpc("waitforblockheight", "\"100\", 1000")
341  );
342  int timeout = 0;
343 
344  int height = params[0].get_int();
345 
346  if (params.size() > 1)
347  timeout = params[1].get_int();
348 
349  CUpdatedBlock block;
350  {
351  std::unique_lock<std::mutex> lock(cs_blockchange);
352  if(timeout)
353  cond_blockchange.wait_for(lock, std::chrono::milliseconds(timeout), [&height]{return latestblock.height >= height || !IsRPCRunning();});
354  else
355  cond_blockchange.wait(lock, [&height]{return latestblock.height >= height || !IsRPCRunning(); });
356  block = latestblock;
357  }
359  ret.push_back(Pair("hash", block.hash.GetHex()));
360  ret.push_back(Pair("height", block.height));
361  return ret;
362 }
363 
364 UniValue getdifficulty(const UniValue& params, bool fHelp)
365 {
366  if (fHelp || params.size() != 0)
367  throw std::runtime_error(
368  "getdifficulty\n"
369  "\nReturns the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
370  "\nResult:\n"
371  "n.nnn (numeric) the proof-of-work difficulty as a multiple of the minimum difficulty.\n"
372  "\nExamples:\n" +
373  HelpExampleCli("getdifficulty", "") + HelpExampleRpc("getdifficulty", ""));
374 
375  LOCK(cs_main);
376  return GetDifficulty();
377 }
378 
379 
380 UniValue mempoolToJSON(bool fVerbose = false)
381 {
382  if (fVerbose) {
383  LOCK(mempool.cs);
385  for (const PAIRTYPE(uint256, CTxMemPoolEntry) & entry : mempool.mapTx) {
386  const uint256& hash = entry.first;
387  const CTxMemPoolEntry& e = entry.second;
388  UniValue info(UniValue::VOBJ);
389  info.push_back(Pair("size", (int)e.GetTxSize()));
390  info.push_back(Pair("fee", ValueFromAmount(e.GetFee())));
391  info.push_back(Pair("time", e.GetTime()));
392  info.push_back(Pair("height", (int)e.GetHeight()));
393  info.push_back(Pair("startingpriority", e.GetPriority(e.GetHeight())));
394  info.push_back(Pair("currentpriority", e.GetPriority(chainActive.Height())));
395  const CTransaction& tx = e.GetTx();
396  std::set<std::string> setDepends;
397  for (const CTxIn& txin : tx.vin) {
398  if (mempool.exists(txin.prevout.hash))
399  setDepends.insert(txin.prevout.hash.ToString());
400  }
401 
402  UniValue depends(UniValue::VARR);
403  for (const std::string& dep : setDepends) {
404  depends.push_back(dep);
405  }
406 
407  info.push_back(Pair("depends", depends));
408  o.push_back(Pair(hash.ToString(), info));
409  }
410  return o;
411  } else {
412  std::vector<uint256> vtxid;
413  mempool.queryHashes(vtxid);
414 
416  for (const uint256& hash : vtxid)
417  a.push_back(hash.ToString());
418 
419  return a;
420  }
421 }
422 
423 UniValue getrawmempool(const UniValue& params, bool fHelp)
424 {
425  if (fHelp || params.size() > 1)
426  throw std::runtime_error(
427  "getrawmempool ( verbose )\n"
428  "\nReturns all transaction ids in memory pool as a json array of string transaction ids.\n"
429  "\nArguments:\n"
430  "1. verbose (boolean, optional, default=false) true for a json object, false for array of transaction ids\n"
431  "\nResult: (for verbose = false):\n"
432  "[ (json array of string)\n"
433  " \"transactionid\" (string) The transaction id\n"
434  " ,...\n"
435  "]\n"
436  "\nResult: (for verbose = true):\n"
437  "{ (json object)\n"
438  " \"transactionid\" : { (json object)\n"
439  " \"size\" : n, (numeric) transaction size in bytes\n"
440  " \"fee\" : n, (numeric) transaction fee in PRCY\n"
441  " \"time\" : n, (numeric) local time transaction entered pool in seconds since 1 Jan 1970 GMT\n"
442  " \"height\" : n, (numeric) block height when transaction entered pool\n"
443  " \"startingpriority\" : n, (numeric) priority when transaction entered pool\n"
444  " \"currentpriority\" : n, (numeric) transaction priority now\n"
445  " \"depends\" : [ (array) unconfirmed transactions used as inputs for this transaction\n"
446  " \"transactionid\", (string) parent transaction id\n"
447  " ... ]\n"
448  " }, ...\n"
449  "]\n"
450  "\nExamples\n" +
451  HelpExampleCli("getrawmempool", "true") + HelpExampleRpc("getrawmempool", "true"));
452 
453  LOCK(cs_main);
454 
455  bool fVerbose = false;
456  if (params.size() > 0)
457  fVerbose = params[0].get_bool();
458 
459  return mempoolToJSON(fVerbose);
460 }
461 
462 
463 UniValue getblockhash(const UniValue& params, bool fHelp)
464 {
465  if (fHelp || params.size() != 1)
466  throw std::runtime_error(
467  "getblockhash index\n"
468  "\nReturns hash of block in best-block-chain at index provided.\n"
469  "\nArguments:\n"
470  "1. index (numeric, required) The block index\n"
471  "\nResult:\n"
472  "\"hash\" (string) The block hash\n"
473  "\nExamples:\n" +
474  HelpExampleCli("getblockhash", "1000") + HelpExampleRpc("getblockhash", "1000"));
475 
476  LOCK(cs_main);
477 
478  int nHeight = params[0].get_int();
479  if (nHeight < 0 || nHeight > chainActive.Height())
480  throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
481 
482  CBlockIndex* pblockindex = chainActive[nHeight];
483  return pblockindex->GetBlockHash().GetHex();
484 }
485 
486 UniValue getblock(const UniValue& params, bool fHelp)
487 {
488  if (fHelp || params.size() < 1 || params.size() > 2)
489  throw std::runtime_error(
490  "getblock \"hash\" ( verbose )\n"
491  "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash'.\n"
492  "If verbose is true, returns an Object with information about block <hash>.\n"
493  "\nArguments:\n"
494  "1. \"hash\" (string, required) The block hash\n"
495  "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
496  "\nResult (for verbose = true):\n"
497  "{\n"
498  " \"hash\" : \"hash\", (string) the block hash (same as provided)\n"
499  " \"confirmations\" : n, (numeric) The number of confirmations, or -1 if the block is not on the main chain\n"
500  " \"size\" : n, (numeric) The block size\n"
501  " \"height\" : n, (numeric) The block height or index\n"
502  " \"version\" : n, (numeric) The block version\n"
503  " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
504  " \"tx\" : [ (array of string) The transaction ids\n"
505  " \"transactionid\" (string) The transaction id\n"
506  " ,...\n"
507  " ],\n"
508  " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
509  " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
510  " \"nonce\" : n, (numeric) The nonce\n"
511  " \"bits\" : \"1d00ffff\", (string) The bits\n"
512  " \"difficulty\" : x.xxx, (numeric) The difficulty\n"
513  " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
514  " \"nextblockhash\" : \"hash\" (string) The hash of the next block\n"
515  " \"moneysupply\" : \"supply\" (numeric) The money supply when this block was added to the blockchain\n"
516  "}\n"
517  "\nResult (for verbose=false):\n"
518  "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash'.\n"
519  "\nExamples:\n" +
520  HelpExampleCli("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") + HelpExampleRpc("getblock", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\""));
521 
522  std::string strHash = params[0].get_str();
523  uint256 hash(uint256S(strHash));
524 
525  bool fVerbose = true;
526  if (params.size() > 1)
527  fVerbose = params[1].get_bool();
528 
529  if (mapBlockIndex.count(hash) == 0)
530  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
531 
532  CBlock block;
533  CBlockIndex* pblockindex = mapBlockIndex[hash];
534 
535  if (!ReadBlockFromDisk(block, pblockindex))
536  throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
537 
538  if (!fVerbose) {
539  CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
540  ssBlock << block;
541  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
542  return strHex;
543  }
544 
545  return blockToJSON(block, pblockindex);
546 }
547 
548 UniValue getblockheader(const UniValue& params, bool fHelp)
549 {
550  if (fHelp || params.size() < 1 || params.size() > 2)
551  throw std::runtime_error(
552  "getblockheader \"hash\" ( verbose )\n"
553  "\nIf verbose is false, returns a string that is serialized, hex-encoded data for block 'hash' header.\n"
554  "If verbose is true, returns an Object with information about block <hash> header.\n"
555  "\nArguments:\n"
556  "1. \"hash\" (string, required) The block hash\n"
557  "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
558  "\nResult (for verbose = true):\n"
559  "{\n"
560  " \"version\" : n, (numeric) The block version\n"
561  " \"previousblockhash\" : \"hash\", (string) The hash of the previous block\n"
562  " \"merkleroot\" : \"xxxx\", (string) The merkle root\n"
563  " \"time\" : ttt, (numeric) The block time in seconds since epoch (Jan 1 1970 GMT)\n"
564  " \"mediantime\" : ttt, (numeric) The median block time in seconds since epoch (Jan 1 1970 GMT)\n"
565  " \"nonce\" : n, (numeric) The nonce\n"
566  " \"bits\" : \"1d00ffff\", (string) The bits\n"
567  "}\n"
568  "\nResult (for verbose=false):\n"
569  "\"data\" (string) A string that is serialized, hex-encoded data for block 'hash' header.\n"
570  "\nExamples:\n" +
571  HelpExampleCli("getblockheader", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\"") + HelpExampleRpc("getblockheader", "\"00000000000fd08c2fb661d2fcb0d49abb3a91e5f27082ce64feed3b4dede2e2\""));
572 
573  std::string strHash = params[0].get_str();
574  uint256 hash(uint256S(strHash));
575 
576  bool fVerbose = true;
577  if (params.size() > 1)
578  fVerbose = params[1].get_bool();
579 
580  if (mapBlockIndex.count(hash) == 0)
581  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
582 
583  CBlock block;
584  CBlockIndex* pblockindex = mapBlockIndex[hash];
585 
586  if (!ReadBlockFromDisk(block, pblockindex))
587  throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
588 
589  if (!fVerbose) {
590  CDataStream ssBlock(SER_NETWORK, PROTOCOL_VERSION);
591  ssBlock << pblockindex->GetBlockHeader();
592  std::string strHex = HexStr(ssBlock.begin(), ssBlock.end());
593  return strHex;
594  }
595 
596  return blockheaderToJSON(pblockindex);
597 }
598 
599 UniValue gettxoutsetinfo(const UniValue& params, bool fHelp)
600 {
601  if (fHelp || params.size() != 0)
602  throw std::runtime_error(
603  "gettxoutsetinfo\n"
604  "\nReturns statistics about the unspent transaction output set.\n"
605  "Note this call may take some time.\n"
606  "\nResult:\n"
607  "{\n"
608  " \"height\":n, (numeric) The current block height (index)\n"
609  " \"bestblock\": \"hex\", (string) the best block hash hex\n"
610  " \"transactions\": n, (numeric) The number of transactions\n"
611  " \"txouts\": n, (numeric) The number of output transactions\n"
612  " \"bytes_serialized\": n, (numeric) The serialized size\n"
613  " \"hash_serialized\": \"hash\", (string) The serialized hash\n"
614  " \"total_amount\": x.xxx (numeric) The total amount\n"
615  "}\n"
616  "\nExamples:\n" +
617  HelpExampleCli("gettxoutsetinfo", "") + HelpExampleRpc("gettxoutsetinfo", ""));
618 
620 
621  CCoinsStats stats;
623  if (pcoinsTip->GetStats(stats)) {
624  ret.push_back(Pair("height", (int64_t)stats.nHeight));
625  ret.push_back(Pair("bestblock", stats.hashBlock.GetHex()));
626  ret.push_back(Pair("transactions", (int64_t)stats.nTransactions));
627  ret.push_back(Pair("txouts", (int64_t)stats.nTransactionOutputs));
628  ret.push_back(Pair("bytes_serialized", (int64_t)stats.nSerializedSize));
629  ret.push_back(Pair("hash_serialized", stats.hashSerialized.GetHex()));
630  ret.push_back(Pair("total_amount", ValueFromAmount(chainActive.Tip()->nMoneySupply)));
631  }
632  return ret;
633 }
634 
635 UniValue gettxout(const UniValue& params, bool fHelp)
636 {
637  if (fHelp || params.size() < 2 || params.size() > 3)
638  throw std::runtime_error(
639  "gettxout \"txid\" n ( includemempool )\n"
640  "\nReturns details about an unspent transaction output.\n"
641  "\nArguments:\n"
642  "1. \"txid\" (string, required) The transaction id\n"
643  "2. n (numeric, required) vout value\n"
644  "3. includemempool (boolean, optional) Whether to included the mem pool\n"
645  "\nResult:\n"
646  "{\n"
647  " \"bestblock\" : \"hash\", (string) the block hash\n"
648  " \"confirmations\" : n, (numeric) The number of confirmations\n"
649  " \"value\" : x.xxx, (numeric) The transaction value in PRCY\n"
650  " \"scriptPubKey\" : { (json object)\n"
651  " \"asm\" : \"code\", (string) \n"
652  " \"hex\" : \"hex\", (string) \n"
653  " \"reqSigs\" : n, (numeric) Number of required signatures\n"
654  " \"type\" : \"pubkeyhash\", (string) The type, eg pubkeyhash\n"
655  " \"addresses\" : [ (array of string) array of prcycoin addresses\n"
656  " \"prcycoinaddress\" (string) prcycoin address\n"
657  " ,...\n"
658  " ]\n"
659  " },\n"
660  " \"version\" : n, (numeric) The version\n"
661  " \"coinbase\" : true|false (boolean) Coinbase or not\n"
662  "}\n"
663 
664  "\nExamples:\n"
665  "\nGet unspent transactions\n" +
666  HelpExampleCli("listunspent", "") +
667  "\nView the details\n" + HelpExampleCli("gettxout", "\"txid\" 1") +
668  "\nAs a json rpc call\n" + HelpExampleRpc("gettxout", "\"txid\", 1"));
669 
670  LOCK(cs_main);
671 
673 
674  std::string strHash = params[0].get_str();
675  uint256 hash(uint256S(strHash));
676  int n = params[1].get_int();
677  bool fMempool = true;
678  if (params.size() > 2)
679  fMempool = params[2].get_bool();
680 
681  CCoins coins;
682  if (fMempool) {
683  LOCK(mempool.cs);
685  if (!view.GetCoins(hash, coins))
686  return NullUniValue;
687  mempool.pruneSpent(hash, coins); // TODO: this should be done by the CCoinsViewMemPool
688  } else {
689  if (!pcoinsTip->GetCoins(hash, coins))
690  return NullUniValue;
691  }
692  if (n < 0 || (unsigned int)n >= coins.vout.size() || coins.vout[n].IsNull())
693  return NullUniValue;
694 
695  BlockMap::iterator it = mapBlockIndex.find(pcoinsTip->GetBestBlock());
696  CBlockIndex* pindex = it->second;
697  ret.push_back(Pair("bestblock", pindex->GetBlockHash().GetHex()));
698  if ((unsigned int)coins.nHeight == MEMPOOL_HEIGHT)
699  ret.push_back(Pair("confirmations", 0));
700  else
701  ret.push_back(Pair("confirmations", pindex->nHeight - coins.nHeight + 1));
702  ret.push_back(Pair("value", ValueFromAmount(coins.vout[n].nValue)));
704  ScriptPubKeyToJSON(coins.vout[n].scriptPubKey, o, true);
705  ret.push_back(Pair("scriptPubKey", o));
706  ret.push_back(Pair("version", coins.nVersion));
707  ret.push_back(Pair("coinbase", coins.fCoinBase));
708 
709  return ret;
710 }
711 
712 UniValue verifychain(const UniValue& params, bool fHelp)
713 {
714  if (fHelp || params.size() > 1)
715  throw std::runtime_error(
716  "verifychain ( numblocks )\n"
717  "\nVerifies blockchain database.\n"
718  "\nArguments:\n"
719  "1. numblocks (numeric, optional, default=288, 0=all) The number of blocks to check.\n"
720  "\nResult:\n"
721  "true|false (boolean) Verified or not\n"
722  "\nExamples:\n" +
723  HelpExampleCli("verifychain", "") + HelpExampleRpc("verifychain", ""));
724 
725  LOCK(cs_main);
726 
727  int nCheckLevel = 4;
728  int nCheckDepth = GetArg("-checkblocks", 288);
729  if (params.size() > 0)
730  nCheckDepth = params[0].get_int();
731 
732  fVerifyingBlocks = true;
733  bool fVerified = CVerifyDB().VerifyDB(pcoinsTip, nCheckLevel, nCheckDepth);
734  fVerifyingBlocks = false;
735 
736  return fVerified;
737 }
738 
740 static UniValue SoftForkMajorityDesc(int minVersion, CBlockIndex* pindex, int nRequired)
741 {
742  int nFound = 0;
743  CBlockIndex* pstart = pindex;
744  for (int i = 0; i < Params().ToCheckBlockUpgradeMajority() && pstart != NULL; i++)
745  {
746  if (pstart->nVersion >= minVersion)
747  ++nFound;
748  pstart = pstart->pprev;
749  }
751  rv.push_back(Pair("status", nFound >= nRequired));
752  rv.push_back(Pair("found", nFound));
753  rv.push_back(Pair("required", nRequired));
754  rv.push_back(Pair("window", Params().ToCheckBlockUpgradeMajority()));
755  return rv;
756 }
757 static UniValue SoftForkDesc(const std::string &name, int version, CBlockIndex* pindex)
758 {
760  rv.push_back(Pair("id", name));
761  rv.push_back(Pair("version", version));
762  rv.push_back(Pair("enforce", SoftForkMajorityDesc(version, pindex, Params().EnforceBlockUpgradeMajority())));
763  rv.push_back(Pair("reject", SoftForkMajorityDesc(version, pindex, Params().RejectBlockOutdatedMajority())));
764  return rv;
765 }
766 
767 UniValue getblockchaininfo(const UniValue& params, bool fHelp)
768 {
769  if (fHelp || params.size() != 0)
770  throw std::runtime_error(
771  "getblockchaininfo\n"
772  "Returns an object containing various state info regarding block chain processing.\n"
773  "\nResult:\n"
774  "{\n"
775  " \"chain\": \"xxxx\", (string) current network name (main, test, regtest)\n"
776  " \"blocks\": xxxxxx, (numeric) the current number of blocks processed in the server\n"
777  " \"headers\": xxxxxx, (numeric) the current number of headers we have validated\n"
778  " \"bestblockhash\": \"...\", (string) the hash of the currently best block\n"
779  " \"difficulty\": xxxxxx, (numeric) the current difficulty\n"
780  " \"verificationprogress\": xxxx, (numeric) estimate of verification progress [0..1]\n"
781  " \"chainwork\": \"xxxx\" (string) total amount of work in active chain, in hexadecimal\n"
782  " \"softforks\": [ (array) status of softforks in progress\n"
783  " {\n"
784  " \"id\": \"xxxx\", (string) name of softfork\n"
785  " \"version\": xx, (numeric) block version\n"
786  " \"enforce\": { (object) progress toward enforcing the softfork rules for new-version blocks\n"
787  " \"status\": xx, (boolean) true if threshold reached\n"
788  " \"found\": xx, (numeric) number of blocks with the new version found\n"
789  " \"required\": xx, (numeric) number of blocks required to trigger\n"
790  " \"window\": xx, (numeric) maximum size of examined window of recent blocks\n"
791  " },\n"
792  " \"reject\": { ... } (object) progress toward rejecting pre-softfork blocks (same fields as \"enforce\")\n"
793  " }, ...\n"
794  " ]\n"
795  "}\n"
796  "\nExamples:\n" +
797  HelpExampleCli("getblockchaininfo", "") + HelpExampleRpc("getblockchaininfo", ""));
798 
799  LOCK(cs_main);
800 
802  obj.push_back(Pair("chain", Params().NetworkIDString()));
803  obj.push_back(Pair("blocks", (int)chainActive.Height()));
804  obj.push_back(Pair("headers", pindexBestHeader ? pindexBestHeader->nHeight : -1));
805  obj.push_back(Pair("bestblockhash", chainActive.Tip()->GetBlockHash().GetHex()));
806  obj.push_back(Pair("difficulty", (double)GetDifficulty()));
807  obj.push_back(Pair("verificationprogress", Checkpoints::GuessVerificationProgress(chainActive.Tip())));
808  obj.push_back(Pair("chainwork", chainActive.Tip()->nChainWork.GetHex()));
809  CBlockIndex* tip = chainActive.Tip();
810  UniValue softforks(UniValue::VARR);
811  softforks.push_back(SoftForkDesc("bip65", 5, tip));
812  obj.push_back(Pair("softforks", softforks));
813  return obj;
814 }
815 
818  bool operator()(const CBlockIndex* a, const CBlockIndex* b) const
819  {
820  /* Make sure that unequal blocks with the same height do not compare
821  equal. Use the pointers themselves to make a distinction. */
822 
823  if (a->nHeight != b->nHeight)
824  return (a->nHeight > b->nHeight);
825 
826  return a < b;
827  }
828 };
829 
830 UniValue getchaintips(const UniValue& params, bool fHelp)
831 {
832  if (fHelp || params.size() != 0)
833  throw std::runtime_error(
834  "getchaintips\n"
835  "Return information about all known tips in the block tree,"
836  " including the main chain as well as orphaned branches.\n"
837  "\nResult:\n"
838  "[\n"
839  " {\n"
840  " \"height\": xxxx, (numeric) height of the chain tip\n"
841  " \"hash\": \"xxxx\", (string) block hash of the tip\n"
842  " \"branchlen\": 0 (numeric) zero for main chain\n"
843  " \"status\": \"active\" (string) \"active\" for the main chain\n"
844  " },\n"
845  " {\n"
846  " \"height\": xxxx,\n"
847  " \"hash\": \"xxxx\",\n"
848  " \"branchlen\": 1 (numeric) length of branch connecting the tip to the main chain\n"
849  " \"status\": \"xxxx\" (string) status of the chain (active, valid-fork, valid-headers, headers-only, invalid)\n"
850  " }\n"
851  "]\n"
852  "Possible values for status:\n"
853  "1. \"invalid\" This branch contains at least one invalid block\n"
854  "2. \"headers-only\" Not all blocks for this branch are available, but the headers are valid\n"
855  "3. \"valid-headers\" All blocks are available for this branch, but they were never fully validated\n"
856  "4. \"valid-fork\" This branch is not part of the active chain, but is fully validated\n"
857  "5. \"active\" This is the tip of the active main chain, which is certainly valid\n"
858  "\nExamples:\n" +
859  HelpExampleCli("getchaintips", "") + HelpExampleRpc("getchaintips", ""));
860 
861  LOCK(cs_main);
862 
863  /* Build up a list of chain tips. We start with the list of all
864  known blocks, and successively remove blocks that appear as pprev
865  of another block. */
866  std::set<const CBlockIndex*, CompareBlocksByHeight> setTips;
867  for (const PAIRTYPE(const uint256, CBlockIndex*) & item : mapBlockIndex)
868  if (item.second)
869  setTips.insert(item.second);
870  for (const PAIRTYPE(const uint256, CBlockIndex*) & item : mapBlockIndex) {
871  if (item.second) {
872  const CBlockIndex* pprev = item.second->pprev;
873  if (pprev)
874  setTips.erase(pprev);
875  }
876  }
877 
878  // Always report the currently active tip.
879  setTips.insert(chainActive.Tip());
880 
881  /* Construct the output array. */
883  for (const CBlockIndex* block : setTips) {
885  obj.push_back(Pair("height", block->nHeight));
886  obj.push_back(Pair("hash", block->phashBlock->GetHex()));
887 
888  const int branchLen = block->nHeight - chainActive.FindFork(block)->nHeight;
889  obj.push_back(Pair("branchlen", branchLen));
890 
891  std::string status;
892  if (chainActive.Contains(block)) {
893  // This block is part of the currently active chain.
894  status = "active";
895  } else if (block->nStatus & BLOCK_FAILED_MASK) {
896  // This block or one of its ancestors is invalid.
897  status = "invalid";
898  } else if (block->nChainTx == 0) {
899  // This block cannot be connected because full block data for it or one of its parents is missing.
900  status = "headers-only";
901  } else if (block->IsValid(BLOCK_VALID_SCRIPTS)) {
902  // This block is fully validated, but no longer part of the active chain. It was probably the active block once, but was reorganized.
903  status = "valid-fork";
904  } else if (block->IsValid(BLOCK_VALID_TREE)) {
905  // The headers for this block are valid, but it has not been validated. It was probably never part of the most-work chain.
906  status = "valid-headers";
907  } else {
908  // No clue.
909  status = "unknown";
910  }
911  obj.push_back(Pair("status", status));
912 
913  res.push_back(obj);
914  }
915 
916  return res;
917 }
918 
919 UniValue getfeeinfo(const UniValue& params, bool fHelp)
920 {
921  if (fHelp || params.size() != 1)
922  throw std::runtime_error(
923  "getfeeinfo blocks\n"
924  "\nReturns details of transaction fees over the last n blocks.\n"
925 
926  "\nArguments:\n"
927  "1. blocks (int, required) the number of blocks to get transaction data from\n"
928 
929  "\nResult:\n"
930  "{\n"
931  " \"txcount\": xxxxx (numeric) Current tx count\n"
932  " \"txbytes\": xxxxx (numeric) Sum of all tx sizes\n"
933  " \"ttlfee\": xxxxx (numeric) Sum of all fees\n"
934  " \"feeperkb\": xxxxx (numeric) Average fee per kb over the block range\n"
935  " \"rec_highpriorityfee_perkb\": xxxxx (numeric) Recommended fee per kb to use for a high priority tx\n"
936  "}\n"
937 
938  "\nExamples:\n" +
939  HelpExampleCli("getfeeinfo", "5") + HelpExampleRpc("getfeeinfo", "5"));
940 
941  int nBlocks = params[0].get_int();
942  int nBestHeight;
943  {
944  LOCK(cs_main);
945  nBestHeight = chainActive.Height();
946  }
947  int nStartHeight = nBestHeight - nBlocks;
948  if (nBlocks < 0 || nStartHeight <= 0)
949  throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid start height");
950 
951  UniValue newParams(UniValue::VARR);
952  newParams.push_back(UniValue(nStartHeight));
953  newParams.push_back(UniValue(nBlocks));
954  newParams.push_back(UniValue(true)); // fFeeOnly
955 
956  return getblockindexstats(newParams, false);
957 }
958 
960 {
962  ret.push_back(Pair("size", (int64_t) mempool.size()));
963  ret.push_back(Pair("bytes", (int64_t) mempool.GetTotalTxSize()));
964 
965  //ret.push_back(Pair("usage", (int64_t) mempool.DynamicMemoryUsage()));
966  return ret;
967 }
968 
969 UniValue getmempoolinfo(const UniValue& params, bool fHelp)
970 {
971  if (fHelp || params.size() != 0)
972  throw std::runtime_error(
973  "getmempoolinfo\n"
974  "\nReturns details on the active state of the TX memory pool.\n"
975  "\nResult:\n"
976  "{\n"
977  " \"size\": xxxxx (numeric) Current tx count\n"
978  " \"bytes\": xxxxx (numeric) Sum of all tx sizes\n"
979  "}\n"
980  "\nExamples:\n" +
981  HelpExampleCli("getmempoolinfo", "") + HelpExampleRpc("getmempoolinfo", ""));
982 
983  return mempoolInfoToJSON();
984 }
985 
986 UniValue invalidateblock(const UniValue& params, bool fHelp)
987 {
988  if (fHelp || params.size() != 1)
989  throw std::runtime_error(
990  "invalidateblock \"hash\"\n"
991  "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n"
992  "\nArguments:\n"
993  "1. hash (string, required) the hash of the block to mark as invalid\n"
994  "\nResult:\n"
995  "\nExamples:\n" +
996  HelpExampleCli("invalidateblock", "\"blockhash\"") + HelpExampleRpc("invalidateblock", "\"blockhash\""));
997 
998  std::string strHash = params[0].get_str();
999  uint256 hash(uint256S(strHash));
1000  CValidationState state;
1001 
1002  {
1003  LOCK(cs_main);
1004  if (mapBlockIndex.count(hash) == 0)
1005  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1006 
1007  CBlockIndex* pblockindex = mapBlockIndex[hash];
1008  InvalidateBlock(state, pblockindex);
1009  }
1010 
1011  if (state.IsValid()) {
1012  ActivateBestChain(state);
1013  }
1014 
1015  if (!state.IsValid()) {
1017  }
1018 
1019  return "Done";
1020 }
1021 
1022 UniValue resyncfrom(const UniValue& params, bool fHelp)
1023 {
1024  if (fHelp || params.size() != 1)
1025  throw std::runtime_error(
1026  "resyncfrom \"block height\"\n"
1027  "\nPermanently marks a block as invalid, as if it violated a consensus rule.\n"
1028  "\nArguments:\n"
1029  "1. height (numeric, required) the hash of the block to mark as invalid\n"
1030  "\nResult:\n"
1031  "\nExamples:\n" +
1032  HelpExampleCli("resyncfrom", "\"height\"") + HelpExampleRpc("resyncfrom", "\"100000\""));
1033 
1034  int height = params[0].get_int();
1035  CValidationState state;
1036 
1037  {
1038  LOCK(cs_main);
1039  if (chainActive.Height() < height)
1040  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid block height");
1041 
1042  CBlockIndex* pblockindex = chainActive[height];
1043  InvalidateBlock(state, pblockindex);
1044  }
1045 
1046  if (state.IsValid()) {
1047  ActivateBestChain(state);
1048  }
1049 
1050  if (!state.IsValid()) {
1052  }
1053 
1054  return NullUniValue;
1055 }
1056 
1057 UniValue reconsiderblock(const UniValue& params, bool fHelp)
1058 {
1059  if (fHelp || params.size() != 1)
1060  throw std::runtime_error(
1061  "reconsiderblock \"hash\"\n"
1062  "\nRemoves invalidity status of a block and its descendants, reconsider them for activation.\n"
1063  "This can be used to undo the effects of invalidateblock.\n"
1064  "\nArguments:\n"
1065  "1. hash (string, required) the hash of the block to reconsider\n"
1066  "\nResult:\n"
1067  "\nExamples:\n" +
1068  HelpExampleCli("reconsiderblock", "\"blockhash\"") + HelpExampleRpc("reconsiderblock", "\"blockhash\""));
1069 
1070  std::string strHash = params[0].get_str();
1071  uint256 hash(uint256S(strHash));
1072  CValidationState state;
1073 
1074  {
1075  LOCK(cs_main);
1076  if (mapBlockIndex.count(hash) == 0)
1077  throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
1078 
1079  CBlockIndex* pblockindex = mapBlockIndex[hash];
1080  ReconsiderBlock(state, pblockindex);
1081  }
1082 
1083  if (state.IsValid()) {
1084  ActivateBestChain(state);
1085  }
1086 
1087  if (!state.IsValid()) {
1089  }
1090 
1091  return "Done";
1092 }
1093 
1094 UniValue getinvalid (const UniValue& params, bool fHelp)
1095 {
1096  if (fHelp || params.size() > 1)
1097  throw std::runtime_error(
1098  "getinvalid \n"
1099  "\nGet a summary of invalidated outpoints.\n"
1100  "\nArguments:\n"
1101  "1. all (string, optional) return a full list of outpoints even if they are spent\n"
1102  "\nExamples:\n" +
1103  HelpExampleCli("getinvalid", "\"all\"") + HelpExampleRpc("getinvalid", "\"all\""));
1104 
1105  std::string strCommand;
1106  if (params.size() == 1){
1107  strCommand = params[0].get_str();
1108  }
1109 
1110  bool fShowAll = false;
1111  if (strCommand == "all")
1112  fShowAll = true;
1113 
1114  CAmount nUnspent = 0;
1115  CAmount nMint = 0;
1116  CAmount nMixedValid = 0;
1117  std::map<CBitcoinAddress, CAmount> mapBanAddress;
1118  std::map<COutPoint, int> mapMixedValid;
1119 
1120  UniValue ret(UniValue::VARR);
1121  for (auto it : mapInvalidOutPoints) {
1122  COutPoint out = it.first;
1123  //Get the tx that the outpoint is from
1124  CTransaction tx;
1125  uint256 hashBlock;
1126  if (!GetTransaction(out.hash, tx, hashBlock, true)) {
1127  continue;
1128  }
1129 
1130  UniValue objTx(UniValue::VOBJ);
1131  objTx.push_back(Pair("inv_out", it.first.ToString()));
1132 
1133  CAmount nValue = tx.vout[out.n].nValue;
1134  objTx.push_back(Pair("value", FormatMoney(nValue)));
1135 
1136  //Search the txin's to see if any of them are "valid".
1137  UniValue objMixedValid(UniValue::VOBJ);
1138 
1139  //if some of the other inputs are valid
1140  for(CTxIn in2 : tx.vin) {
1141  //See if this is already accounted for
1142  if(mapInvalidOutPoints.count(in2.prevout) || mapMixedValid.count(in2.prevout))
1143  continue;
1144 
1145  CTransaction txPrev;
1146  uint256 hashBlock;
1147  if(!GetTransaction(in2.prevout.hash, txPrev, hashBlock, true))
1148  continue;
1149 
1150  //This is a valid outpoint that mixed with an invalid outpoint. Investigate this person.
1151  //Information leakage, not covering their tracks well enough
1152  CAmount nValid = txPrev.vout[in2.prevout.n].nValue;
1153  objMixedValid.push_back(Pair(FormatMoney(nValid), in2.prevout.ToString()));
1154 
1155  nMixedValid += nValid;
1156  mapMixedValid[in2.prevout] = 1;
1157  }
1158 
1159  //Check whether this bad outpoint has been spent
1160  bool fSpent = false;
1161  CCoinsViewCache cache(pcoinsTip);
1162  const CCoins* coins = cache.AccessCoins(out.hash);
1163  if (!coins || !coins->IsAvailable(out.n))
1164  fSpent = true;
1165 
1166  objTx.push_back(Pair("spent", fSpent));
1167  if (!objMixedValid.empty())
1168  objTx.push_back(Pair("mixed_with_valid", objMixedValid));
1169 
1170  CScript scriptPubKey = tx.vout[out.n].scriptPubKey;
1171  if (!fSpent) {
1172  CTxDestination dest;
1173  if (!ExtractDestination(scriptPubKey, dest)) {
1174  continue;
1175  }
1176  CBitcoinAddress address(dest);
1177  mapBanAddress[address] += nValue;
1178  nUnspent += nValue;
1179  }
1180 
1181  if (fSpent && !fShowAll)
1182  continue;
1183 
1184  ret.push_back(objTx);
1185  }
1186 
1187  UniValue objAddresses(UniValue::VOBJ);
1188  for (auto it : mapBanAddress)
1189  objAddresses.push_back(Pair(it.first.ToString(), FormatMoney(it.second)));
1190 
1191  UniValue obj(UniValue::VOBJ);
1192  obj.push_back(Pair("addresses_with_invalid", objAddresses));
1193  obj.push_back(Pair("total_unspent", FormatMoney(nUnspent)));
1194  obj.push_back(Pair("total_minted", FormatMoney(nMint)));
1195  obj.push_back(Pair("total_valid_used", FormatMoney(nMixedValid)));
1196 
1197  ret.push_back(obj);
1198  return ret;
1199 }
1200 
1201 UniValue setmaxreorgdepth(const UniValue& params, bool fHelp)
1202 {
1203  if (fHelp || params.size() != 1)
1204  throw std::runtime_error(
1205  "setmaxreorgdepth <value>\n"
1206  "\nSet max reorganization depth to a value.\n"
1207  "\nArguments:\n"
1208  "1. num (numeric, required) the number of blocks\n"
1209  "\nResult:\n"
1210  "\nExamples:\n" +
1211  HelpExampleCli("setmaxreorgdepth", "100") + HelpExampleRpc("setmaxreorgdepth", "100"));
1212 
1213  int num = params[0].get_int();
1214  if (num <= 5)
1215  throw std::runtime_error("Invalid number");
1216  {
1217  LOCK(cs_main);
1218  Params().ChangeMaxReorg(num);
1219  }
1220 
1221  return NullUniValue;
1222 }
1223 
1224 UniValue getlastpoablock(const UniValue& params, bool fHelp)
1225 {
1226  if (fHelp || params.size() != 0)
1227  throw std::runtime_error(
1228  "getlastpoablock\n"
1229  "\nReturns all details of the last PoA block\n"
1230  "\nResult:\n"
1231  "\"hash\" (string) The last PoA block hash\n"
1232  "\nExamples:\n" +
1233  HelpExampleCli("getlastpoablockhash", "") + HelpExampleRpc("getlastpoablockhash", ""));
1234 
1235  LOCK(cs_main);
1236 
1237  //Find the previous PoA block
1238  CBlock block;
1239  CBlockIndex* pindex = chainActive.Tip();
1240  while (pindex->nHeight > Params().START_POA_BLOCK()) {
1241  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
1242  break;
1243  }
1244  pindex = pindex->pprev;
1245  }
1246  ReadBlockFromDisk(block, pindex);
1247 
1248  return blockToJSON(block, pindex);
1249 }
1250 
1251 UniValue getlastpoablockhash(const UniValue& params, bool fHelp)
1252 {
1253  if (fHelp || params.size() != 0)
1254  throw std::runtime_error(
1255  "getlastpoablockhash\n"
1256  "\nReturns hash of the last PoA block.\n"
1257  "\nResult:\n"
1258  "\"hash\" (string) The last PoA block hash\n"
1259  "\nExamples:\n" +
1260  HelpExampleCli("getlastpoablockhash", "") + HelpExampleRpc("getlastpoablockhash", ""));
1261 
1262  LOCK(cs_main);
1263 
1264  //Find the previous PoA block
1265  CBlockIndex* pindex = chainActive.Tip();
1266  while (pindex->nHeight > Params().START_POA_BLOCK()) {
1267  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
1268  break;
1269  }
1270  pindex = pindex->pprev;
1271  }
1272 
1273  return pindex->GetBlockHash().GetHex();
1274 }
1275 
1276 UniValue getlastpoablockheight(const UniValue& params, bool fHelp)
1277 {
1278  if (fHelp || params.size() != 0)
1279  throw std::runtime_error(
1280  "getlastpoablockheight\n"
1281  "\nReturns block height of the last PoA block.\n"
1282  "\nResult:\n"
1283  "\"height\" (numeric) The last PoA block height\n"
1284  "\nExamples:\n" +
1285  HelpExampleCli("getlastpoablockheight", "") + HelpExampleRpc("getlastpoablockheight", ""));
1286 
1287  LOCK(cs_main);
1288 
1289  //Find the previous PoA block
1290  CBlockIndex* pindex = chainActive.Tip();
1291  while (pindex->nHeight > Params().START_POA_BLOCK()) {
1292  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
1293  break;
1294  }
1295  pindex = pindex->pprev;
1296  }
1297 
1298  return pindex->nHeight;
1299 }
1300 
1301 UniValue getlastpoablocktime(const UniValue& params, bool fHelp)
1302 {
1303  if (fHelp || params.size() != 0)
1304  throw std::runtime_error(
1305  "getlastpoablocktime\n"
1306  "\nReturns the time in seconds since epoch (Jan 1 1970 GMT) of the last PoA block.\n"
1307  "\nResult:\n"
1308  "\"time\" (numeric) The last PoA block time in seconds since epoch (Jan 1 1970 GMT)\n"
1309  "\nExamples:\n" +
1310  HelpExampleCli("getlastpoablocktime", "") + HelpExampleRpc("getlastpoablocktime", ""));
1311 
1312  LOCK(cs_main);
1313 
1314  //Find the previous PoA block
1315  CBlockIndex* pindex = chainActive.Tip();
1316  while (pindex->nHeight > Params().START_POA_BLOCK()) {
1317  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
1318  break;
1319  }
1320  pindex = pindex->pprev;
1321  }
1322 
1323  int nTime = pindex->nTime;
1324 
1325  return nTime;
1326 }
1327 
1328 UniValue getlastpoaauditedpos(const UniValue& params, bool fHelp)
1329 {
1330  if (fHelp || params.size() != 0)
1331  throw std::runtime_error(
1332  "getlastpoaauditedpos\n"
1333  "\nReturns the last audited PoS block in the last PoA block.\n"
1334  "\nResult:\n"
1335  "\"height\" (numeric) The last audited PoS block in the last PoA block\n"
1336  "\nExamples:\n" +
1337  HelpExampleCli("getlastpoaauditedpos", "") + HelpExampleRpc("getlastpoaauditedpos", ""));
1338 
1339  LOCK(cs_main);
1340 
1341  int lastPoSHeight = 0;
1342  //Find the previous PoA block
1343  CBlock block;
1344  CBlockIndex* pindex = chainActive.Tip();
1345  while (pindex->nHeight > Params().START_POA_BLOCK()) {
1346  if (pindex->GetBlockHeader().IsPoABlockByVersion()) {
1347  break;
1348  }
1349  pindex = pindex->pprev;
1350  }
1351  ReadBlockFromDisk(block, pindex);
1352  for (size_t i = 0; i < block.posBlocksAudited.size(); i++) {
1353  lastPoSHeight = block.posBlocksAudited[i].height;
1354  }
1355 
1356  return lastPoSHeight;
1357 }
1358 
1359 void validaterange(const UniValue& params, int& heightStart, int& heightEnd, int minHeightStart)
1360 {
1361  if (params.size() < 2) {
1362  throw JSONRPCError(RPC_INVALID_PARAMETER, "Not enough parameters in validaterange");
1363  }
1364 
1365  int nBestHeight;
1366  {
1367  LOCK(cs_main);
1368  nBestHeight = chainActive.Height();
1369  }
1370 
1371  heightStart = params[0].get_int();
1372  if (heightStart > nBestHeight) {
1373  throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid starting block (%d). Out of range.", heightStart));
1374  }
1375 
1376  const int range = params[1].get_int();
1377  if (range < 1) {
1378  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid block range. Must be strictly positive.");
1379  }
1380 
1381  heightEnd = heightStart + range - 1;
1382 
1383  if (heightStart < minHeightStart && heightEnd >= minHeightStart) {
1384  heightStart = minHeightStart;
1385  }
1386 
1387  if (heightEnd > nBestHeight) {
1388  throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Invalid ending block (%d). Out of range.", heightEnd));
1389  }
1390 }
1391 
1392 UniValue getblockindexstats(const UniValue& params, bool fHelp) {
1393  if (fHelp || params.size() < 2 || params.size() > 3)
1394  throw std::runtime_error(
1395  "getblockindexstats height range ( fFeeOnly )\n"
1396  "\nReturns aggregated BlockIndex data for blocks "
1397  "\n[height, height+1, height+2, ..., height+range-1]\n"
1398 
1399  "\nArguments:\n"
1400  "1. height (numeric, required) block height where the search starts.\n"
1401  "2. range (numeric, required) number of blocks to include.\n"
1402  "3. fFeeOnly (boolean, optional, default=False) return only fee info.\n"
1403 
1404  "\nResult:\n"
1405  "{\n"
1406  " \"first_block\": \"x\" (integer) First counted block\n"
1407  " \"last_block\": \"x\" (integer) Last counted block\n"
1408  " \"txcount\": xxxxx (numeric) tx count (excluding coinbase/coinstake)\n"
1409  " \"txcount_all\": xxxxx (numeric) tx count (including coinbase/coinstake)\n"
1410  " }\n"
1411  " \"txbytes\": xxxxx (numeric) Sum of the size of all txes over block range\n"
1412  " \"ttlfee\": xxxxx (numeric) Sum of the fee amount of all txes over block range\n"
1413  " \"ttlfee_all\": xxxxx (numeric) Sum of the fee amount of all txes over block range\n"
1414  " \"feeperkb\": xxxxx (numeric) Average fee per kb\n"
1415  "}\n"
1416 
1417  "\nExamples:\n" +
1418  HelpExampleCli("getblockindexstats", "1200000 1000") +
1419  HelpExampleRpc("getblockindexstats", "1200000, 1000"));
1420 
1421  int heightStart, heightEnd;
1422  validaterange(params, heightStart, heightEnd);
1423  // return object
1424  UniValue ret(UniValue::VOBJ);
1425  ret.push_back(Pair("Starting block", heightStart));
1426  ret.push_back(Pair("Ending block", heightEnd));
1427 
1428  bool fFeeOnly = false;
1429  if (params.size() > 2) {
1430  fFeeOnly = params[2].get_bool();
1431  }
1432 
1433  CAmount nFees = 0;
1434  CAmount nFees_all = 0;
1435  int64_t nBytes = 0;
1436  int64_t nTxCount = 0;
1437  int64_t nTxCount_all = 0;
1438 
1439  CBlockIndex* pindex = nullptr;
1440  {
1441  LOCK(cs_main);
1442  pindex = chainActive[heightStart];
1443  }
1444 
1445  if (!pindex)
1446  throw JSONRPCError(RPC_INVALID_PARAMETER, "invalid block height");
1447 
1448  while (true) {
1449  CBlock block;
1450  if (!ReadBlockFromDisk(block, pindex)) {
1451  throw JSONRPCError(RPC_DATABASE_ERROR, "failed to read block from disk");
1452  }
1453 
1454  CAmount nValueIn = 0;
1455  CAmount nValueOut = 0;
1456  const int ntx = block.vtx.size();
1457  nTxCount_all += ntx;
1458  nTxCount = block.IsProofOfStake() ? nTxCount + ntx - 2 : nTxCount + ntx - 1;
1459 
1460  // loop through each tx in block and save size and fee
1461  for (const CTransaction& tx : block.vtx) {
1462  if (tx.IsCoinBase() || tx.IsCoinStake())
1463  continue;
1464 
1465  // fetch input value from prevouts
1466  for (unsigned int j = 0; j < tx.vin.size(); j++) {
1467  COutPoint prevout = tx.vin[j].prevout;
1468  CTransaction txPrev;
1469  uint256 hashBlock;
1470  if(!GetTransaction(prevout.hash, txPrev, hashBlock, true))
1471  throw JSONRPCError(RPC_DATABASE_ERROR, "failed to read tx from disk");
1472  nValueIn += txPrev.vout[prevout.n].nValue;
1473  }
1474 
1475  // sum output values in nValueOut
1476  for (unsigned int j = 0; j < tx.vout.size(); j++) {
1477  nValueOut += tx.vout[j].nValue;
1478  }
1479 
1480  // update sums
1481  nFees_all += tx.nTxFee;
1482  nFees += tx.nTxFee;
1483  nBytes += tx.GetSerializeSize(SER_NETWORK, CLIENT_VERSION);
1484  }
1485 
1486  if (pindex->nHeight < heightEnd) {
1487  LOCK(cs_main);
1488  pindex = chainActive.Next(pindex);
1489  } else {
1490  break;
1491  }
1492  }
1493 
1494  // get fee rate
1495  CFeeRate nFeeRate = CFeeRate(nFees, nBytes);
1496 
1497  // return UniValue object
1498  ret.push_back(Pair("txcount", (int64_t)nTxCount));
1499  ret.push_back(Pair("txcount_all", (int64_t)nTxCount_all));
1500  ret.push_back(Pair("txbytes", (int64_t)nBytes));
1501  ret.push_back(Pair("ttlfee", FormatMoney(nFees)));
1502  ret.push_back(Pair("ttlfee_all", FormatMoney(nFees_all)));
1503  ret.push_back(Pair("feeperkb", FormatMoney(nFeeRate.GetFeePerK())));
1504 
1505  return ret;
1506 }
pindexBestHeader
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
Definition: main.cpp:71
mempoolInfoToJSON
UniValue mempoolInfoToJSON()
Definition: blockchain.cpp:959
CTxIn
An input of a transaction.
Definition: transaction.h:83
getblockindexstats
UniValue getblockindexstats(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1392
CTxMemPool::size
unsigned long size()
Definition: txmempool.h:168
CCoinsViewMemPool::GetCoins
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: txmempool.cpp:706
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
invalidateblock
UniValue invalidateblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:986
getblockcount
UniValue getblockcount(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:194
mempoolToJSON
UniValue mempoolToJSON(bool fVerbose=false)
Definition: blockchain.cpp:380
CBlockIndex::IsProofOfStake
bool IsProofOfStake() const
Definition: chain.h:390
CTxMemPool::pruneSpent
void pruneSpent(const uint256 &hash, CCoins &coins)
Definition: txmempool.cpp:376
getbestblockhash
UniValue getbestblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:209
UniValue::VOBJ
@ VOBJ
Definition: univalue.h:21
getlastpoaauditedpos
UniValue getlastpoaauditedpos(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1328
CTxMemPoolEntry::GetHeight
unsigned int GetHeight() const
Definition: txmempool.h:61
UniValue::get_bool
bool get_bool() const
Definition: univalue.cpp:302
getlastpoablock
UniValue getlastpoablock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1224
CUpdatedBlock::height
int height
Definition: blockchain.cpp:29
RPC_INTERNAL_ERROR
@ RPC_INTERNAL_ERROR
Definition: protocol.h:36
getmaxsupply
UniValue getmaxsupply(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:180
CBlockHeader::hashMerkleRoot
uint256 hashMerkleRoot
Definition: block.h:62
getrawmempool
UniValue getrawmempool(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:423
CBlockHeader::nBits
uint32_t nBits
Definition: block.h:65
b
void const uint64_t * b
Definition: field_5x52_asm_impl.h:10
getchaintips
UniValue getchaintips(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:830
FlushStateToDisk
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
Definition: main.cpp:3467
gettxout
UniValue gettxout(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:635
CDataStream::begin
const_iterator begin() const
Definition: streams.h:116
CCoinsViewBacked::GetStats
bool GetStats(CCoinsStats &stats) const
Calculate statistics about the unspent transaction output set.
Definition: coins.cpp:79
base_uint::GetHex
std::string GetHex() const
Definition: arith_uint256.cpp:155
CTxMemPoolEntry::GetTime
int64_t GetTime() const
Definition: txmempool.h:60
validaterange
void validaterange(const UniValue &params, int &heightStart, int &heightEnd, int minHeightStart)
Definition: blockchain.cpp:1359
ValueFromAmount
UniValue ValueFromAmount(const CAmount &amount)
Definition: server.cpp:118
sync.h
getblock
UniValue getblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:486
CBlockHeader::nVersion
int32_t nVersion
Definition: block.h:59
chainActive
CChain chainActive
The currently-connected chain of blocks.
Definition: main.cpp:70
CBlockIndex::nMoneySupply
int64_t nMoneySupply
Definition: chain.h:223
BLOCK_FAILED_MASK
@ BLOCK_FAILED_MASK
descends from failed block
Definition: chain.h:154
NullUniValue
const UniValue NullUniValue
Definition: univalue.cpp:78
COutPoint::hash
uint256 hash
Definition: transaction.h:39
getlastpoablocktime
UniValue getlastpoablocktime(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1301
CBitcoinAddress
base58-encoded PRCY addresses.
Definition: base58.h:109
CBlockIndex::nNonce
unsigned int nNonce
Definition: chain.h:230
RPC_INVALID_PARAMETER
@ RPC_INVALID_PARAMETER
Ran out of memory during operation.
Definition: protocol.h:45
CTxMemPool::exists
bool exists(uint256 hash)
Definition: txmempool.h:179
CCoinsStats::nTransactions
uint64_t nTransactions
Definition: coins.h:335
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:169
CCoins::IsAvailable
bool IsAvailable(unsigned int nPos) const
check whether a particular output is still available
Definition: coins.h:275
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
BLOCK_VALID_TREE
@ BLOCK_VALID_TREE
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
Definition: chain.h:127
CBlockHeader::nAccumulatorCheckpoint
uint256 nAccumulatorCheckpoint
Definition: block.h:67
CUpdatedBlock::hash
uint256 hash
Definition: blockchain.cpp:28
CBlockHeader::IsPoABlockByVersion
bool IsPoABlockByVersion() const
Definition: block.h:105
CompareBlocksByHeight
Comparison function for sorting the getchaintips heads.
Definition: blockchain.cpp:817
CCoinsStats
Definition: coins.h:332
CBlockIndex::nBits
unsigned int nBits
Definition: chain.h:229
CBlockIndex::nChainWork
uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: chain.h:193
clientversion.h
GetSerializeSize
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:194
CCoins::nHeight
int nHeight
at which height this transaction was included in the active block chain
Definition: coins.h:88
ReconsiderBlock
bool ReconsiderBlock(CValidationState &state, CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
Definition: main.cpp:4008
CTxMemPoolEntry::GetFee
CAmount GetFee() const
Definition: txmempool.h:58
InvalidateBlock
bool InvalidateBlock(CValidationState &state, CBlockIndex *pindex)
Mark a block as invalid.
Definition: main.cpp:3972
CValidationState::GetRejectReason
std::string GetRejectReason() const
Definition: validation.h:87
FormatMoney
std::string FormatMoney(const CAmount &n, bool fPlus)
Money parsing/formatting utilities.
Definition: utilmoneystr.cpp:13
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:159
getmempoolinfo
UniValue getmempoolinfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:969
CFeeRate
Fee rate in PRCY per kilobyte: CAmount / kB.
Definition: amount.h:39
CBlockHeader::GetHash
uint256 GetHash() const
Definition: block.cpp:80
IsRPCRunning
bool IsRPCRunning()
Definition: server.cpp:487
CChain::FindFork
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
Definition: chain.cpp:54
UniValue
Definition: univalue.h:19
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:269
CBlockIndex::nTime
unsigned int nTime
Definition: chain.h:228
ActivateBestChain
bool ActivateBestChain(CValidationState &state, CBlock *pblock, bool fAlreadyChecked)
Make the best chain active, in multiple steps.
Definition: main.cpp:3892
PoSBlockInfoToJSON
void PoSBlockInfoToJSON(const uint256 hashBlock, int64_t nTime, int height, UniValue &entry)
Definition: rawtransaction.cpp:59
CBlockHeader::nNonce
uint32_t nNonce
Definition: block.h:66
UniValue::get_str
const std::string & get_str() const
Definition: univalue.cpp:309
cs_main
RecursiveMutex cs_main
Global state.
Definition: main.cpp:65
CBlockIndex::GetBlockHeader
CBlockHeader GetBlockHeader() const
Definition: chain.h:340
CTransaction::IsCoinBase
bool IsCoinBase() const
Definition: transaction.h:359
CCoins::vout
std::vector< CTxOut > vout
unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are d...
Definition: coins.h:85
reconsiderblock
UniValue reconsiderblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1057
blockheaderToJSON
UniValue blockheaderToJSON(const CBlockIndex *blockindex)
Definition: blockchain.cpp:67
CTxMemPool::cs
RecursiveMutex cs
sum of all mempool tx' byte sizes
Definition: txmempool.h:135
getblockchaininfo
UniValue getblockchaininfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:767
CBlockHeader::GetBlockTime
int64_t GetBlockTime() const
Definition: block.h:135
CCoinsStats::hashBlock
uint256 hashBlock
Definition: coins.h:334
GetTransaction
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.
Definition: main.cpp:2010
GetDifficulty
double GetDifficulty(const CBlockIndex *blockindex)
Definition: blockchain.cpp:39
CBlockIndex::GetMedianTimePast
int64_t GetMedianTimePast() const
Definition: chain.h:371
CTransaction::vout
std::vector< CTxOut > vout
Definition: transaction.h:286
resyncfrom
UniValue resyncfrom(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1022
CBlockIndex::hashMerkleRoot
uint256 hashMerkleRoot
Definition: chain.h:227
univalue.h
RPC_DATABASE_ERROR
@ RPC_DATABASE_ERROR
Invalid, missing or duplicate parameter.
Definition: protocol.h:46
CDataStream::end
const_iterator end() const
Definition: streams.h:118
HexStr
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: utilstrencodings.h:85
PAIRTYPE
#define PAIRTYPE(t1, t2)
This is needed because the foreach macro can't get over the comma in pair<t1, t2>
Definition: utilstrencodings.h:24
JSONRPCError
UniValue JSONRPCError(int code, const std::string &message)
Definition: protocol.cpp:60
CAmount
int64_t CAmount
Amount in PRCY (Can be negative)
Definition: amount.h:17
pcoinsTip
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:1130
waitfornewblock
UniValue waitfornewblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:234
CTransaction::nTxFee
CAmount nTxFee
Definition: transaction.h:298
waitforblockheight
UniValue waitforblockheight(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:319
mempool
CTxMemPool mempool(::minRelayTxFee)
CBlockIndex::nStakeModifier
uint64_t nStakeModifier
Definition: chain.h:217
CTxMemPool::GetTotalTxSize
uint64_t GetTotalTxSize()
Definition: txmempool.h:173
HelpExampleRpc
std::string HelpExampleRpc(std::string methodname, std::string args)
Definition: server.cpp:607
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
uint256S
uint256 uint256S(const char *str)
Definition: uint256.h:99
CBlockIndex::nVersion
int nVersion
block header
Definition: chain.h:226
CScript
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:363
ExtractDestination
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: standard.cpp:199
BLOCK_VALID_SCRIPTS
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:141
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
CCoinsViewCache::AccessCoins
const CCoins * AccessCoins(const uint256 &txid) const
Return a pointer to CCoins in the cache, or NULL if not found.
Definition: coins.cpp:145
CTxDestination
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: standard.h:81
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
getblockhash
UniValue getblockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:463
checkpoints.h
getlastpoablockhash
UniValue getlastpoablockhash(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1251
CCoinsStats::nSerializedSize
uint64_t nSerializedSize
Definition: coins.h:337
fVerifyingBlocks
bool fVerifyingBlocks
Definition: main.cpp:85
CBlockIndex::nAccumulatorCheckpoint
uint256 nAccumulatorCheckpoint
Definition: chain.h:231
CVerifyDB
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: main.h:421
HelpExampleCli
std::string HelpExampleCli(std::string methodname, std::string args)
Definition: server.cpp:603
RPCNotifyBlockChange
void RPCNotifyBlockChange(bool fInitialDownload, const CBlockIndex *pindex)
Definition: blockchain.cpp:224
RPC_INVALID_ADDRESS_OR_KEY
@ RPC_INVALID_ADDRESS_OR_KEY
Unexpected type was passed as parameter.
Definition: protocol.h:43
name
const char * name
Definition: rest.cpp:34
CBlock::vtx
std::vector< CTransaction > vtx
Definition: block.h:146
CCoins::nVersion
int nVersion
version of the CTransaction; accesses to this value should probably check for nHeight as well,...
Definition: coins.h:92
CBlock
Definition: block.h:142
getlastpoablockheight
UniValue getlastpoablockheight(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1276
verifychain
UniValue verifychain(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:712
strprintf
#define strprintf
Definition: tinyformat.h:1056
ScriptPubKeyToJSON
void ScriptPubKeyToJSON(const CScript &scriptPubKey, UniValue &out, bool fIncludeHex)
Definition: rawtransaction.cpp:34
CTxMemPool::queryHashes
void queryHashes(std::vector< uint256 > &vtxid)
Definition: txmempool.cpp:614
CCoinsStats::nHeight
int nHeight
Definition: coins.h:333
Checkpoints::GuessVerificationProgress
double GuessVerificationProgress(const CBlockIndex *pindex, bool fSigchecks)
Guess how far we are in the verification process at the given block index.
Definition: checkpoints.cpp:45
CVerifyDB::VerifyDB
bool VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
Definition: main.cpp:5308
CChainParams::ChangeMaxReorg
void ChangeMaxReorg(int num) const
Definition: chainparams.h:193
UniValue::get_int
int get_int() const
Definition: univalue.cpp:316
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:414
CCoinsStats::nTransactionOutputs
uint64_t nTransactionOutputs
Definition: coins.h:336
CompareBlocksByHeight::operator()
bool operator()(const CBlockIndex *a, const CBlockIndex *b) const
Definition: blockchain.cpp:818
setmaxreorgdepth
UniValue setmaxreorgdepth(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1201
utilmoneystr.h
main.h
COutPoint::n
uint32_t n
Definition: transaction.h:40
CTransaction::vin
std::vector< CTxIn > vin
Definition: transaction.h:285
CTxMemPoolEntry
CTxMemPool stores these:
Definition: txmempool.h:40
CTxMemPool::mapTx
std::map< uint256, CTxMemPoolEntry > mapTx
Definition: txmempool.h:136
LOCK
#define LOCK(cs)
Definition: sync.h:182
CTxMemPoolEntry::GetPriority
double GetPriority(unsigned int currentHeight) const
Definition: txmempool.cpp:38
ReadBlockFromDisk
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos)
Definition: main.cpp:2101
CTxIn::prevout
COutPoint prevout
Definition: transaction.h:86
CCoinsViewMemPool
CCoinsView that brings transactions from a memorypool into view.
Definition: txmempool.h:202
UniValue::push_back
bool push_back(const UniValue &val)
Definition: univalue.cpp:173
CBlockHeader::hashPrevPoABlock
uint256 hashPrevPoABlock
Definition: block.h:73
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:463
CUpdatedBlock
Definition: blockchain.cpp:26
CChain::Contains
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:626
UniValue::empty
bool empty() const
Definition: univalue.h:67
mapInvalidOutPoints
std::map< COutPoint, COutPoint > mapInvalidOutPoints
Definition: main.cpp:2735
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:34
CCoinsStats::hashSerialized
uint256 hashSerialized
Definition: coins.h:338
base58.h
CCoins
Definition: coins.h:77
CCoins::fCoinBase
bool fCoinBase
whether transaction is a coinbase
Definition: coins.h:81
UniValue::size
size_t size() const
Definition: univalue.h:69
CTxMemPoolEntry::GetTxSize
size_t GetTxSize() const
Definition: txmempool.h:59
COutPoint::ToString
std::string ToString() const
Definition: transaction.cpp:21
CTransaction::GetHash
const uint256 & GetHash() const
Definition: transaction.h:342
CCoinsViewCache::GetBestBlock
uint256 GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:165
getsupply
UniValue getsupply(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:165
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
CBlockIndex::IsProofOfAudit
bool IsProofOfAudit() const
Definition: chain.h:400
gettxoutsetinfo
UniValue gettxoutsetinfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:599
CValidationState::IsValid
bool IsValid() const
Definition: validation.h:62
waitforblock
UniValue waitforblock(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:274
UniValue::VARR
@ VARR
Definition: univalue.h:21
server.h
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
CFeeRate::GetFeePerK
CAmount GetFeePerK() const
Definition: amount.h:50
TxToJSON
void TxToJSON(const CTransaction &tx, const uint256 hashBlock, UniValue &entry)
Definition: rawtransaction.cpp:66
GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:241
CValidationState
Capture information about block/transaction validation.
Definition: validation.h:23
CCoinsViewCache::GetCoins
bool GetCoins(const uint256 &txid, CCoins &coins) const
Retrieve the CCoins (unspent transaction outputs) for a given txid.
Definition: coins.cpp:113
CChain::Next
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or NULL if the given index is not found or is the tip.
Definition: chain.h:632
CBlock::IsProofOfStake
bool IsProofOfStake() const
Definition: block.h:213
getblockheader
UniValue getblockheader(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:548
blockToJSON
UniValue blockToJSON(const CBlock &block, const CBlockIndex *blockindex, bool txDetails=false)
Definition: blockchain.cpp:95
getinvalid
UniValue getinvalid(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:1094
getdifficulty
UniValue getdifficulty(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:364
CBlock::posBlocksAudited
std::vector< PoSBlockSummary > posBlocksAudited
Definition: block.h:149
CChainParams::ToCheckBlockUpgradeMajority
int ToCheckBlockUpgradeMajority() const
Definition: chainparams.h:62
mapBlockIndex
BlockMap mapBlockIndex
Definition: main.cpp:67
getfeeinfo
UniValue getfeeinfo(const UniValue &params, bool fHelp)
Definition: blockchain.cpp:919
CTxMemPoolEntry::GetTx
const CTransaction & GetTx() const
Definition: txmempool.h:56
CTransaction::IsCoinStake
bool IsCoinStake() const
Definition: transaction.cpp:143
base_uint::ToString
std::string ToString() const
Definition: arith_uint256.cpp:199