Skip to content

Commit 06bcdb8

Browse files
committed
Convert named argument from nblocks to conf_target
in estimatesmartfee and estimaterawfee. Also reuse existing bounds checking.
1 parent 439c4e8 commit 06bcdb8

File tree

1 file changed

+15
-21
lines changed

1 file changed

+15
-21
lines changed

src/rpc/mining.cpp

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -806,13 +806,13 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
806806
{
807807
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
808808
throw std::runtime_error(
809-
"estimatesmartfee nblocks (\"estimate_mode\")\n"
809+
"estimatesmartfee conf_target (\"estimate_mode\")\n"
810810
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
811-
"confirmation within nblocks blocks if possible and return the number of blocks\n"
811+
"confirmation within conf_target blocks if possible and return the number of blocks\n"
812812
"for which the estimate is valid. Uses virtual transaction size as defined\n"
813813
"in BIP 141 (witness data is discounted).\n"
814814
"\nArguments:\n"
815-
"1. nblocks (numeric) Confirmation target in blocks (1 - 1008)\n"
815+
"1. conf_target (numeric) Confirmation target in blocks (1 - 1008)\n"
816816
"2. \"estimate_mode\" (string, optional, default=CONSERVATIVE) The fee estimate mode.\n"
817817
" Whether to return a more conservative estimate which also satisfies\n"
818818
" a longer history. A conservative estimate potentially returns a\n"
@@ -839,10 +839,7 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
839839

840840
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
841841
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
842-
int nBlocks = request.params[0].get_int();
843-
if (nBlocks < 1 || (unsigned int)nBlocks > ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE)) {
844-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid nblocks");
845-
}
842+
unsigned int conf_target = ParseConfirmTarget(request.params[0]);
846843
bool conservative = true;
847844
if (request.params.size() > 1 && !request.params[1].isNull()) {
848845
FeeEstimateMode fee_mode;
@@ -855,7 +852,7 @@ UniValue estimatesmartfee(const JSONRPCRequest& request)
855852
UniValue result(UniValue::VOBJ);
856853
UniValue errors(UniValue::VARR);
857854
FeeCalculation feeCalc;
858-
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(nBlocks, &feeCalc, conservative);
855+
CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
859856
if (feeRate != CFeeRate(0)) {
860857
result.push_back(Pair("feerate", ValueFromAmount(feeRate.GetFeePerK())));
861858
} else {
@@ -870,18 +867,18 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
870867
{
871868
if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
872869
throw std::runtime_error(
873-
"estimaterawfee nblocks (threshold)\n"
870+
"estimaterawfee conf_target (threshold)\n"
874871
"\nWARNING: This interface is unstable and may disappear or change!\n"
875872
"\nWARNING: This is an advanced API call that is tightly coupled to the specific\n"
876873
" implementation of fee estimation. The parameters it can be called with\n"
877874
" and the results it returns will change if the internal implementation changes.\n"
878875
"\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
879-
"confirmation within nblocks blocks if possible. Uses virtual transaction size as defined\n"
880-
"in BIP 141 (witness data is discounted).\n"
876+
"confirmation within conf_target blocks if possible. Uses virtual transaction size as\n"
877+
"defined in BIP 141 (witness data is discounted).\n"
881878
"\nArguments:\n"
882-
"1. nblocks (numeric) Confirmation target in blocks (1 - 1008)\n"
879+
"1. conf_target (numeric) Confirmation target in blocks (1 - 1008)\n"
883880
"2. threshold (numeric, optional) The proportion of transactions in a given feerate range that must have been\n"
884-
" confirmed within nblocks in order to consider those feerates as high enough and proceed to check\n"
881+
" confirmed within conf_target in order to consider those feerates as high enough and proceed to check\n"
885882
" lower buckets. Default: 0.95\n"
886883
"\nResult:\n"
887884
"{\n"
@@ -911,10 +908,7 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
911908

912909
RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VNUM}, true);
913910
RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
914-
int nBlocks = request.params[0].get_int();
915-
if (nBlocks < 1 || (unsigned int)nBlocks > ::feeEstimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE)) {
916-
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid nblocks");
917-
}
911+
unsigned int conf_target = ParseConfirmTarget(request.params[0]);
918912
double threshold = 0.95;
919913
if (!request.params[1].isNull()) {
920914
threshold = request.params[1].get_real();
@@ -930,9 +924,9 @@ UniValue estimaterawfee(const JSONRPCRequest& request)
930924
EstimationResult buckets;
931925

932926
// Only output results for horizons which track the target
933-
if ((unsigned int)nBlocks > ::feeEstimator.HighestTargetTracked(horizon)) continue;
927+
if (conf_target > ::feeEstimator.HighestTargetTracked(horizon)) continue;
934928

935-
feeRate = ::feeEstimator.estimateRawFee(nBlocks, threshold, horizon, &buckets);
929+
feeRate = ::feeEstimator.estimateRawFee(conf_target, threshold, horizon, &buckets);
936930
UniValue horizon_result(UniValue::VOBJ);
937931
UniValue errors(UniValue::VARR);
938932
UniValue passbucket(UniValue::VOBJ);
@@ -983,9 +977,9 @@ static const CRPCCommand commands[] =
983977
{ "generating", "generatetoaddress", &generatetoaddress, true, {"nblocks","address","maxtries"} },
984978

985979
{ "util", "estimatefee", &estimatefee, true, {"nblocks"} },
986-
{ "util", "estimatesmartfee", &estimatesmartfee, true, {"nblocks", "estimate_mode"} },
980+
{ "util", "estimatesmartfee", &estimatesmartfee, true, {"conf_target", "estimate_mode"} },
987981

988-
{ "hidden", "estimaterawfee", &estimaterawfee, true, {"nblocks", "threshold"} },
982+
{ "hidden", "estimaterawfee", &estimaterawfee, true, {"conf_target", "threshold"} },
989983
};
990984

991985
void RegisterMiningRPCCommands(CRPCTable &t)

0 commit comments

Comments
 (0)