Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | static UniValue GetNetworkHashPS(int lookup, int height) { | ||||
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( | ||||
"getnetworkhashps ( nblocks height )\n" | RPCHelpMan{"getnetworkhashps", | ||||
"\nReturns the estimated network hashes per second based on the " | "\nReturns the estimated network hashes per second " | ||||
"last n blocks.\n" | "based on the last n blocks.\n" | ||||
"Pass in [blocks] to override # of blocks, -1 specifies since last " | "Pass in [blocks] to override # of blocks, -1 specifies " | ||||
"difficulty change.\n" | "since last difficulty change.\n" | ||||
"Pass in [height] to estimate the network speed at the time when a " | "Pass in [height] to estimate the network speed at the " | ||||
"certain block was found.\n" | "time when a certain block was found.\n", | ||||
{ | |||||
{"nblocks", RPCArg::Type::NUM, true}, | |||||
{"height", RPCArg::Type::NUM, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. nblocks (numeric, optional, default=120) The number of " | "1. nblocks (numeric, optional, default=120) The number of " | ||||
"blocks, or -1 for blocks since last difficulty change.\n" | "blocks, or -1 for blocks since last difficulty change.\n" | ||||
"2. height (numeric, optional, default=-1) To estimate at the " | "2. height (numeric, optional, default=-1) To estimate at the " | ||||
"time of the given height.\n" | "time of the given height.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"x (numeric) Hashes per second estimated\n" | "x (numeric) Hashes per second estimated\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
▲ Show 20 Lines • Show All 74 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( | ||||
"generatetoaddress nblocks address (maxtries)\n" | RPCHelpMan{"generatetoaddress", | ||||
"\nMine blocks immediately to a specified address (before the RPC " | "\nMine blocks immediately to a specified address " | ||||
"call returns)\n" | "before the RPC call returns)\n", | ||||
{ | |||||
{"nblocks", RPCArg::Type::NUM, false}, | |||||
{"address", RPCArg::Type::STR, false}, | |||||
{"maxtries", RPCArg::Type::NUM, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. nblocks (numeric, required) How many blocks are generated " | "1. nblocks (numeric, required) How many blocks are generated " | ||||
"immediately.\n" | "immediately.\n" | ||||
"2. address (string, required) The address to send the newly " | "2. address (string, required) The address to send the newly " | ||||
"generated bitcoin to.\n" | "generated bitcoin to.\n" | ||||
"3. maxtries (numeric, optional) How many iterations to try " | "3. maxtries (numeric, optional) How many iterations to try " | ||||
"(default = 1000000).\n" | "(default = 1000000).\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
Show All 22 Lines | static UniValue generatetoaddress(const Config &config, | ||||
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( | ||||
"getmininginfo\n" | RPCHelpMan{"getmininginfo", | ||||
"\nReturns a json object containing mining-related information." | "\nReturns a json object containing mining-related " | ||||
"information.", | |||||
{}} | |||||
.ToString() + | |||||
"\nResult:\n" | "\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 difficulty\n" | ||||
" \"networkhashps\": nnn, (numeric) The network hashes per " | " \"networkhashps\": nnn, (numeric) The network hashes per " | ||||
Show All 25 Lines | |||||
} | } | ||||
// 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( | ||||
"prioritisetransaction \"txid\" dummy fee_delta\n" | RPCHelpMan{"prioritisetransaction", | ||||
"Accepts the transaction into mined blocks at a higher (or lower) " | "Accepts the transaction into mined blocks at a higher " | ||||
"priority\n" | "(or lower) priority\n", | ||||
{ | |||||
{"txid", RPCArg::Type::STR_HEX, false}, | |||||
{"dummy", RPCArg::Type::NUM, false}, | |||||
{"fee_delta", RPCArg::Type::NUM, false}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. \"txid\" (string, required) The transaction id.\n" | "1. \"txid\" (string, required) The transaction id.\n" | ||||
"2. dummy (numeric, optional) API-Compatibility for " | "2. dummy (numeric, optional) API-Compatibility for " | ||||
"previous API. Must be zero or null.\n" | "previous API. Must be zero or null.\n" | ||||
" DEPRECATED. For forward compatibility use named " | " DEPRECATED. For forward compatibility use named " | ||||
"arguments and omit this parameter.\n" | "arguments and omit this parameter.\n" | ||||
"3. fee_delta (numeric, required) The fee value (in satoshis) " | "3. fee_delta (numeric, required) The fee value (in satoshis) " | ||||
"to add (or subtract, if negative).\n" | "to add (or subtract, if negative).\n" | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 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( | ||||
"getblocktemplate ( \"template_request\" )\n" | RPCHelpMan{ | ||||
"\nIf the request parameters include a 'mode' key, that is used to " | "getblocktemplate", | ||||
"explicitly select between the default 'template' request or a " | "\nIf the request parameters include a 'mode' key, that is " | ||||
"'proposal'.\n" | "used to explicitly select between the default 'template' " | ||||
"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/bip-0022.mediawiki\n" | "https://github.com/bitcoin/bips/blob/master/" | ||||
"bip-0022.mediawiki\n" | |||||
" " | " " | ||||
"https://github.com/bitcoin/bips/blob/master/bip-0023.mediawiki\n" | "https://github.com/bitcoin/bips/blob/master/" | ||||
"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" | ||||
" " | " ", | ||||
"https://github.com/bitcoin/bips/blob/master/bip-0145.mediawiki\n" | { | ||||
{"template_request", | |||||
RPCArg::Type::OBJ, | |||||
{ | |||||
{"mode", RPCArg::Type::STR, true}, | |||||
{"capabilities", | |||||
RPCArg::Type::ARR, | |||||
{ | |||||
{"support", RPCArg::Type::STR, true}, | |||||
}, | |||||
true}, | |||||
{"rules", | |||||
RPCArg::Type::ARR, | |||||
{ | |||||
{"support", RPCArg::Type::STR, true}, | |||||
}, | |||||
true}, | |||||
}, | |||||
true, | |||||
"\"template_request\""}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. template_request (json object, optional) A json object " | "1. template_request (json object, optional) A json object " | ||||
"in the following spec\n" | "in the following spec\n" | ||||
" {\n" | " {\n" | ||||
" \"mode\":\"template\" (string, optional) This must be " | " \"mode\":\"template\" (string, optional) This must be " | ||||
"set to \"template\", \"proposal\" (see BIP 23), or omitted\n" | "set to \"template\", \"proposal\" (see BIP 23), or omitted\n" | ||||
" \"capabilities\":[ (array, optional) A list of " | " \"capabilities\":[ (array, optional) A list of " | ||||
"strings\n" | "strings\n" | ||||
▲ Show 20 Lines • Show All 331 Lines • ▼ Show 20 Lines | |||||
}; | }; | ||||
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( | ||||
"submitblock \"hexdata\" ( \"dummy\" )\n" | RPCHelpMan{"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 specification.\n" | "See https://en.bitcoin.it/wiki/BIP_0022 for full " | ||||
"specification.\n", | |||||
{ | |||||
{"hexdata", RPCArg::Type::STR_HEX, false}, | |||||
{"dummy", RPCArg::Type::STR, true}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments\n" | "\nArguments\n" | ||||
"1. \"hexdata\" (string, required) the hex-encoded block " | "1. \"hexdata\" (string, required) the hex-encoded block " | ||||
"data to submit\n" | "data to submit\n" | ||||
"2. \"dummy\" (optional) dummy value, for compatibility " | "2. \"dummy\" (optional) dummy value, for compatibility " | ||||
"with BIP22. This value is ignored.\n" | "with BIP22. This value is ignored.\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("submitblock", "\"mydata\"") + | HelpExampleCli("submitblock", "\"mydata\"") + | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 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("submitheader \"hexdata\"\n" | throw std::runtime_error( | ||||
"\nDecode the given hexdata as a header and " | RPCHelpMan{"submitheader", | ||||
"submit it as a candidate chain tip if valid." | "\nDecode the given hexdata as a header and submit it " | ||||
"\nThrows when the header is invalid.\n" | "as a candidate chain tip if valid." | ||||
"\nThrows when the header is invalid.\n", | |||||
{ | |||||
{"hexdata", RPCArg::Type::STR_HEX, false}, | |||||
}} | |||||
.ToString() + | |||||
"\nArguments\n" | "\nArguments\n" | ||||
"1. \"hexdata\" (string, required) the " | "1. \"hexdata\" (string, required) the " | ||||
"hex-encoded block header data\n" | "hex-encoded block header data\n" | ||||
"\nResult:\n" | "\nResult:\n" | ||||
"None" | "None" | ||||
"\nExamples:\n" + | "\nExamples:\n" + | ||||
HelpExampleCli("submitheader", "\"aabbcc\"") + | HelpExampleCli("submitheader", "\"aabbcc\"") + | ||||
HelpExampleRpc("submitheader", "\"aabbcc\"")); | 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 16 Lines | static UniValue submitheader(const Config &config, | ||||
} | } | ||||
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( | ||||
"estimatefee\n" | RPCHelpMan{"estimatefee", | ||||
"\nEstimates the approximate fee per kilobyte needed for a " | "\nEstimates the approximate fee per kilobyte needed " | ||||
"transaction\n" | "for a transaction\n", | ||||
{}} | |||||
.ToString() + | |||||
"\nResult:\n" | "\nResult:\n" | ||||
"n (numeric) estimated fee-per-kilobyte\n" | "n (numeric) estimated fee-per-kilobyte\n" | ||||
"\nExample:\n" + | "\nExample:\n" + | ||||
HelpExampleCli("estimatefee", "")); | HelpExampleCli("estimatefee", "")); | ||||
} | } | ||||
return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); | return ValueFromAmount(g_mempool.estimateFee().GetFeePerK()); | ||||
} | } | ||||
Show All 23 Lines |