MCPcopy Create free account
hub / github.com/ElementsProject/elements / estimatesmartfee

Function estimatesmartfee

src/rpc/mining.cpp:1094–1166  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1092}
1093
1094static RPCHelpMan estimatesmartfee()
1095{
1096 return RPCHelpMan{"estimatesmartfee",
1097 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
1098 "confirmation within conf_target blocks if possible and return the number of blocks\n"
1099 "for which the estimate is valid. Uses virtual transaction size as defined\n"
1100 "in BIP 141 (witness data is discounted).\n",
1101 {
1102 {"conf_target", RPCArg::Type::NUM, RPCArg::Optional::NO, "Confirmation target in blocks (1 - 1008)"},
1103 {"estimate_mode", RPCArg::Type::STR, RPCArg::Default{"conservative"}, "The fee estimate mode.\n"
1104 " Whether to return a more conservative estimate which also satisfies\n"
1105 " a longer history. A conservative estimate potentially returns a\n"
1106 " higher feerate and is more likely to be sufficient for the desired\n"
1107 " target, but is not as responsive to short term drops in the\n"
1108 " prevailing fee market. Must be one of (case insensitive):\n"
1109 "\"" + FeeModes("\"\n\"") + "\""},
1110 },
1111 RPCResult{
1112 RPCResult::Type::OBJ, "", "",
1113 {
1114 {RPCResult::Type::NUM, "feerate", /*optional=*/true, "estimate fee rate in " + CURRENCY_UNIT + "/kvB (only present if no errors were encountered)"},
1115 {RPCResult::Type::ARR, "errors", /*optional=*/true, "Errors encountered during processing (if there are any)",
1116 {
1117 {RPCResult::Type::STR, "", "error"},
1118 }},
1119 {RPCResult::Type::NUM, "blocks", "block number where estimate was found\n"
1120 "The request target will be clamped between 2 and the highest target\n"
1121 "fee estimation is able to return based on how long it has been running.\n"
1122 "An error is returned if not enough transactions and blocks\n"
1123 "have been observed to make an estimate for any number of blocks."},
1124 }},
1125 RPCExamples{
1126 HelpExampleCli("estimatesmartfee", "6") +
1127 HelpExampleRpc("estimatesmartfee", "6")
1128 },
1129 [&](const RPCHelpMan& self, const JSONRPCRequest& request) -> UniValue
1130{
1131 RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
1132 RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
1133
1134 CBlockPolicyEstimator& fee_estimator = EnsureAnyFeeEstimator(request.context);
1135 const NodeContext& node = EnsureAnyNodeContext(request.context);
1136 const CTxMemPool& mempool = EnsureMemPool(node);
1137
1138 unsigned int max_target = fee_estimator.HighestTargetTracked(FeeEstimateHorizon::LONG_HALFLIFE);
1139 unsigned int conf_target = ParseConfirmTarget(request.params[0], max_target);
1140 bool conservative = true;
1141 if (!request.params[1].isNull()) {
1142 FeeEstimateMode fee_mode;
1143 if (!FeeModeFromString(request.params[1].get_str(), fee_mode)) {
1144 throw JSONRPCError(RPC_INVALID_PARAMETER, InvalidEstimateModeErrorMessage());
1145 }
1146 if (fee_mode == FeeEstimateMode::ECONOMICAL) conservative = false;
1147 }
1148
1149 UniValue result(UniValue::VOBJ);
1150 UniValue errors(UniValue::VARR);
1151 FeeCalculation feeCalc;

Callers

nothing calls this directly

Calls 15

FeeModesFunction · 0.85
HelpExampleCliFunction · 0.85
HelpExampleRpcFunction · 0.85
RPCTypeCheckFunction · 0.85
RPCTypeCheckArgumentFunction · 0.85
ParseConfirmTargetFunction · 0.85
FeeModeFromStringFunction · 0.85
JSONRPCErrorFunction · 0.85
ValueFromAmountFunction · 0.85
HighestTargetTrackedMethod · 0.80
GetMinFeeMethod · 0.80

Tested by

no test coverage detected