32 #include <boost/assign/list_of.hpp> 33 #include <boost/shared_ptr.hpp> 63 int64_t maxTime = minTime;
64 for (
int i = 0; i < lookup; i++) {
67 minTime = std::min(time, minTime);
68 maxTime = std::max(time, maxTime);
72 if (minTime == maxTime)
76 int64_t timeDiff = maxTime - minTime;
83 if (fHelp || params.
size() > 2)
85 "getnetworkhashps ( blocks height )\n" 86 "\nReturns the estimated network hashes per second based on the last n blocks.\n" 87 "Pass in [blocks] to override # of blocks, -1 specifies since last difficulty change.\n" 88 "Pass in [height] to estimate the network speed at the time when a certain block was found.\n" 90 "1. blocks (numeric, optional, default=120) The number of blocks, or -1 for blocks since last difficulty change.\n" 91 "2. height (numeric, optional, default=-1) To estimate at the time of the given height.\n" 93 "x (numeric) Hashes per second estimated\n" 105 if (fHelp || params.
size() != 0)
108 "\nReturn if the server is set to generate coins or not. The default is false.\n" 109 "It is set with the command line argument -gen (or " + std::string(
BITCOIN_CONF_FILENAME) +
" setting gen)\n" 110 "It can also be set with the setgenerate call.\n" 112 "true|false (boolean) If the server is set to generate coins or not\n" 124 if (fHelp || params.
size() < 1 || params.
size() > 1)
126 "generate numblocks\n" 127 "\nMine blocks immediately (before the RPC call returns)\n" 128 "\nNote: this function can only be used on the regtest network\n" 130 "1. numblocks (numeric, required) How many blocks are generated immediately.\n" 132 "[ blockhashes ] (array) hashes of blocks generated\n" 134 "\nGenerate 11 blocks\n" 141 int nHeightStart = 0;
144 int nGenerate = params[0].
get_int();
146 boost::shared_ptr<CReserveScript> coinbaseScript;
154 if (coinbaseScript->reserveScript.empty())
160 nHeight = nHeightStart;
161 nHeightEnd = nHeightStart+nGenerate;
163 unsigned int nExtraNonce = 0;
165 while (nHeight < nHeightEnd)
167 std::unique_ptr<CBlockTemplate> pblocktemplate(
CreateNewBlock(
Params(), coinbaseScript->reserveScript));
168 if (!pblocktemplate.get())
170 CBlock *pblock = &pblocktemplate->block;
186 coinbaseScript->KeepScript();
193 if (fHelp || params.
size() < 1 || params.
size() > 2)
195 "setgenerate generate ( genproclimit )\n" 196 "\nSet 'generate' true or false to turn generation on or off.\n" 197 "Generation is limited to 'genproclimit' processors, -1 is unlimited.\n" 198 "See the getgenerate call for the current setting.\n" 200 "1. generate (boolean, required) Set to true to turn on generation, false to turn off.\n" 201 "2. genproclimit (numeric, optional) Set the processor limit for when generation is on. Can be -1 for unlimited.\n" 203 "\nSet the generation on with a limit of one processor\n" 205 "\nCheck the setting\n" 207 "\nTurn off generation\n" 216 bool fGenerate =
true;
217 if (params.
size() > 0)
218 fGenerate = params[0].get_bool();
221 if (params.
size() > 1)
223 nGenProcLimit = params[1].
get_int();
224 if (nGenProcLimit == 0)
228 mapArgs[
"-gen"] = (fGenerate ?
"1" :
"0");
237 if (fHelp || params.
size() != 0)
240 "\nReturns a json object containing mining-related information." 243 " \"blocks\": nnn, (numeric) The current block\n" 244 " \"currentblocksize\": nnn, (numeric) The last block size\n" 245 " \"currentblocktx\": nnn, (numeric) The last block transaction\n" 246 " \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n" 247 " \"errors\": \"...\" (string) Current errors\n" 248 " \"generate\": true|false (boolean) If the generation is on or off (see getgenerate or setgenerate calls)\n" 249 " \"genproclimit\": n (numeric) The processor limit for generation. -1 if no generation. (see getgenerate or setgenerate calls)\n" 250 " \"pooledtx\": n (numeric) The size of the mem pool\n" 251 " \"testnet\": true|false (boolean) If using testnet or not\n" 252 " \"chain\": \"xxxx\", (string) current network name as defined in BIP70 (main, test, regtest)\n" 281 if (fHelp || params.
size() != 3)
283 "prioritisetransaction <txid> <priority delta> <fee delta>\n" 284 "Accepts the transaction into mined blocks at a higher (or lower) priority\n" 286 "1. \"txid\" (string, required) The transaction id.\n" 287 "2. priority delta (numeric, required) The priority to add or subtract.\n" 288 " The transaction selection algorithm considers the tx as it would have a higher priority.\n" 289 " (priority of a transaction is calculated: coinage * value_in_duffs / txsize) \n" 290 "3. fee delta (numeric, required) The fee value (in duffs) to add (or subtract, if negative).\n" 291 " The fee is not actually paid, only the algorithm for selecting transactions into a block\n" 292 " considers the transaction as it would have paid a higher (or lower) fee.\n" 294 "true (boolean) Returns true\n" 320 if (strRejectReason.empty())
322 return strRejectReason;
330 std::string s = vbinfo.
name;
332 s.insert(s.begin(),
'!');
339 if (fHelp || params.
size() > 1)
341 "getblocktemplate ( \"jsonrequestobject\" )\n" 342 "\nIf the request parameters include a 'mode' key, that is used to explicitly select between the default 'template' request or a 'proposal'.\n" 343 "It returns data needed to construct a block to work on.\n" 344 "For full specification, see BIPs 22 and 9:\n" 345 " https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki\n" 346 " https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki#getblocktemplate_changes\n" 349 "1. \"jsonrequestobject\" (string, optional) A json object in the following spec\n" 351 " \"mode\":\"template\" (string, optional) This must be set to \"template\" or omitted\n" 352 " \"capabilities\":[ (array, optional) A list of strings\n" 353 " \"support\" (string) client side supported feature, 'longpoll', 'coinbasetxn', 'coinbasevalue', 'proposal', 'serverlist', 'workid'\n" 361 " \"version\" : n, (numeric) The block version\n" 362 " \"rules\" : [ \"rulename\", ... ], (array of strings) specific block rules that are to be enforced\n" 363 " \"vbavailable\" : { (json object) set of pending, supported versionbit (BIP 9) softfork deployments\n" 364 " \"rulename\" : bitnumber (numeric) identifies the bit number as indicating acceptance and readiness for the named softfork rule\n" 367 " \"vbrequired\" : n, (numeric) bit mask of versionbits the server requires set in submissions\n" 368 " \"previousblockhash\" : \"xxxx\", (string) The hash of current highest block\n" 369 " \"transactions\" : [ (array) contents of non-coinbase transactions that should be included in the next block\n" 371 " \"data\" : \"xxxx\", (string) transaction data encoded in hexadecimal (byte-for-byte)\n" 372 " \"hash\" : \"xxxx\", (string) hash/id encoded in little-endian hexadecimal\n" 373 " \"depends\" : [ (array) array of numbers \n" 374 " n (numeric) transactions before this one (by 1-based index in 'transactions' list) that must be present in the final block if this one is\n" 377 " \"fee\": n, (numeric) difference in value between transaction inputs and outputs (in duffs); for coinbase transactions, this is a negative Number of the total collected block fees (ie, not including the block subsidy); if key is not present, fee is unknown and clients MUST NOT assume there isn't one\n" 378 " \"sigops\" : n, (numeric) total number of SigOps, as counted for purposes of block limits; if key is not present, sigop count is unknown and clients MUST NOT assume there aren't any\n" 379 " \"required\" : true|false (boolean) if provided and true, this transaction must be in the final block\n" 383 " \"coinbaseaux\" : { (json object) data that should be included in the coinbase's scriptSig content\n" 384 " \"flags\" : \"flags\" (string) \n" 386 " \"coinbasevalue\" : n, (numeric) maximum allowable input to coinbase transaction, including the generation award and transaction fees (in duffs)\n" 387 " \"coinbasetxn\" : { ... }, (json object) information for coinbase transaction\n" 388 " \"target\" : \"xxxx\", (string) The hash target\n" 389 " \"mintime\" : xxx, (numeric) The minimum timestamp appropriate for next block time in seconds since epoch (Jan 1 1970 GMT)\n" 390 " \"mutable\" : [ (array of string) list of ways the block template may be changed \n" 391 " \"value\" (string) A way the block template may be changed, e.g. 'time', 'transactions', 'prevblock'\n" 394 " \"noncerange\" : \"00000000ffffffff\", (string) A range of valid nonces\n" 395 " \"sigoplimit\" : n, (numeric) limit of sigops in blocks\n" 396 " \"sizelimit\" : n, (numeric) limit of block size\n" 397 " \"curtime\" : ttt, (numeric) current timestamp in seconds since epoch (Jan 1 1970 GMT)\n" 398 " \"bits\" : \"xxx\", (string) compressed target of next block\n" 399 " \"height\" : n (numeric) The height of the next block\n" 400 " \"masternode\" : { (json object) required masternode payee that must be included in the next block\n" 401 " \"payee\" : \"xxxx\", (string) payee address\n" 402 " \"script\" : \"xxxx\", (string) payee scriptPubKey\n" 403 " \"amount\": n (numeric) required amount to pay\n" 405 " \"masternode_payments_started\" : true|false, (boolean) true, if masternode payments started\n" 406 " \"masternode_payments_enforced\" : true|false, (boolean) true, if masternode payments are enforced\n" 407 " \"superblock\" : [ (array) required superblock payees that must be included in the next block\n" 409 " \"payee\" : \"xxxx\", (string) payee address\n" 410 " \"script\" : \"xxxx\", (string) payee scriptPubKey\n" 411 " \"amount\": n (numeric) required amount to pay\n" 415 " \"superblocks_started\" : true|false, (boolean) true, if superblock payments started\n" 416 " \"superblocks_enabled\" : true|false (boolean) true, if superblock payments are enabled\n" 426 std::string strMode =
"template";
428 std::set<std::string> setClientRules;
429 int64_t nMaxVersionPreVB = -1;
430 if (params.
size() > 0)
436 else if (modeval.
isNull())
444 if (strMode ==
"proposal")
447 if (!dataval.
isStr())
461 return "duplicate-invalid";
462 return "duplicate-inconclusive";
468 return "inconclusive-not-best-prevblk";
476 for (
unsigned int i = 0; i < aClientRules.
size(); ++i) {
477 const UniValue& v = aClientRules[i];
478 setClientRules.insert(v.
get_str());
483 if (uvMaxVersion.
isNum()) {
484 nMaxVersionPreVB = uvMaxVersion.
get_int64();
489 if (strMode !=
"template")
504 static unsigned int nTransactionsUpdatedLast;
510 boost::system_time checktxtime;
511 unsigned int nTransactionsUpdatedLastLP;
516 std::string lpstr = lpval.
get_str();
518 hashWatchedChain.
SetHex(lpstr.substr(0, 64));
519 nTransactionsUpdatedLastLP =
atoi64(lpstr.substr(64));
525 nTransactionsUpdatedLastLP = nTransactionsUpdatedLast;
531 checktxtime = boost::get_system_time() + boost::posix_time::minutes(1);
533 boost::unique_lock<boost::mutex> lock(
csBestBlock);
541 checktxtime += boost::posix_time::seconds(10);
554 static int64_t nStart;
570 delete pblocktemplate;
571 pblocktemplate = NULL;
579 pindexPrev = pindexPrevNew;
585 UpdateTime(pblock, consensusParams, pindexPrev);
591 map<uint256, int64_t> setTxIndex;
595 setTxIndex[txHash] = i++;
607 BOOST_FOREACH (
const CTxIn &in, tx.
vin)
614 int index_in_template = i - 1;
632 result.push_back(
Pair(
"capabilities", aCaps));
652 if (setClientRules.find(vbinfo.
name) == setClientRules.end()) {
665 if (setClientRules.find(vbinfo.
name) == setClientRules.end()) {
678 result.push_back(
Pair(
"vbavailable", vbavailable));
681 if (nMaxVersionPreVB >= 2) {
690 result.push_back(
Pair(
"transactions", transactions));
692 result.push_back(
Pair(
"coinbasevalue", (int64_t)pblock->
vtx[0].GetValueOut()));
697 result.push_back(
Pair(
"noncerange",
"00000000ffffffff"));
713 result.push_back(
Pair(
"masternode", masternodeObj));
714 result.push_back(
Pair(
"masternode_payments_started", pindexPrev->
nHeight + 1 >
Params().GetConsensus().nMasternodePaymentsStartBlock));
730 result.push_back(
Pair(
"superblock", superblockObjArray));
731 result.push_back(
Pair(
"superblocks_started", pindexPrev->
nHeight + 1 >
Params().GetConsensus().nSuperblockStartBlock));
757 if (fHelp || params.
size() < 1 || params.
size() > 2)
759 "submitblock \"hexdata\" ( \"jsonparametersobject\" )\n" 760 "\nAttempts to submit new block to network.\n" 761 "The 'jsonparametersobject' parameter is currently ignored.\n" 762 "See https://en.bitcoin.it/wiki/BIP_0022 for full specification.\n" 765 "1. \"hexdata\" (string, required) the hex-encoded block data to submit\n" 766 "2. \"jsonparametersobject\" (string, optional) object of optional parameters\n" 768 " \"workid\" : \"id\" (string, optional) if the server provided a workid, it MUST be included with submissions\n" 781 bool fBlockPresent =
false;
790 return "duplicate-invalid";
792 fBlockPresent =
true;
802 if (fAccepted && !sc.found)
803 return "duplicate-inconclusive";
807 return "inconclusive";
813 if (fHelp || params.
size() != 1)
815 "estimatefee nblocks\n" 816 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" 817 "confirmation within nblocks blocks.\n" 819 "1. nblocks (numeric)\n" 821 "n (numeric) estimated fee-per-kilobyte\n" 823 "A negative value is returned if not enough transactions and blocks\n" 824 "have been observed to make an estimate.\n" 831 int nBlocks = params[0].
get_int();
844 if (fHelp || params.
size() != 1)
846 "estimatepriority nblocks\n" 847 "\nEstimates the approximate priority a zero-fee transaction needs to begin\n" 848 "confirmation within nblocks blocks.\n" 850 "1. nblocks (numeric)\n" 852 "n (numeric) estimated priority\n" 854 "A negative value is returned if not enough transactions and blocks\n" 855 "have been observed to make an estimate.\n" 862 int nBlocks = params[0].
get_int();
871 if (fHelp || params.
size() != 1)
873 "estimatesmartfee nblocks\n" 874 "\nWARNING: This interface is unstable and may disappear or change!\n" 875 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" 876 "confirmation within nblocks blocks if possible and return the number of blocks\n" 877 "for which the estimate is valid.\n" 879 "1. nblocks (numeric)\n" 882 " \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in BTC)\n" 883 " \"blocks\" : n (numeric) block number where estimate was found\n" 886 "A negative value is returned if not enough transactions and blocks\n" 887 "have been observed to make an estimate for any number of blocks.\n" 888 "However it will not return a value below the mempool reject fee.\n" 895 int nBlocks = params[0].
get_int();
901 result.push_back(
Pair(
"blocks", answerFound));
907 if (fHelp || params.
size() != 1)
909 "estimatesmartpriority nblocks\n" 910 "\nWARNING: This interface is unstable and may disappear or change!\n" 911 "\nEstimates the approximate priority a zero-fee transaction needs to begin\n" 912 "confirmation within nblocks blocks if possible and return the number of blocks\n" 913 "for which the estimate is valid.\n" 915 "1. nblocks (numeric)\n" 918 " \"priority\" : x.x, (numeric) estimated priority\n" 919 " \"blocks\" : n (numeric) block number where estimate was found\n" 922 "A negative value is returned if not enough transactions and blocks\n" 923 "have been observed to make an estimate for any number of blocks.\n" 924 "However if the mempool reject fee is set it will return 1e9 * MAX_MONEY.\n" 931 int nBlocks = params[0].
get_int();
937 result.push_back(
Pair(
"blocks", answerFound));
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
boost::signals2::signal< void(boost::shared_ptr< CReserveScript > &)> ScriptForMining
UniValue prioritisetransaction(const UniValue ¶ms, bool fHelp)
UniValue getnetworkhashps(const UniValue ¶ms, bool fHelp)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
CMasternodeSync masternodeSync
bool DecodeHexBlk(CBlock &, const std::string &strHexBlk)
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
const char *const BITCOIN_CONF_FILENAME
int64_t UpdateTime(CBlockHeader *pblock, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev)
std::string GetRejectReason() const
unsigned int MaxBlockSize(bool fDIP0001Active)
descends from failed block
CWaitableCriticalSection csBestBlock
submitblock_StateCatcher(const uint256 &hashIn)
const Consensus::Params & GetConsensus() const
CFeeRate estimateSmartFee(int nBlocks, int *answerFoundAtBlocks=NULL) const
static const int DEFAULT_GENERATE_THREADS
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
UniValue getblocktemplate(const UniValue ¶ms, bool fHelp)
UniValue GetNetworkHashPS(int lookup, int height)
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=NULL, bool *pfOverflow=NULL)
double estimateSmartPriority(int nBlocks, int *answerFoundAtBlocks=NULL) const
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
static const int SPORK_9_SUPERBLOCKS_ENABLED
std::string HelpExampleRpc(const std::string &methodname, const std::string &args)
double GetDifficulty(const CBlockIndex *blockindex)
uint32_t VersionBitsMask(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
UniValue estimatepriority(const UniValue ¶ms, bool fHelp)
std::vector< CTxOut > voutSuperblock
bool push_back(const UniValue &val)
UniValue ValueFromAmount(const CAmount &amount)
Ran out of memory during operation.
std::vector< CAmount > vTxFees
const UniValue & find_value(const UniValue &obj, const std::string &name)
std::vector< CTransaction > vtx
UniValue submitblock(const UniValue ¶ms, bool fHelp)
std::string ToString() const
int64_t get_int64() const
bool ProcessNewBlock(const CChainParams &chainparams, const CBlock *pblock, bool fForceProcessing, const CDiskBlockPos *dbp, bool *fNewBlock)
Error parsing or validating structure in raw format.
const UniValue & get_obj() const
bool GetBoolArg(const std::string &strArg, bool fDefault)
virtual void BlockChecked(const CBlock &block, const CValidationState &stateIn)
#define LEAVE_CRITICAL_SECTION(cs)
BIP9Deployment vDeployments[MAX_VERSION_BITS_DEPLOYMENTS]
unsigned int MaxBlockSigOps(bool fDIP0001Active)
UniValue setgenerate(const UniValue ¶ms, bool fHelp)
CAmount GetFeePerK() const
static const int SPORK_8_MASTERNODE_PAYMENT_ENFORCEMENT
void GenerateBitcoins(bool fGenerate, int nThreads, const CChainParams &chainparams, CConnman &connman)
Server is in safe mode, and command is not allowed in safe mode.
static UniValue BIP22ValidationResult(const CValidationState &state)
bool IsInitialBlockDownload()
std::atomic< bool > fDIP0001ActiveAtTip
CMainSignals & GetMainSignals()
std::string HelpExampleCli(const std::string &methodname, const std::string &args)
static std::pair< std::string, UniValue > Pair(const char *cKey, const char *cVal)
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params ¶ms)
int64_t DifficultyAdjustmentInterval() const
VersionBitsCache versionbitscache
std::vector< int64_t > vTxSigOps
void RegisterValidationInterface(CValidationInterface *pwalletIn)
CSporkManager sporkManager
void IncrementExtraNonce(CBlock *pblock, const CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
#define ENTER_CRITICAL_SECTION(cs)
UniValue generate(const UniValue ¶ms, bool fHelp)
const std::vector< CTxIn > vin
std::string EncodeHexTx(const CTransaction &tx)
void RPCTypeCheck(const UniValue ¶ms, const list< UniValue::VType > &typesExpected, bool fAllowNull)
static const bool DEFAULT_GENERATE
uint256 ParseHashStr(const std::string &, const std::string &strName)
std::string GetWarnings(const std::string &strFor)
const CChainParams & Params()
const uint256 & GetHash() const
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot)
uint256 GetBlockHash() const
std::string GetHex() const
int64_t atoi64(const char *psz)
std::unique_ptr< CConnman > g_connman
const UniValue NullUniValue
std::string i64tostr(int64_t n)
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
CBlockIndex * Tip() const
std::string gbt_vb_name(const Consensus::DeploymentPos pos)
int64_t GetMedianTimePast() const
int64_t GetBlockTime() const
std::string GetArg(const std::string &strArg, const std::string &strDefault)
void PrioritiseTransaction(const uint256 hash, const std::string strHash, double dPriorityDelta, const CAmount &nFeeDelta)
CBlockIndex * pprev
pointer to the index of the predecessor of this block
std::string GetHex() const
bool IsSporkActive(int nSporkID)
int64_t GetTime()
For unit testing.
UniValue estimatesmartfee(const UniValue ¶ms, bool fHelp)
CFeeRate estimateFee(int nBlocks) const
Dash Core is not connected.
CBlockTemplate * CreateNewBlock(const CChainParams &chainparams, const CScript &scriptPubKeyIn)
UniValue estimatefee(const UniValue ¶ms, bool fHelp)
void SetHex(const char *psz)
ThresholdState VersionBitsState(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::DeploymentPos pos, VersionBitsCache &cache)
int nHeight
height of the entry in the chain. The genesis block has height 0
bool MineBlocksOnDemand() const
UniValue estimatesmartpriority(const UniValue ¶ms, bool fHelp)
UniValue JSONRPCError(int code, const string &message)
double estimatePriority(int nBlocks) const
unsigned int GetTransactionsUpdated() const
std::string get_str() const
UniValue getmininginfo(const UniValue ¶ms, bool fHelp)
std::string itostr(int n)
const struct BIP9DeploymentInfo VersionBitsDeploymentInfo[Consensus::MAX_VERSION_BITS_DEPLOYMENTS]
map< string, string > mapArgs
CConditionVariable cvBlockChange
UniValue getgenerate(const UniValue ¶ms, bool fHelp)