Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show First 20 Lines • Show All 918 Lines • ▼ Show 20 Lines | static UniValue estimatefee(const Config &config, | ||||
CFeeRate feeRate = mempool.estimateFee(nBlocks); | CFeeRate feeRate = mempool.estimateFee(nBlocks); | ||||
if (feeRate == CFeeRate(Amount(0))) { | if (feeRate == CFeeRate(Amount(0))) { | ||||
return -1.0; | return -1.0; | ||||
} | } | ||||
return ValueFromAmount(feeRate.GetFeePerK()); | return ValueFromAmount(feeRate.GetFeePerK()); | ||||
} | } | ||||
static UniValue estimatesmartfee(const Config &config, | |||||
const JSONRPCRequest &request) { | |||||
if (request.fHelp || request.params.size() != 1) { | |||||
throw std::runtime_error( | |||||
"estimatesmartfee nblocks\n" | |||||
"\nWARNING: This interface is unstable and may disappear or " | |||||
"change!\n" | |||||
"\nEstimates the approximate fee per kilobyte needed for a " | |||||
"transaction to begin\n" | |||||
"confirmation within nblocks blocks if possible and return the " | |||||
"number of blocks\n" | |||||
"for which the estimate is valid.\n" | |||||
"\nArguments:\n" | |||||
"1. nblocks (numeric)\n" | |||||
"\nResult:\n" | |||||
"{\n" | |||||
" \"feerate\" : x.x, (numeric) estimate fee-per-kilobyte (in " | |||||
"BCH)\n" | |||||
" \"blocks\" : n (numeric) block number where estimate " | |||||
"was found\n" | |||||
"}\n" | |||||
"\n" | |||||
"A negative value is returned if not enough transactions and " | |||||
"blocks\n" | |||||
"have been observed to make an estimate for any number of blocks.\n" | |||||
"However it will not return a value below the mempool reject fee.\n" | |||||
"\nExample:\n" + | |||||
HelpExampleCli("estimatesmartfee", "6")); | |||||
} | |||||
RPCTypeCheck(request.params, {UniValue::VNUM}); | |||||
int nBlocks = request.params[0].get_int(); | |||||
UniValue result(UniValue::VOBJ); | |||||
int answerFound; | |||||
CFeeRate feeRate = mempool.estimateSmartFee(nBlocks, &answerFound); | |||||
result.push_back(Pair("feerate", | |||||
feeRate == CFeeRate(Amount(0)) | |||||
? -1.0 | |||||
: ValueFromAmount(feeRate.GetFeePerK()))); | |||||
result.push_back(Pair("blocks", answerFound)); | |||||
return result; | |||||
} | |||||
// clang-format off | // clang-format off | ||||
static const CRPCCommand commands[] = { | static const CRPCCommand commands[] = { | ||||
// category name actor (function) okSafeMode | // category name actor (function) okSafeMode | ||||
// ---------- ------------------------ ---------------------- ---------- | // ---------- ------------------------ ---------------------- ---------- | ||||
{"mining", "getnetworkhashps", getnetworkhashps, true, {"nblocks", "height"}}, | {"mining", "getnetworkhashps", getnetworkhashps, true, {"nblocks", "height"}}, | ||||
{"mining", "getmininginfo", getmininginfo, true, {}}, | {"mining", "getmininginfo", getmininginfo, true, {}}, | ||||
{"mining", "prioritisetransaction", prioritisetransaction, true, {"txid", "priority_delta", "fee_delta"}}, | {"mining", "prioritisetransaction", prioritisetransaction, true, {"txid", "priority_delta", "fee_delta"}}, | ||||
{"mining", "getblocktemplate", getblocktemplate, true, {"template_request"}}, | {"mining", "getblocktemplate", getblocktemplate, true, {"template_request"}}, | ||||
{"mining", "submitblock", submitblock, true, {"hexdata", "parameters"}}, | {"mining", "submitblock", submitblock, true, {"hexdata", "parameters"}}, | ||||
{"generating", "generatetoaddress", generatetoaddress, true, {"nblocks", "address", "maxtries"}}, | {"generating", "generatetoaddress", generatetoaddress, true, {"nblocks", "address", "maxtries"}}, | ||||
{"util", "estimatefee", estimatefee, true, {"nblocks"}}, | {"util", "estimatefee", estimatefee, true, {"nblocks"}}, | ||||
{"util", "estimatesmartfee", estimatesmartfee, true, {"nblocks"}}, | |||||
}; | }; | ||||
// clang-format on | // clang-format on | ||||
void RegisterMiningRPCCommands(CRPCTable &t) { | void RegisterMiningRPCCommands(CRPCTable &t) { | ||||
for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | for (unsigned int vcidx = 0; vcidx < ARRAYLEN(commands); vcidx++) | ||||
t.appendCommand(commands[vcidx].name, &commands[vcidx]); | t.appendCommand(commands[vcidx].name, &commands[vcidx]); | ||||
} | } |