36 int64 maxTime = minTime;
37 for (
int i = 0; i < lookup; i++) {
40 minTime = std::min(time, minTime);
41 maxTime = std::max(time, maxTime);
45 if (minTime == maxTime)
49 int64 timeDiff = maxTime - minTime;
56 if (fHelp || params.size() > 2)
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.");
63 return GetNetworkHashPS(params.size() > 0 ? params[0].get_int() : 30, params.size() > 1 ? params[1].get_int() : -1);
86 delete pMiningKey; pMiningKey = NULL;
91 if (fHelp || params.size() != 0)
94 "Returns true or false.");
105 if (fHelp || params.size() < 1 || params.size() > 2)
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.");
111 bool fGenerate =
true;
112 if (params.size() > 0)
113 fGenerate = params[0].get_bool();
115 if (params.size() > 1)
117 int nGenProcLimit = params[1].
get_int();
119 if (nGenProcLimit == 0)
122 mapArgs[
"-gen"] = (fGenerate ?
"1" :
"0");
132 if (fHelp || params.size() != 0)
135 "Returns a recent hashes per second performance measurement while generating.");
145 if (fHelp || params.size() != 0)
148 "Returns an object containing mining-related information.");
157 obj.push_back(
Pair(
"genproclimit", (
int)
GetArg(
"-genproclimit", -1)));
168 if (fHelp || params.size() > 2)
170 "getworkex [data, coinbase]\n"
171 "If [data, coinbase] is not specified, returns extended work data.\n"
180 typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
181 static mapNewBlock_t mapNewBlock;
182 static vector<CBlockTemplate*> vNewBlockTemplate;
185 if (params.size() == 0)
188 static unsigned int nTransactionsUpdatedLast;
200 delete pblocktemplate;
201 vNewBlockTemplate.clear();
216 vNewBlockTemplate.push_back(pblocktemplate);
219 pindexPrev = pindexPrevNew;
228 static unsigned int nExtraNonce = 0;
232 mapNewBlock[pblock->
hashMerkleRoot] = make_pair(pblock, pblock->
vtx[0].vin[0].scriptSig);
255 BOOST_FOREACH(
uint256 merkleh, merkle) {
260 result.push_back(
Pair(
"merkle", merkle_arr));
268 vector<unsigned char> coinbase;
270 if(params.size() == 2)
273 if (vchData.size() != 128)
279 for (
int i = 0; i < 128/4; i++)
280 ((
unsigned int*)pdata)[i] =
ByteReverse(((
unsigned int*)pdata)[i]);
290 if(coinbase.size() == 0)
304 if (fHelp || params.size() > 1)
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"
309 " \"data\" : block data\n"
310 " \"hash1\" : formatted hash buffer for second hash (DEPRECATED)\n"
311 " \"target\" : little endian hash target\n"
312 "If [data] is specified, tries to solve the block and returns true if it was successful.");
320 typedef map<uint256, pair<CBlock*, CScript> > mapNewBlock_t;
321 static mapNewBlock_t mapNewBlock;
322 static vector<CBlockTemplate*> vNewBlockTemplate;
324 if (params.size() == 0)
327 static unsigned int nTransactionsUpdatedLast;
339 delete pblocktemplate;
340 vNewBlockTemplate.clear();
355 vNewBlockTemplate.push_back(pblocktemplate);
358 pindexPrev = pindexPrevNew;
367 static unsigned int nExtraNonce = 0;
371 mapNewBlock[pblock->
hashMerkleRoot] = make_pair(pblock, pblock->
vtx[0].vin[0].scriptSig);
392 if (vchData.size() != 128)
397 for (
int i = 0; i < 128/4; i++)
398 ((
unsigned int*)pdata)[i] =
ByteReverse(((
unsigned int*)pdata)[i]);
418 if (fHelp || params.size() > 1)
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.");
438 std::string strMode =
"template";
439 if (params.size() > 0)
453 if (strMode !=
"template")
463 static unsigned int nTransactionsUpdatedLast;
481 delete pblocktemplate;
482 pblocktemplate = NULL;
490 pindexPrev = pindexPrevNew;
499 map<uint256, int64_t> setTxIndex;
504 setTxIndex[txHash] = i++;
515 entry.push_back(
Pair(
"hash", txHash.
GetHex()));
518 BOOST_FOREACH (
const CTxIn &in, tx.vin)
523 entry.push_back(
Pair(
"depends", deps));
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]));
529 transactions.push_back(entry);
537 static Array aMutable;
538 if (aMutable.empty())
540 aMutable.push_back(
"time");
541 aMutable.push_back(
"transactions");
542 aMutable.push_back(
"prevblock");
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()));
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));
566 if (fHelp || params.size() < 1 || params.size() > 2)
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.");
579 catch (std::exception &e) {
CBlockIndex * FindBlockByHeight(int nHeight)
Find a block by height in the currently-connected chain.
const Object & get_obj() const
void GenerateBitcoins(bool fGenerate, CWallet *pwallet)
Run the miner threads.
double GetDifficulty(const CBlockIndex *blockindex=NULL)
const_iterator begin() const
uint256 getuint256() const
Value setgenerate(const Array ¶ms, bool fHelp)
int64 GetBlockTime() const
Value GetNetworkHashPS(int lookup, int height)
std::vector< int64_t > vTxFees
void IncrementExtraNonce(CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Modify the extranonce in a block.
string GetWarnings(string strFor)
Double ended buffer combining vector and stream-like interfaces.
int64 GetMedianTimePast() const
Object JSONRPCError(int code, const string &message)
Config::Object_type Object
CBlockTemplate * CreateNewBlockWithKey(CReserveKey &reservekey)
uint256 BuildMerkleTree() const
bool CheckWork(CBlock *pblock, CWallet &wallet, CReserveKey &reservekey)
Check mined block.
CBigNum & SetCompact(unsigned int nCompact)
Value getgenerate(const Array ¶ms, bool fHelp)
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
An input of a transaction.
std::string itostr(int n)
const Object_type::value_type::Value_type & find_value(const Object_type &obj, const String_type &name)
unsigned long long uint64_t
static const Value_impl null
Value getmininginfo(const Array ¶ms, bool fHelp)
C++ wrapper for BIGNUM (OpenSSL bignum)
const String_type & get_str() const
std::string GetHex() const
Value submitblock(const Array ¶ms, bool fHelp)
std::vector< uint256 > GetMerkleBranch(int nIndex) const
CBlockTemplate * CreateNewBlock(const CScript &scriptPubKeyIn)
Generate a new block, without valid proof-of-work.
std::string HexBits(unsigned int nBits)
Value getwork(const Array ¶ms, bool fHelp)
Capture information about block/transaction validation.
bool ProcessBlock(CValidationState &state, CNode *pfrom, CBlock *pblock, CDiskBlockPos *dbp)
Process an incoming block.
A key allocated from the key pool.
uint32_t ByteReverse(uint32_t value)
The block chain is a tree shaped structure starting with the genesis block at the root...
Serialized script, used inside transaction inputs and outputs.
std::string ToString() const
std::vector< int64_t > vTxSigOps
Value gethashespersec(const Array ¶ms, bool fHelp)
unsigned int nTransactionsUpdated
Value getworkex(const Array ¶ms, bool fHelp)
Value getnetworkhashps(const Array ¶ms, bool fHelp)
std::vector< CTransaction > vtx
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Value getblocktemplate(const Array ¶ms, bool fHelp)
The basic transaction that is broadcasted on the network and contained in blocks. ...
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
std::string get_str(std::string::const_iterator begin, std::string::const_iterator end)
vector< unsigned char > ParseHex(const char *psz)
map< string, string > mapArgs
const_iterator end() const
void FormatHashBuffers(CBlock *pblock, char *pmidstate, char *pdata, char *phash1)
Do mining precalculation.