Changeset View
Changeset View
Standalone View
Standalone View
src/rpc/mining.cpp
Show All 25 Lines | |||||
#include "validation.h" | #include "validation.h" | ||||
#include "validationinterface.h" | #include "validationinterface.h" | ||||
#include <univalue.h> | #include <univalue.h> | ||||
#include <cstdint> | #include <cstdint> | ||||
#include <memory> | #include <memory> | ||||
#include <boost/optional.hpp> | |||||
/** | /** | ||||
* Return average network hashes per second based on the last 'lookup' blocks, | * Return average network hashes per second based on the last 'lookup' blocks, | ||||
* or from the last difficulty change if 'lookup' is nonpositive. If 'height' is | * or from the last difficulty change if 'lookup' is nonpositive. If 'height' is | ||||
* nonnegative, compute the estimate at the time when a given block was found. | * nonnegative, compute the estimate at the time when a given block was found. | ||||
*/ | */ | ||||
static UniValue GetNetworkHashPS(int lookup, int height) { | static UniValue GetNetworkHashPS(int lookup, int height) { | ||||
CBlockIndex *pb = chainActive.Tip(); | CBlockIndex *pb = chainActive.Tip(); | ||||
▲ Show 20 Lines • Show All 840 Lines • ▼ Show 20 Lines | if (!sc.found) { | ||||
return "inconclusive"; | return "inconclusive"; | ||||
} | } | ||||
return BIP22ValidationResult(config, sc.state); | return BIP22ValidationResult(config, sc.state); | ||||
} | } | ||||
static UniValue estimatefee(const Config &config, | static UniValue estimatefee(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
if (request.fHelp || request.params.size() != 1) { | if (request.fHelp || request.params.size() < 1 || | ||||
request.params.size() > 3) { | |||||
throw std::runtime_error( | throw std::runtime_error( | ||||
"estimatefee nblocks\n" | "estimatefee nblocks\n" | ||||
"\nEstimates the approximate fee per kilobyte needed for a " | "\nEstimates the approximate fee per kilobyte needed for a " | ||||
"transaction to begin\n" | "transaction to begin\n" | ||||
"confirmation within nblocks blocks.\n" | "confirmation within nblocks blocks.\n" | ||||
"\nArguments:\n" | "\nArguments:\n" | ||||
"1. nblocks (numeric, required)\n" | "1. nblocks (numeric, required, deprecated)\n" | ||||
"2. size (numeric, required, txn size)\n" | |||||
"3. newutxos (numeric, optional)\n" | |||||
"\nResult:\n" | "\nResult:\n" | ||||
"n (numeric) estimated fee-per-kilobyte\n" | "n (numeric) estimated fee-per-kilobyte\n" | ||||
"\n" | "\n" | ||||
"A negative value is returned if not enough transactions and " | "A negative value is returned if not enough transactions and " | ||||
"blocks\n" | "blocks\n" | ||||
"have been observed to make an estimate.\n" | "have been observed to make an estimate.\n" | ||||
"-1 is always returned for nblocks == 1 as it is impossible to " | "-1 is always returned for nblocks == 1 as it is impossible to " | ||||
"calculate\n" | "calculate\n" | ||||
"a fee that is high enough to get reliably included in the next " | "a fee that is high enough to get reliably included in the next " | ||||
"block.\n" | "block.\n" | ||||
"\nExample:\n" + | "\nExample:\n" + | ||||
HelpExampleCli("estimatefee", "6")); | HelpExampleCli("estimatefee", "6")); | ||||
} | } | ||||
RPCTypeCheck(request.params, {UniValue::VNUM}); | size_t txSize = 0; | ||||
boost::optional<int64_t> newUTXOs; | |||||
RPCTypeCheckArgument(request.params[0], UniValue::VNUM); | |||||
int nBlocks = request.params[0].get_int(); | int nBlocks = request.params[0].get_int(); | ||||
if (nBlocks < 1) { | if (nBlocks < 1) { | ||||
nBlocks = 1; | nBlocks = 1; | ||||
} | } | ||||
if (request.params.size() >= 2) { | |||||
RPCTypeCheckArgument(request.params[1], UniValue::VNUM); | |||||
txSize = request.params[1].get_int64(); | |||||
} | |||||
if (request.params.size() >= 3) { | |||||
RPCTypeCheckArgument(request.params[2], UniValue::VNUM); | |||||
newUTXOs = request.params[2].get_int64(); | |||||
} | |||||
CFeeRate feeRate = mempool.estimateFee(nBlocks); | CFeeRate feeRate = mempool.estimateFee(config, nBlocks, txSize, newUTXOs); | ||||
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, | static UniValue estimatesmartfee(const Config &config, | ||||
const JSONRPCRequest &request) { | const JSONRPCRequest &request) { | ||||
▲ Show 20 Lines • Show All 64 Lines • Show Last 20 Lines |