Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | static UniValue GetNetworkHashPS(int lookup, int height) { | ||||
int64_t timeDiff = maxTime - minTime; | int64_t timeDiff = maxTime - minTime; | ||||
return workDiff.getdouble() / timeDiff; | return workDiff.getdouble() / timeDiff; | ||||
} | } | ||||
static UniValue getnetworkhashps(const Config &config, | static UniValue getnetworkhashps(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 2) { | if (request.fHelp || request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getnetworkhashps", | "getnetworkhashps", | ||||
"\nReturns the estimated network hashes per second " | "\nReturns the estimated network hashes per second " | ||||
"based on the last n blocks.\n" | "based on the last n blocks.\n" | ||||
"Pass in [blocks] to override # of blocks, -1 specifies " | "Pass in [blocks] to override # of blocks, -1 specifies " | ||||
"since last difficulty change.\n" | "since last difficulty change.\n" | ||||
"Pass in [height] to estimate the network speed at the " | "Pass in [height] to estimate the network speed at the " | ||||
"time when a certain block was found.\n", | "time when a certain block was found.\n", | ||||
{ | { | ||||
{"nblocks", RPCArg::Type::NUM, /* opt */ true, | {"nblocks", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "120", | /* default_val */ "120", | ||||
"The number of blocks, or -1 for blocks since last " | "The number of blocks, or -1 for blocks since last " | ||||
"difficulty change."}, | "difficulty change."}, | ||||
{"height", RPCArg::Type::NUM, /* opt */ true, | {"height", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "-1", | /* default_val */ "-1", | ||||
"To estimate at the time of the given height."}, | "To estimate at the time of the given height."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"x (numeric) Hashes per second estimated\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("getnetworkhashps", "") + | ||||
"x (numeric) Hashes per second estimated\n" | HelpExampleRpc("getnetworkhashps", "")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("getnetworkhashps", "") + | .ToString()); | ||||
HelpExampleRpc("getnetworkhashps", "")); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
return GetNetworkHashPS( | return GetNetworkHashPS( | ||||
!request.params[0].isNull() ? request.params[0].get_int() : 120, | !request.params[0].isNull() ? request.params[0].get_int() : 120, | ||||
!request.params[1].isNull() ? request.params[1].get_int() : -1); | !request.params[1].isNull() ? request.params[1].get_int() : -1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | UniValue generateBlocks(const Config &config, | ||||
return blockHashes; | return blockHashes; | ||||
} | } | ||||
static UniValue generatetoaddress(const Config &config, | static UniValue generatetoaddress(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() < 2 || | if (request.fHelp || request.params.size() < 2 || | ||||
request.params.size() > 3) { | request.params.size() > 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"generatetoaddress", | "generatetoaddress", | ||||
"\nMine blocks immediately to a specified address before the " | "\nMine blocks immediately to a specified address before the " | ||||
"RPC call returns)\n", | "RPC call returns)\n", | ||||
{ | { | ||||
{"nblocks", RPCArg::Type::NUM, /* opt */ false, | {"nblocks", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"How many blocks are generated immediately."}, | "How many blocks are generated immediately."}, | ||||
{"address", RPCArg::Type::STR, /* opt */ false, | {"address", RPCArg::Type::STR, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The address to send the newly generated bitcoin to."}, | "The address to send the newly generated bitcoin to."}, | ||||
{"maxtries", RPCArg::Type::NUM, /* opt */ true, | {"maxtries", RPCArg::Type::NUM, /* opt */ true, | ||||
/* default_val */ "1000000", | /* default_val */ "1000000", "How many iterations to try."}, | ||||
"How many iterations to try."}, | }, | ||||
}} | RPCResult{ | ||||
.ToString() + | "[ blockhashes ] (array) hashes of blocks generated\n"}, | ||||
"\nResult:\n" | RPCExamples{ | ||||
"[ blockhashes ] (array) hashes of blocks generated\n" | |||||
"\nExamples:\n" | |||||
"\nGenerate 11 blocks to myaddress\n" + | "\nGenerate 11 blocks to myaddress\n" + | ||||
HelpExampleCli("generatetoaddress", "11 \"myaddress\"")); | HelpExampleCli("generatetoaddress", "11 \"myaddress\"") + | ||||
"If you are running the bitcoin core wallet, you can get a new " | |||||
"address to send the newly generated bitcoin to with:\n" + | |||||
HelpExampleCli("getnewaddress", "")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
int nGenerate = request.params[0].get_int(); | int nGenerate = request.params[0].get_int(); | ||||
uint64_t nMaxTries = 1000000; | uint64_t nMaxTries = 1000000; | ||||
if (!request.params[2].isNull()) { | if (!request.params[2].isNull()) { | ||||
nMaxTries = request.params[2].get_int(); | nMaxTries = request.params[2].get_int(); | ||||
} | } | ||||
Show All 9 Lines | static UniValue generatetoaddress(const Config &config, | ||||
coinbaseScript->reserveScript = GetScriptForDestination(destination); | coinbaseScript->reserveScript = GetScriptForDestination(destination); | ||||
return generateBlocks(config, coinbaseScript, nGenerate, nMaxTries, false); | return generateBlocks(config, coinbaseScript, nGenerate, nMaxTries, false); | ||||
} | } | ||||
static UniValue getmininginfo(const Config &config, | static UniValue getmininginfo(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 0) { | if (request.fHelp || request.params.size() != 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"getmininginfo", | "getmininginfo", | ||||
"\nReturns a json object containing mining-related " | "\nReturns a json object containing mining-related " | ||||
"information.", | "information.", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"blocks\": nnn, (numeric) The current block\n" | " \"blocks\": nnn, (numeric) The current block\n" | ||||
" \"currentblocksize\": nnn, (numeric) The last block size\n" | " \"currentblocksize\": nnn, (numeric) The last block size\n" | ||||
" \"currentblocktx\": nnn, (numeric) The last block " | " \"currentblocktx\": nnn, (numeric) The last block " | ||||
"transaction\n" | "transaction\n" | ||||
" \"difficulty\": xxx.xxxxx (numeric) The current difficulty\n" | " \"difficulty\": xxx.xxxxx (numeric) The current " | ||||
" \"networkhashps\": nnn, (numeric) The network hashes per " | "difficulty\n" | ||||
" \"networkhashps\": nnn, (numeric) The network hashes " | |||||
"per " | |||||
"second\n" | "second\n" | ||||
" \"pooledtx\": n (numeric) The size of the mempool\n" | " \"pooledtx\": n (numeric) The size of the " | ||||
" \"chain\": \"xxxx\", (string) current network name as " | "mempool\n" | ||||
" \"chain\": \"xxxx\", (string) current network " | |||||
"name as " | |||||
"defined in BIP70 (main, test, regtest)\n" | "defined in BIP70 (main, test, regtest)\n" | ||||
" \"warnings\": \"...\" (string) any network and " | " \"warnings\": \"...\" (string) any network and " | ||||
"blockchain warnings\n" | "blockchain warnings\n" | ||||
"}\n" | "}\n"}, | ||||
"\nExamples:\n" + | RPCExamples{HelpExampleCli("getmininginfo", "") + | ||||
HelpExampleCli("getmininginfo", "") + | HelpExampleRpc("getmininginfo", "")}, | ||||
HelpExampleRpc("getmininginfo", "")); | } | ||||
.ToString()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
UniValue obj(UniValue::VOBJ); | UniValue obj(UniValue::VOBJ); | ||||
obj.pushKV("blocks", int(::ChainActive().Height())); | obj.pushKV("blocks", int(::ChainActive().Height())); | ||||
obj.pushKV("currentblocksize", uint64_t(nLastBlockSize)); | obj.pushKV("currentblocksize", uint64_t(nLastBlockSize)); | ||||
obj.pushKV("currentblocktx", uint64_t(nLastBlockTx)); | obj.pushKV("currentblocktx", uint64_t(nLastBlockTx)); | ||||
obj.pushKV("difficulty", double(GetDifficulty(::ChainActive().Tip()))); | obj.pushKV("difficulty", double(GetDifficulty(::ChainActive().Tip()))); | ||||
obj.pushKV("networkhashps", getnetworkhashps(config, request)); | obj.pushKV("networkhashps", getnetworkhashps(config, request)); | ||||
obj.pushKV("pooledtx", uint64_t(g_mempool.size())); | obj.pushKV("pooledtx", uint64_t(g_mempool.size())); | ||||
obj.pushKV("chain", config.GetChainParams().NetworkIDString()); | obj.pushKV("chain", config.GetChainParams().NetworkIDString()); | ||||
obj.pushKV("warnings", GetWarnings("statusbar")); | obj.pushKV("warnings", GetWarnings("statusbar")); | ||||
return obj; | return obj; | ||||
} | } | ||||
// NOTE: Unlike wallet RPC (which use BCH values), mining RPCs follow GBT (BIP | // NOTE: Unlike wallet RPC (which use BCH values), mining RPCs follow GBT (BIP | ||||
// 22) in using satoshi amounts | // 22) in using satoshi amounts | ||||
static UniValue prioritisetransaction(const Config &config, | static UniValue prioritisetransaction(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 3) { | if (request.fHelp || request.params.size() != 3) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"prioritisetransaction", | "prioritisetransaction", | ||||
"Accepts the transaction into mined blocks at a higher " | "Accepts the transaction into mined blocks at a higher " | ||||
"(or lower) priority\n", | "(or lower) priority\n", | ||||
{ | { | ||||
{"txid", RPCArg::Type::STR_HEX, /* opt */ false, | {"txid", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "The transaction id."}, | /* default_val */ "", "The transaction id."}, | ||||
{"dummy", RPCArg::Type::NUM, /* opt */ false, | {"dummy", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"API-Compatibility for previous API. Must be zero or " | "API-Compatibility for previous API. Must be zero or " | ||||
"null.\n" | "null.\n" | ||||
" DEPRECATED. For forward compatibility " | " DEPRECATED. For forward compatibility " | ||||
"use named arguments and omit this parameter."}, | "use named arguments and omit this parameter."}, | ||||
{"fee_delta", RPCArg::Type::NUM, /* opt */ false, | {"fee_delta", RPCArg::Type::NUM, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"The fee value (in satoshis) to add (or subtract, if " | "The fee value (in satoshis) to add (or subtract, if " | ||||
"negative).\n" | "negative).\n" | ||||
" Note, that this value is not a " | " Note, that this value is not a " | ||||
"fee rate. It is a value to modify absolute fee of the " | "fee rate. It is a value to modify absolute fee of the " | ||||
"TX.\n" | "TX.\n" | ||||
" The fee is not actually paid, " | " The fee is not actually paid, " | ||||
"only the algorithm for selecting transactions into a " | "only the algorithm for selecting transactions into a " | ||||
"block\n" | "block\n" | ||||
" considers the transaction as it would " | " considers the transaction as it would " | ||||
"have paid a higher (or lower) fee."}, | "have paid a higher (or lower) fee."}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"true (boolean) Returns true\n"}, | ||||
"\nResult:\n" | RPCExamples{ | ||||
"true (boolean) Returns true\n" | |||||
"\nExamples:\n" + | |||||
HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + | HelpExampleCli("prioritisetransaction", "\"txid\" 0.0 10000") + | ||||
HelpExampleRpc("prioritisetransaction", "\"txid\", 0.0, 10000")); | HelpExampleRpc("prioritisetransaction", | ||||
"\"txid\", 0.0, 10000")}, | |||||
} | |||||
.ToString()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
TxId txid(ParseHashV(request.params[0], "txid")); | TxId txid(ParseHashV(request.params[0], "txid")); | ||||
Amount nAmount = request.params[2].get_int64() * SATOSHI; | Amount nAmount = request.params[2].get_int64() * SATOSHI; | ||||
if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) { | if (!(request.params[1].isNull() || request.params[1].get_real() == 0)) { | ||||
Show All 28 Lines | static UniValue BIP22ValidationResult(const Config &config, | ||||
// Should be impossible. | // Should be impossible. | ||||
return "valid?"; | return "valid?"; | ||||
} | } | ||||
static UniValue getblocktemplate(const Config &config, | static UniValue getblocktemplate(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 1) { | if (request.fHelp || request.params.size() > 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"getblocktemplate", | "getblocktemplate", | ||||
"\nIf the request parameters include a 'mode' key, that is " | "\nIf the request parameters include a 'mode' key, that is " | ||||
"used to explicitly select between the default 'template' " | "used to explicitly select between the default 'template' " | ||||
"request or a 'proposal'.\n" | "request or a 'proposal'.\n" | ||||
"It returns data needed to construct a block to work on.\n" | "It returns data needed to construct a block to work on.\n" | ||||
"For full specification, see BIPs 22, 23, 9, and 145:\n" | "For full specification, see BIPs 22, 23, 9, and 145:\n" | ||||
" " | " " | ||||
"https://github.com/bitcoin/bips/blob/master/" | "https://github.com/bitcoin/bips/blob/master/" | ||||
"bip-0022.mediawiki\n" | "bip-0022.mediawiki\n" | ||||
" " | " " | ||||
"https://github.com/bitcoin/bips/blob/master/" | "https://github.com/bitcoin/bips/blob/master/" | ||||
"bip-0023.mediawiki\n" | "bip-0023.mediawiki\n" | ||||
" " | " " | ||||
"https://github.com/bitcoin/bips/blob/master/" | "https://github.com/bitcoin/bips/blob/master/" | ||||
"bip-0009.mediawiki#getblocktemplate_changes\n" | "bip-0009.mediawiki#getblocktemplate_changes\n" | ||||
" ", | " ", | ||||
{ | { | ||||
{"template_request", | {"template_request", | ||||
RPCArg::Type::OBJ, | RPCArg::Type::OBJ, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A json object in the following spec", | "A json object in the following spec", | ||||
{ | { | ||||
{"mode", RPCArg::Type::STR, /* opt */ true, | {"mode", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"This must be set to \"template\", \"proposal\" (see " | "This must be set to \"template\", \"proposal\" (see " | ||||
"BIP 23), or omitted"}, | "BIP 23), or omitted"}, | ||||
{ | { | ||||
"capabilities", | "capabilities", | ||||
RPCArg::Type::ARR, | RPCArg::Type::ARR, | ||||
/* opt */ true, | /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"A list of strings", | "A list of strings", | ||||
{ | { | ||||
{"support", RPCArg::Type::STR, /* opt */ true, | {"support", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"client side supported feature, 'longpoll', " | "client side supported feature, 'longpoll', " | ||||
"'coinbasetxn', 'coinbasevalue', 'proposal', " | "'coinbasetxn', 'coinbasevalue', 'proposal', " | ||||
"'serverlist', 'workid'"}, | "'serverlist', 'workid'"}, | ||||
}, | }, | ||||
}, | }, | ||||
}, | }, | ||||
"\"template_request\""}, | "\"template_request\""}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{ | ||||
"\nResult:\n" | |||||
"{\n" | "{\n" | ||||
" \"version\" : n, (numeric) The preferred " | " \"version\" : n, (numeric) The preferred " | ||||
"block version\n" | "block version\n" | ||||
" \"previousblockhash\" : \"xxxx\", (string) The hash of " | " \"previousblockhash\" : \"xxxx\", (string) The hash of " | ||||
"current highest block\n" | "current highest block\n" | ||||
" \"transactions\" : [ (array) contents of " | " \"transactions\" : [ (array) contents of " | ||||
"non-coinbase transactions that should be included in the next " | "non-coinbase transactions that should be included in the next " | ||||
"block\n" | "block\n" | ||||
" {\n" | " {\n" | ||||
" \"data\" : \"xxxx\", (string) transaction " | " \"data\" : \"xxxx\", (string) " | ||||
"transaction " | |||||
"data encoded in hexadecimal (byte-for-byte)\n" | "data encoded in hexadecimal (byte-for-byte)\n" | ||||
" \"txid\" : \"xxxx\", (string) transaction id " | " \"txid\" : \"xxxx\", (string) " | ||||
"transaction id " | |||||
"encoded in little-endian hexadecimal\n" | "encoded in little-endian hexadecimal\n" | ||||
" \"hash\" : \"xxxx\", (string) hash encoded " | " \"hash\" : \"xxxx\", (string) hash " | ||||
"encoded " | |||||
"in little-endian hexadecimal (including witness data)\n" | "in little-endian hexadecimal (including witness data)\n" | ||||
" \"depends\" : [ (array) array of numbers " | " \"depends\" : [ (array) array of " | ||||
"numbers " | |||||
"\n" | "\n" | ||||
" n (numeric) transactions " | " n (numeric) " | ||||
"before this one (by 1-based index in 'transactions' list) that " | "transactions " | ||||
"before this one (by 1-based index in 'transactions' list) " | |||||
"that " | |||||
"must be present in the final block if this one is\n" | "must be present in the final block if this one is\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"fee\": n, (numeric) difference in " | " \"fee\": n, (numeric) difference " | ||||
"value between transaction inputs and outputs (in satoshis); for " | "in " | ||||
"value between transaction inputs and outputs (in satoshis); " | |||||
"for " | |||||
"coinbase transactions, this is a negative Number of the total " | "coinbase transactions, this is a negative Number of the total " | ||||
"collected block fees (ie, not including the block subsidy); if " | "collected block fees (ie, not including the block subsidy); " | ||||
"key is not present, fee is unknown and clients MUST NOT assume " | "if " | ||||
"key is not present, fee is unknown and clients MUST NOT " | |||||
"assume " | |||||
"there isn't one\n" | "there isn't one\n" | ||||
" \"sigops\" : n, (numeric) total SigOps " | " \"sigops\" : n, (numeric) total " | ||||
"SigOps " | |||||
"count, as counted for purposes of block limits; if key is not " | "count, as counted for purposes of block limits; if key is not " | ||||
"present, sigop count is unknown and clients MUST NOT assume it is " | "present, sigop count is unknown and clients MUST NOT assume " | ||||
"it is " | |||||
"zero\n" | "zero\n" | ||||
" \"required\" : true|false (boolean) if provided and " | " \"required\" : true|false (boolean) if provided " | ||||
"and " | |||||
"true, this transaction must be in the final block\n" | "true, this transaction must be in the final block\n" | ||||
" }\n" | " }\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"coinbaseaux\" : { (json object) data that " | " \"coinbaseaux\" : { (json object) data that " | ||||
"should be included in the coinbase's scriptSig content\n" | "should be included in the coinbase's scriptSig content\n" | ||||
" \"flags\" : \"xx\" (string) key name is to " | " \"flags\" : \"xx\" (string) key name " | ||||
"is to " | |||||
"be ignored, and value included in scriptSig\n" | "be ignored, and value included in scriptSig\n" | ||||
" },\n" | " },\n" | ||||
" \"coinbasevalue\" : n, (numeric) maximum allowable " | " \"coinbasevalue\" : n, (numeric) maximum " | ||||
"input to coinbase transaction, including the generation award and " | "allowable " | ||||
"input to coinbase transaction, including the generation award " | |||||
"and " | |||||
"transaction fees (in satoshis)\n" | "transaction fees (in satoshis)\n" | ||||
" \"coinbasetxn\" : { ... }, (json object) information " | " \"coinbasetxn\" : { ... }, (json object) " | ||||
"information " | |||||
"for coinbase transaction\n" | "for coinbase transaction\n" | ||||
" \"target\" : \"xxxx\", (string) The hash target\n" | " \"target\" : \"xxxx\", (string) The hash " | ||||
"target\n" | |||||
" \"mintime\" : xxx, (numeric) The minimum " | " \"mintime\" : xxx, (numeric) The minimum " | ||||
"timestamp appropriate for next block time in seconds since epoch " | "timestamp appropriate for next block time in seconds since " | ||||
"epoch " | |||||
"(Jan 1 1970 GMT)\n" | "(Jan 1 1970 GMT)\n" | ||||
" \"mutable\" : [ (array of string) list of " | " \"mutable\" : [ (array of string) list " | ||||
"of " | |||||
"ways the block template may be changed \n" | "ways the block template may be changed \n" | ||||
" \"value\" (string) A way the block " | " \"value\" (string) A way the " | ||||
"block " | |||||
"template may be changed, e.g. 'time', 'transactions', " | "template may be changed, e.g. 'time', 'transactions', " | ||||
"'prevblock'\n" | "'prevblock'\n" | ||||
" ,...\n" | " ,...\n" | ||||
" ],\n" | " ],\n" | ||||
" \"noncerange\" : \"00000000ffffffff\",(string) A range of valid " | " \"noncerange\" : \"00000000ffffffff\",(string) A range of " | ||||
"valid " | |||||
"nonces\n" | "nonces\n" | ||||
" \"sigoplimit\" : n, (numeric) limit of sigops " | " \"sigoplimit\" : n, (numeric) limit of " | ||||
"sigops " | |||||
"in blocks\n" | "in blocks\n" | ||||
" \"sizelimit\" : n, (numeric) limit of block " | " \"sizelimit\" : n, (numeric) limit of " | ||||
"block " | |||||
"size\n" | "size\n" | ||||
" \"curtime\" : ttt, (numeric) current timestamp " | " \"curtime\" : ttt, (numeric) current " | ||||
"timestamp " | |||||
"in seconds since epoch (Jan 1 1970 GMT)\n" | "in seconds since epoch (Jan 1 1970 GMT)\n" | ||||
" \"bits\" : \"xxxxxxxx\", (string) compressed " | " \"bits\" : \"xxxxxxxx\", (string) compressed " | ||||
"target of next block\n" | "target of next block\n" | ||||
" \"height\" : n (numeric) The height of the " | " \"height\" : n (numeric) The height of " | ||||
"the " | |||||
"next block\n" | "next block\n" | ||||
"}\n" | "}\n"}, | ||||
RPCExamples{HelpExampleCli("getblocktemplate", | |||||
"\nExamples:\n" + | "{\"rules\": [\"segwit\"]}") + | ||||
HelpExampleCli("getblocktemplate", "") + | HelpExampleRpc("getblocktemplate", | ||||
HelpExampleRpc("getblocktemplate", "")); | "{\"rules\": [\"segwit\"]}")}, | ||||
} | |||||
.ToString()); | |||||
} | } | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
std::string strMode = "template"; | std::string strMode = "template"; | ||||
UniValue lpval = NullUniValue; | UniValue lpval = NullUniValue; | ||||
std::set<std::string> setClientRules; | std::set<std::string> setClientRules; | ||||
if (!request.params[0].isNull()) { | if (!request.params[0].isNull()) { | ||||
▲ Show 20 Lines • Show All 238 Lines • ▼ Show 20 Lines | protected: | ||||
} | } | ||||
}; | }; | ||||
static UniValue submitblock(const Config &config, | static UniValue submitblock(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
// We allow 2 arguments for compliance with BIP22. Argument 2 is ignored. | // We allow 2 arguments for compliance with BIP22. Argument 2 is ignored. | ||||
if (request.fHelp || request.params.size() < 1 || | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 2) { | request.params.size() > 2) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"submitblock", | "submitblock", | ||||
"\nAttempts to submit new block to network.\n" | "\nAttempts to submit new block to network.\n" | ||||
"See https://en.bitcoin.it/wiki/BIP_0022 for full " | "See https://en.bitcoin.it/wiki/BIP_0022 for full " | ||||
"specification.\n", | "specification.\n", | ||||
{ | { | ||||
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, | {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", | /* default_val */ "", "the hex-encoded block data to submit"}, | ||||
"the hex-encoded block data to submit"}, | |||||
{"dummy", RPCArg::Type::STR, /* opt */ true, | {"dummy", RPCArg::Type::STR, /* opt */ true, | ||||
/* default_val */ "", | /* default_val */ "", | ||||
"dummy value, for compatibility with BIP22. This " | "dummy value, for compatibility with BIP22. This " | ||||
"value is ignored."}, | "value is ignored."}, | ||||
}} | }, | ||||
.ToString() + | RPCResults{}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("submitblock", "\"mydata\"") + | ||||
"\nExamples:\n" + | HelpExampleRpc("submitblock", "\"mydata\"")}, | ||||
HelpExampleCli("submitblock", "\"mydata\"") + | } | ||||
HelpExampleRpc("submitblock", "\"mydata\"")); | .ToString()); | ||||
} | } | ||||
std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>(); | std::shared_ptr<CBlock> blockptr = std::make_shared<CBlock>(); | ||||
CBlock &block = *blockptr; | CBlock &block = *blockptr; | ||||
if (!DecodeHexBlk(block, request.params[0].get_str())) { | if (!DecodeHexBlk(block, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, "Block decode failed"); | ||||
} | } | ||||
Show All 37 Lines | static UniValue submitblock(const Config &config, | ||||
} | } | ||||
return BIP22ValidationResult(config, sc.state); | return BIP22ValidationResult(config, sc.state); | ||||
} | } | ||||
static UniValue submitheader(const Config &config, | static UniValue submitheader(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() != 1) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{ | |||||
"submitheader", | "submitheader", | ||||
"\nDecode the given hexdata as a header and submit it as a " | "\nDecode the given hexdata as a header and submit it as a " | ||||
"candidate chain tip if valid." | "candidate chain tip if valid." | ||||
"\nThrows when the header is invalid.\n", | "\nThrows when the header is invalid.\n", | ||||
{ | { | ||||
{"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, | {"hexdata", RPCArg::Type::STR_HEX, /* opt */ false, | ||||
/* default_val */ "", "the hex-encoded block header data"}, | /* default_val */ "", "the hex-encoded block header data"}, | ||||
}} | }, | ||||
.ToString() + | RPCResult{"None"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("submitheader", "\"aabbcc\"") + | ||||
"None" | HelpExampleRpc("submitheader", "\"aabbcc\"")}, | ||||
"\nExamples:\n" + | } | ||||
HelpExampleCli("submitheader", "\"aabbcc\"") + | .ToString()); | ||||
HelpExampleRpc("submitheader", "\"aabbcc\"")); | |||||
} | } | ||||
CBlockHeader h; | CBlockHeader h; | ||||
if (!DecodeHexBlockHeader(h, request.params[0].get_str())) { | if (!DecodeHexBlockHeader(h, request.params[0].get_str())) { | ||||
throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | throw JSONRPCError(RPC_DESERIALIZATION_ERROR, | ||||
"Block header decode failed"); | "Block header decode failed"); | ||||
} | } | ||||
{ | { | ||||
Show All 15 Lines | if (state.IsError()) { | ||||
throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state)); | throw JSONRPCError(RPC_VERIFY_ERROR, FormatStateMessage(state)); | ||||
} | } | ||||
throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason()); | throw JSONRPCError(RPC_VERIFY_ERROR, state.GetRejectReason()); | ||||
} | } | ||||
static UniValue estimatefee(const Config &config, | static UniValue estimatefee(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() > 0) { | if (request.fHelp || request.params.size() > 0) { | ||||
throw std::runtime_error( | throw std::runtime_error(RPCHelpMan{ | ||||
RPCHelpMan{"estimatefee", | "estimatefee", | ||||
"\nEstimates the approximate fee per kilobyte needed " | "\nEstimates the approximate fee per kilobyte needed " | ||||
"for a transaction\n", | "for a transaction\n", | ||||
{}} | {}, | ||||
.ToString() + | RPCResult{"n (numeric) estimated fee-per-kilobyte\n"}, | ||||
"\nResult:\n" | RPCExamples{HelpExampleCli("estimatefee", "")}, | ||||
"n (numeric) estimated fee-per-kilobyte\n" | } | ||||
"\nExample:\n" + | .ToString()); | ||||
HelpExampleCli("estimatefee", "")); | |||||
} | } | ||||
return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); | return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); | ||||
} | } | ||||
// clang-format off | // clang-format off | ||||
static const ContextFreeRPCCommand commands[] = { | static const ContextFreeRPCCommand commands[] = { | ||||
// category name actor (function) argNames | // category name actor (function) argNames | ||||
Show All 19 Lines |