Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
rpcmining.cpp
Go to the documentation of this file.
1 // Copyright (c) 2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include "main.h"
7 #include "db.h"
8 #include "init.h"
9 #include "bitcoinrpc.h"
10 
11 using namespace json_spirit;
12 using namespace std;
13 
14 // Return average network hashes per second based on the last 'lookup' blocks,
15 // or from the last difficulty change if 'lookup' is nonpositive.
16 // If 'height' is nonnegative, compute the estimate at the time when a given block was found.
17 Value GetNetworkHashPS(int lookup, int height) {
18  CBlockIndex *pb = pindexBest;
19 
20  if (height >= 0 && height < nBestHeight)
21  pb = FindBlockByHeight(height);
22 
23  if (pb == NULL || !pb->nHeight)
24  return 0;
25 
26  // If lookup is zero or negative value, then use blocks since the last retarget.
27  if (lookup <= 0)
28  lookup = pb->nHeight % 504 + 1;
29 
30  // If lookup is larger than block chain, then set it to the maximum allowed.
31  if (lookup > pb->nHeight)
32  lookup = pb->nHeight;
33 
34  CBlockIndex *pb0 = pb;
35  int64 minTime = pb0->GetBlockTime();
36  int64 maxTime = minTime;
37  for (int i = 0; i < lookup; i++) {
38  pb0 = pb0->pprev;
39  int64 time = pb0->GetBlockTime();
40  minTime = std::min(time, minTime);
41  maxTime = std::max(time, maxTime);
42  }
43 
44  // In case there's a situation where minTime == maxTime, we don't want a divide by zero exception.
45  if (minTime == maxTime)
46  return 0;
47 
48  uint256 workDiff = pb->nChainWork - pb0->nChainWork;
49  int64 timeDiff = maxTime - minTime;
50 
51  return (boost::int64_t)(workDiff.getdouble() / timeDiff);
52 }
53 
54 Value getnetworkhashps(const Array& params, bool fHelp)
55 {
56  if (fHelp || params.size() > 2)
57  throw runtime_error(
58  "getnetworkhashps [blocks] [height]\n"
59  "Returns the estimated network hashes per second based on the last 30 blocks.\n"
60  "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n"
61  "Pass in [height] to estimate the network speed at the time when a certain block was found.");
62 
63  return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 30, params.size() > 1 ? params[1].get_int() : -1);
64 }
65 
66 
67 
68 // Key used by getwork/getblocktemplate miners.
69 // Allocated in InitRPCMining, free'd in ShutdownRPCMining
70 static CReserveKey* pMiningKey = NULL;
71 
73 {
74  if (!pwalletMain)
75  return;
76 
77  // getwork/getblocktemplate mining rewards paid here:
78  pMiningKey = new CReserveKey(pwalletMain);
79 }
80 
82 {
83  if (!pMiningKey)
84  return;
85 
86  delete pMiningKey; pMiningKey = NULL;
87 }
88 
89 Value getgenerate(const Array& params, bool fHelp)
90 {
91  if (fHelp || params.size() != 0)
92  throw runtime_error(
93  "getgenerate\n"
94  "Returns true or false.");
95 
96  if (!pMiningKey)
97  return false;
98 
99  return GetBoolArg("-gen");
100 }
101 
102 
103 Value setgenerate(const Array& params, bool fHelp)
104 {
105  if (fHelp || params.size() < 1 || params.size() > 2)
106  throw runtime_error(
107  "setgenerate <generate> [genproclimit]\n"
108  "<generate> is true or false to turn generation on or off.\n"
109  "Generation is limited to [genproclimit] processors, -1 is unlimited.");
110 
111  bool fGenerate = true;
112  if (params.size() > 0)
113  fGenerate = params[0].get_bool();
114 
115  if (params.size() > 1)
116  {
117  int nGenProcLimit = params[1].get_int();
118  mapArgs["-genproclimit"] = itostr(nGenProcLimit);
119  if (nGenProcLimit == 0)
120  fGenerate = false;
121  }
122  mapArgs["-gen"] = (fGenerate ? "1" : "0");
123 
124  assert(pwalletMain != NULL);
125  GenerateBitcoins(fGenerate, pwalletMain);
126  return Value::null;
127 }
128 
129 
130 Value gethashespersec(const Array& params, bool fHelp)
131 {
132  if (fHelp || params.size() != 0)
133  throw runtime_error(
134  "gethashespersec\n"
135  "Returns a recent hashes per second performance measurement while generating.");
136 
137  if (GetTimeMillis() - nHPSTimerStart > 8000)
138  return (boost::int64_t)0;
140 }
141 
142 
143 Value getmininginfo(const Array& params, bool fHelp)
144 {
145  if (fHelp || params.size() != 0)
146  throw runtime_error(
147  "getmininginfo\n"
148  "Returns an object containing mining-related information.");
149 
150  Object obj;
151  obj.push_back(Pair("blocks", (int)nBestHeight));
152  obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize));
153  obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx));
154  obj.push_back(Pair("difficulty", (double)GetDifficulty()));
155  obj.push_back(Pair("errors", GetWarnings("statusbar")));
156  obj.push_back(Pair("generate", GetBoolArg("-gen")));
157  obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1)));
158  obj.push_back(Pair("hashespersec", gethashespersec(params, false)));
159  obj.push_back(Pair("networkhashps", getnetworkhashps(params, false)));
160  obj.push_back(Pair("pooledtx", (uint64_t)mempool.size()));
161  obj.push_back(Pair("testnet", fTestNet));
162  return obj;
163 }
164 
165 
166 Value getworkex(const Array& params, bool fHelp)
167 {
168  if (fHelp || params.size() > 2)
169  throw runtime_error(
170  "getworkex [data, coinbase]\n"
171  "If [data, coinbase] is not specified, returns extended work data.\n"
172  );
173 
174  if (vNodes.empty())
175  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Feathercoin is not connected!");
176 
178  throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Feathercoin is downloading blocks...");
179 
180  typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
181  static mapNewBlock_t mapNewBlock; // FIXME: thread safety
182  static vector<CBlockTemplate*> vNewBlockTemplate;
183  static CReserveKey reservekey(pwalletMain);
184 
185  if (params.size() == 0)
186  {
187  // Update block
188  static unsigned int nTransactionsUpdatedLast;
189  static CBlockIndex* pindexPrev;
190  static int64 nStart;
191  static CBlockTemplate* pblocktemplate;
192  if (pindexPrev != pindexBest ||
193  (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
194  {
195  if (pindexPrev != pindexBest)
196  {
197  // Deallocate old blocks since they're obsolete now
198  mapNewBlock.clear();
199  BOOST_FOREACH(CBlockTemplate* pblocktemplate, vNewBlockTemplate)
200  delete pblocktemplate;
201  vNewBlockTemplate.clear();
202  }
203 
204  // Clear pindexPrev so future getworks make a new block, despite any failures from here on
205  pindexPrev = NULL;
206 
207  // Store the pindexBest used before CreateNewBlock, to avoid races
208  nTransactionsUpdatedLast = nTransactionsUpdated;
209  CBlockIndex* pindexPrevNew = pindexBest;
210  nStart = GetTime();
211 
212  // Create new block
213  pblocktemplate = CreateNewBlockWithKey(*pMiningKey);
214  if (!pblocktemplate)
215  throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
216  vNewBlockTemplate.push_back(pblocktemplate);
217 
218  // Need to update only after we know CreateNewBlock succeeded
219  pindexPrev = pindexPrevNew;
220  }
221  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
222 
223  // Update nTime
224  pblock->UpdateTime(pindexPrev);
225  pblock->nNonce = 0;
226 
227  // Update nExtraNonce
228  static unsigned int nExtraNonce = 0;
229  IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
230 
231  // Save
232  mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
233 
234  // Pre-build hash buffers
235  char pmidstate[32];
236  char pdata[128];
237  char phash1[64];
238  FormatHashBuffers(pblock, pmidstate, pdata, phash1);
239 
240  uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
241 
242  CTransaction coinbaseTx = pblock->vtx[0];
243  std::vector<uint256> merkle = pblock->GetMerkleBranch(0);
244 
245  Object result;
246  result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata))));
247  result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
248 
249  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
250  ssTx << coinbaseTx;
251  result.push_back(Pair("coinbase", HexStr(ssTx.begin(), ssTx.end())));
252 
253  Array merkle_arr;
254 
255  BOOST_FOREACH(uint256 merkleh, merkle) {
256  printf("%s\n", merkleh.ToString().c_str());
257  merkle_arr.push_back(HexStr(BEGIN(merkleh), END(merkleh)));
258  }
259 
260  result.push_back(Pair("merkle", merkle_arr));
261 
262  return result;
263  }
264  else
265  {
266  // Parse parameters
267  vector<unsigned char> vchData = ParseHex(params[0].get_str());
268  vector<unsigned char> coinbase;
269 
270  if(params.size() == 2)
271  coinbase = ParseHex(params[1].get_str());
272 
273  if (vchData.size() != 128)
274  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
275 
276  CBlock* pdata = (CBlock*)&vchData[0];
277 
278  // Byte reverse
279  for (int i = 0; i < 128/4; i++)
280  ((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
281 
282  // Get saved block
283  if (!mapNewBlock.count(pdata->hashMerkleRoot))
284  return false;
285  CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
286 
287  pblock->nTime = pdata->nTime;
288  pblock->nNonce = pdata->nNonce;
289 
290  if(coinbase.size() == 0)
291  pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
292  else
293  CDataStream(coinbase, SER_NETWORK, PROTOCOL_VERSION) >> pblock->vtx[0];
294 
295  pblock->hashMerkleRoot = pblock->BuildMerkleTree();
296 
297  return CheckWork(pblock, *pwalletMain, reservekey);
298  }
299 }
300 
301 
302 Value getwork(const Array& params, bool fHelp)
303 {
304  if (fHelp || params.size() > 1)
305  throw runtime_error(
306  "getwork [data]\n"
307  "If [data] is not specified, returns formatted hash data to work on:\n"
308  " \"midstate\" : precomputed hash state after hashing the first half of the data (DEPRECATED)\n" // deprecated
309  " \"data\" : block data\n"
310  " \"hash1\" : formatted hash buffer for second hash (DEPRECATED)\n" // deprecated
311  " \"target\" : little endian hash target\n"
312  "If [data] is specified, tries to solve the block and returns true if it was successful.");
313 
314  if (vNodes.empty())
315  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Feathercoin is not connected!");
316 
318  throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Feathercoin is downloading blocks...");
319 
320  typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
321  static mapNewBlock_t mapNewBlock; // FIXME: thread safety
322  static vector<CBlockTemplate*> vNewBlockTemplate;
323 
324  if (params.size() == 0)
325  {
326  // Update block
327  static unsigned int nTransactionsUpdatedLast;
328  static CBlockIndex* pindexPrev;
329  static int64 nStart;
330  static CBlockTemplate* pblocktemplate;
331  if (pindexPrev != pindexBest ||
332  (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 60))
333  {
334  if (pindexPrev != pindexBest)
335  {
336  // Deallocate old blocks since they're obsolete now
337  mapNewBlock.clear();
338  BOOST_FOREACH(CBlockTemplate* pblocktemplate, vNewBlockTemplate)
339  delete pblocktemplate;
340  vNewBlockTemplate.clear();
341  }
342 
343  // Clear pindexPrev so future getworks make a new block, despite any failures from here on
344  pindexPrev = NULL;
345 
346  // Store the pindexBest used before CreateNewBlock, to avoid races
347  nTransactionsUpdatedLast = nTransactionsUpdated;
348  CBlockIndex* pindexPrevNew = pindexBest;
349  nStart = GetTime();
350 
351  // Create new block
352  pblocktemplate = CreateNewBlockWithKey(*pMiningKey);
353  if (!pblocktemplate)
354  throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
355  vNewBlockTemplate.push_back(pblocktemplate);
356 
357  // Need to update only after we know CreateNewBlock succeeded
358  pindexPrev = pindexPrevNew;
359  }
360  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
361 
362  // Update nTime
363  pblock->UpdateTime(pindexPrev);
364  pblock->nNonce = 0;
365 
366  // Update nExtraNonce
367  static unsigned int nExtraNonce = 0;
368  IncrementExtraNonce(pblock, pindexPrev, nExtraNonce);
369 
370  // Save
371  mapNewBlock[pblock->hashMerkleRoot] = make_pair(pblock, pblock->vtx[0].vin[0].scriptSig);
372 
373  // Pre-build hash buffers
374  char pmidstate[32];
375  char pdata[128];
376  char phash1[64];
377  FormatHashBuffers(pblock, pmidstate, pdata, phash1);
378 
379  uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
380 
381  Object result;
382  result.push_back(Pair("midstate", HexStr(BEGIN(pmidstate), END(pmidstate)))); // deprecated
383  result.push_back(Pair("data", HexStr(BEGIN(pdata), END(pdata))));
384  result.push_back(Pair("hash1", HexStr(BEGIN(phash1), END(phash1)))); // deprecated
385  result.push_back(Pair("target", HexStr(BEGIN(hashTarget), END(hashTarget))));
386  return result;
387  }
388  else
389  {
390  // Parse parameters
391  vector<unsigned char> vchData = ParseHex(params[0].get_str());
392  if (vchData.size() != 128)
393  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter");
394  CBlock* pdata = (CBlock*)&vchData[0];
395 
396  // Byte reverse
397  for (int i = 0; i < 128/4; i++)
398  ((unsigned int*)pdata)[i] = ByteReverse(((unsigned int*)pdata)[i]);
399 
400  // Get saved block
401  if (!mapNewBlock.count(pdata->hashMerkleRoot))
402  return false;
403  CBlock* pblock = mapNewBlock[pdata->hashMerkleRoot].first;
404 
405  pblock->nTime = pdata->nTime;
406  pblock->nNonce = pdata->nNonce;
407  pblock->vtx[0].vin[0].scriptSig = mapNewBlock[pdata->hashMerkleRoot].second;
408  pblock->hashMerkleRoot = pblock->BuildMerkleTree();
409 
410  assert(pwalletMain != NULL);
411  return CheckWork(pblock, *pwalletMain, *pMiningKey);
412  }
413 }
414 
415 
416 Value getblocktemplate(const Array& params, bool fHelp)
417 {
418  if (fHelp || params.size() > 1)
419  throw runtime_error(
420  "getblocktemplate [params]\n"
421  "Returns data needed to construct a block to work on:\n"
422  " \"version\" : block version\n"
423  " \"previousblockhash\" : hash of current highest block\n"
424  " \"transactions\" : contents of non-coinbase transactions that should be included in the next block\n"
425  " \"coinbaseaux\" : data that should be included in coinbase\n"
426  " \"coinbasevalue\" : maximum allowable input to coinbase transaction, including the generation award and transaction fees\n"
427  " \"target\" : hash target\n"
428  " \"mintime\" : minimum timestamp appropriate for next block\n"
429  " \"curtime\" : current timestamp\n"
430  " \"mutable\" : list of ways the block template may be changed\n"
431  " \"noncerange\" : range of valid nonces\n"
432  " \"sigoplimit\" : limit of sigops in blocks\n"
433  " \"sizelimit\" : limit of block size\n"
434  " \"bits\" : compressed target of next block\n"
435  " \"height\" : height of the next block\n"
436  "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
437 
438  std::string strMode = "template";
439  if (params.size() > 0)
440  {
441  const Object& oparam = params[0].get_obj();
442  const Value& modeval = find_value(oparam, "mode");
443  if (modeval.type() == str_type)
444  strMode = modeval.get_str();
445  else if (modeval.type() == null_type)
446  {
447  /* Do nothing */
448  }
449  else
450  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
451  }
452 
453  if (strMode != "template")
454  throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
455 
456  if (vNodes.empty())
457  throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, "Feathercoin is not connected!");
458 
460  throw JSONRPCError(RPC_CLIENT_IN_INITIAL_DOWNLOAD, "Feathercoin is downloading blocks...");
461 
462  // Update block
463  static unsigned int nTransactionsUpdatedLast;
464  static CBlockIndex* pindexPrev;
465  static int64 nStart;
466  static CBlockTemplate* pblocktemplate;
467  if (pindexPrev != pindexBest ||
468  (nTransactionsUpdated != nTransactionsUpdatedLast && GetTime() - nStart > 5))
469  {
470  // Clear pindexPrev so future calls make a new block, despite any failures from here on
471  pindexPrev = NULL;
472 
473  // Store the pindexBest used before CreateNewBlock, to avoid races
474  nTransactionsUpdatedLast = nTransactionsUpdated;
475  CBlockIndex* pindexPrevNew = pindexBest;
476  nStart = GetTime();
477 
478  // Create new block
479  if(pblocktemplate)
480  {
481  delete pblocktemplate;
482  pblocktemplate = NULL;
483  }
484  CScript scriptDummy = CScript() << OP_TRUE;
485  pblocktemplate = CreateNewBlock(scriptDummy);
486  if (!pblocktemplate)
487  throw JSONRPCError(RPC_OUT_OF_MEMORY, "Out of memory");
488 
489  // Need to update only after we know CreateNewBlock succeeded
490  pindexPrev = pindexPrevNew;
491  }
492  CBlock* pblock = &pblocktemplate->block; // pointer for convenience
493 
494  // Update nTime
495  pblock->UpdateTime(pindexPrev);
496  pblock->nNonce = 0;
497 
498  Array transactions;
499  map<uint256, int64_t> setTxIndex;
500  int i = 0;
501  BOOST_FOREACH (CTransaction& tx, pblock->vtx)
502  {
503  uint256 txHash = tx.GetHash();
504  setTxIndex[txHash] = i++;
505 
506  if (tx.IsCoinBase())
507  continue;
508 
509  Object entry;
510 
511  CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
512  ssTx << tx;
513  entry.push_back(Pair("data", HexStr(ssTx.begin(), ssTx.end())));
514 
515  entry.push_back(Pair("hash", txHash.GetHex()));
516 
517  Array deps;
518  BOOST_FOREACH (const CTxIn &in, tx.vin)
519  {
520  if (setTxIndex.count(in.prevout.hash))
521  deps.push_back(setTxIndex[in.prevout.hash]);
522  }
523  entry.push_back(Pair("depends", deps));
524 
525  int index_in_template = i - 1;
526  entry.push_back(Pair("fee", pblocktemplate->vTxFees[index_in_template]));
527  entry.push_back(Pair("sigops", pblocktemplate->vTxSigOps[index_in_template]));
528 
529  transactions.push_back(entry);
530  }
531 
532  Object aux;
533  aux.push_back(Pair("flags", HexStr(COINBASE_FLAGS.begin(), COINBASE_FLAGS.end())));
534 
535  uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();
536 
537  static Array aMutable;
538  if (aMutable.empty())
539  {
540  aMutable.push_back("time");
541  aMutable.push_back("transactions");
542  aMutable.push_back("prevblock");
543  }
544 
545  Object result;
546  result.push_back(Pair("version", pblock->nVersion));
547  result.push_back(Pair("previousblockhash", pblock->hashPrevBlock.GetHex()));
548  result.push_back(Pair("transactions", transactions));
549  result.push_back(Pair("coinbaseaux", aux));
550  result.push_back(Pair("coinbasevalue", (int64_t)pblock->vtx[0].vout[0].nValue));
551  result.push_back(Pair("target", hashTarget.GetHex()));
552  result.push_back(Pair("mintime", (int64_t)pindexPrev->GetMedianTimePast()+1));
553  result.push_back(Pair("mutable", aMutable));
554  result.push_back(Pair("noncerange", "00000000ffffffff"));
555  result.push_back(Pair("sigoplimit", (int64_t)MAX_BLOCK_SIGOPS));
556  result.push_back(Pair("sizelimit", (int64_t)MAX_BLOCK_SIZE));
557  result.push_back(Pair("curtime", (int64_t)pblock->nTime));
558  result.push_back(Pair("bits", HexBits(pblock->nBits)));
559  result.push_back(Pair("height", (int64_t)(pindexPrev->nHeight+1)));
560 
561  return result;
562 }
563 
564 Value submitblock(const Array& params, bool fHelp)
565 {
566  if (fHelp || params.size() < 1 || params.size() > 2)
567  throw runtime_error(
568  "submitblock <hex data> [optional-params-obj]\n"
569  "[optional-params-obj] parameter is currently ignored.\n"
570  "Attempts to submit new block to network.\n"
571  "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.");
572 
573  vector<unsigned char> blockData(ParseHex(params[0].get_str()));
574  CDataStream ssBlock(blockData, SER_NETWORK, PROTOCOL_VERSION);
575  CBlock pblock;
576  try {
577  ssBlock >> pblock;
578  }
579  catch (std::exception &e) {
580  throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed");
581  }
582 
584  bool fAccepted = ProcessBlock(state, NULL, &pblock);
585  if (!fAccepted)
586  return "rejected"; // TODO: report validation state
587 
588  return Value::null;
589 }
CBlockIndex * FindBlockByHeight(int nHeight)
Find a block by height in the currently-connected chain.
Definition: main.cpp:1041
const Object & get_obj() const
void GenerateBitcoins(bool fGenerate, CWallet *pwallet)
Run the miner threads.
Definition: main.cpp:4800
double GetDifficulty(const CBlockIndex *blockindex=NULL)
int64 nHPSTimerStart
Definition: main.cpp:81
int nVersion
Definition: main.h:1283
const_iterator begin() const
Definition: serialize.h:884
CBlockIndex * pprev
Definition: main.h:1633
uint256 getuint256() const
Definition: bignum.h:225
Definition: main.h:1334
Value setgenerate(const Array &params, bool fHelp)
Definition: rpcmining.cpp:103
#define END(a)
Definition: util.h:40
uint64 nLastBlockTx
Definition: main.cpp:4292
int64 GetBlockTime() const
Definition: main.h:1749
void ShutdownRPCMining()
Definition: rpcmining.cpp:81
Value GetNetworkHashPS(int lookup, int height)
Definition: rpcmining.cpp:17
std::vector< int64_t > vTxFees
Definition: main.h:2249
void IncrementExtraNonce(CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Modify the extranonce in a block.
Definition: main.cpp:4568
string GetWarnings(string strFor)
Definition: main.cpp:3075
uint256 GetHash() const
Definition: main.h:515
Double ended buffer combining vector and stream-like interfaces.
Definition: serialize.h:799
int64 GetMedianTimePast() const
Definition: main.h:1777
Object JSONRPCError(int code, const string &message)
Definition: bitcoinrpc.cpp:46
uint256 nChainWork
Definition: main.h:1651
Config::Object_type Object
vector< CNode * > vNodes
Definition: net.cpp:56
CBlockTemplate * CreateNewBlockWithKey(CReserveKey &reservekey)
Definition: main.cpp:4558
int64 GetTime()
Definition: util.cpp:1298
uint256 BuildMerkleTree() const
Definition: main.h:1386
int64 GetTimeMillis()
Definition: util.h:340
bool CheckWork(CBlock *pblock, CWallet &wallet, CReserveKey &reservekey)
Check mined block.
Definition: main.cpp:4632
CBigNum & SetCompact(unsigned int nCompact)
Definition: bignum.h:289
Value getgenerate(const Array &params, bool fHelp)
Definition: rpcmining.cpp:89
Value_type type() const
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:600
bool fTestNet
Definition: util.cpp:81
double getdouble() const
Definition: uint256.h:59
CScript COINBASE_FLAGS
Definition: main.cpp:76
unsigned long size()
Definition: main.h:2113
uint256 hashMerkleRoot
Definition: main.h:1285
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
Definition: main.cpp:1276
#define printf
Definition: rpcdump.cpp:12
An input of a transaction.
Definition: main.h:323
std::string itostr(int n)
Definition: util.h:248
const Object_type::value_type::Value_type & find_value(const Object_type &obj, const String_type &name)
unsigned long long uint64_t
Definition: stdint.h:22
static const Value_impl null
uint256 hashPrevBlock
Definition: main.h:1284
MTState * state
Definition: db_test.cc:1708
Value getmininginfo(const Array &params, bool fHelp)
Definition: rpcmining.cpp:143
C++ wrapper for BIGNUM (OpenSSL bignum)
Definition: bignum.h:51
CWallet * pwalletMain
Definition: init.cpp:31
uint64 nLastBlockSize
Definition: main.cpp:4293
unsigned int nNonce
Definition: main.h:1288
Config::Array_type Array
const String_type & get_str() const
std::string GetHex() const
Definition: uint256.h:298
Value submitblock(const Array &params, bool fHelp)
Definition: rpcmining.cpp:564
std::vector< uint256 > GetMerkleBranch(int nIndex) const
Definition: main.h:1411
CBlockTemplate * CreateNewBlock(const CScript &scriptPubKeyIn)
Generate a new block, without valid proof-of-work.
Definition: main.cpp:4319
CTxMemPool mempool
Definition: main.cpp:34
std::string HexBits(unsigned int nBits)
Definition: bitcoinrpc.cpp:110
double dHashesPerSec
Definition: main.cpp:80
Value getwork(const Array &params, bool fHelp)
Definition: rpcmining.cpp:302
#define BEGIN(a)
Definition: util.h:39
Capture information about block/transaction validation.
Definition: main.h:1907
256-bit unsigned integer
Definition: uint256.h:537
unsigned int nTime
Definition: main.h:1286
bool ProcessBlock(CValidationState &state, CNode *pfrom, CBlock *pblock, CDiskBlockPos *dbp)
Process an incoming block.
Definition: main.cpp:2339
A key allocated from the key pool.
Definition: wallet.h:318
uint32_t ByteReverse(uint32_t value)
Definition: util.h:548
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:1626
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:244
void InitRPCMining()
Definition: rpcmining.cpp:72
std::string ToString() const
Definition: uint256.h:343
std::vector< int64_t > vTxSigOps
Definition: main.h:2250
Value gethashespersec(const Array &params, bool fHelp)
Definition: rpcmining.cpp:130
unsigned int nTransactionsUpdated
Definition: main.cpp:35
Value getworkex(const Array &params, bool fHelp)
Definition: rpcmining.cpp:166
bool IsCoinBase() const
Definition: main.h:566
signed long long int64_t
Definition: stdint.h:18
void UpdateTime(const CBlockIndex *pindexPrev)
Definition: main.cpp:1373
CBlockIndex * pindexBest
Definition: main.cpp:45
CBlock block
Definition: main.h:2248
Value getnetworkhashps(const Array &params, bool fHelp)
Definition: rpcmining.cpp:54
std::vector< CTransaction > vtx
Definition: main.h:1338
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:586
Value getblocktemplate(const Array &params, bool fHelp)
Definition: rpcmining.cpp:416
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: main.h:477
int nHeight
Definition: main.h:1639
unsigned int nBits
Definition: main.h:1287
int nBestHeight
Definition: main.cpp:41
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:292
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
Definition: script.h:78
COutPoint prevout
Definition: main.h:326
Config::Pair_type Pair
vector< unsigned char > ParseHex(const char *psz)
Definition: util.cpp:500
map< string, string > mapArgs
Definition: util.cpp:71
const_iterator end() const
Definition: serialize.h:886
void FormatHashBuffers(CBlock *pblock, char *pmidstate, char *pdata, char *phash1)
Do mining precalculation.
Definition: main.cpp:4586
uint256 hash
Definition: main.h:281
long long int64
Definition: serialize.h:25