rpc: extract fee estimate result helpers

Replace inline fee estimation field lists in estimaterawfee with
reusable FeeRateBucketDoc() and FeeEstimateHorizonDoc() helpers.

Use ElideGroup() to keep repeated horizon and bucket sections
compact in human-readable help while preserving explicit result
metadata.
This commit is contained in:
Renato Britto
2026-03-17 00:30:29 -03:00
committed by satsfy (Renato Britto)
parent 8a615a8800
commit a9f9e7d17e

View File

@@ -94,6 +94,35 @@ static RPCMethod estimatesmartfee()
};
}
static std::vector<RPCResult> FeeRateBucketDoc(bool elide = false)
{
auto fields = std::vector<RPCResult>{
{RPCResult::Type::NUM, "startrange", "start of feerate range"},
{RPCResult::Type::NUM, "endrange", "end of feerate range"},
{RPCResult::Type::NUM, "withintarget", "number of txs over history horizon in the feerate range that were confirmed within target"},
{RPCResult::Type::NUM, "totalconfirmed", "number of txs over history horizon in the feerate range that were confirmed at any point"},
{RPCResult::Type::NUM, "inmempool", "current number of txs in mempool in the feerate range unconfirmed for at least target blocks"},
{RPCResult::Type::NUM, "leftmempool", "number of txs over history horizon in the feerate range that left mempool unconfirmed after target"},
};
return elide ? ElideGroup(std::move(fields)) : fields;
}
static std::vector<RPCResult> FeeEstimateHorizonDoc(bool elide = false)
{
auto fields = std::vector<RPCResult>{
{RPCResult::Type::NUM, "feerate", /*optional=*/true, "estimate fee rate in " + CURRENCY_UNIT + "/kvB"},
{RPCResult::Type::NUM, "decay", "exponential decay (per block) for historical moving average of confirmation data"},
{RPCResult::Type::NUM, "scale", "The resolution of confirmation targets at this time horizon"},
{RPCResult::Type::OBJ, "pass", /*optional=*/true, "information about the lowest range of feerates to succeed in meeting the threshold", FeeRateBucketDoc()},
{RPCResult::Type::OBJ, "fail", /*optional=*/true, "information about the highest range of feerates to fail to meet the threshold", FeeRateBucketDoc(/*elide=*/true)},
{RPCResult::Type::ARR, "errors", /*optional=*/true, "Errors encountered during processing (if there are any)",
{
{RPCResult::Type::STR, "error", ""},
}},
};
return elide ? ElideGroup(std::move(fields)) : fields;
}
static RPCMethod estimaterawfee()
{
return RPCMethod{
@@ -115,36 +144,11 @@ static RPCMethod estimaterawfee()
RPCResult::Type::OBJ, "", "Results are returned for any horizon which tracks blocks up to the confirmation target",
{
{RPCResult::Type::OBJ, "short", /*optional=*/true, "estimate for short time horizon",
{
{RPCResult::Type::NUM, "feerate", /*optional=*/true, "estimate fee rate in " + CURRENCY_UNIT + "/kvB"},
{RPCResult::Type::NUM, "decay", "exponential decay (per block) for historical moving average of confirmation data"},
{RPCResult::Type::NUM, "scale", "The resolution of confirmation targets at this time horizon"},
{RPCResult::Type::OBJ, "pass", /*optional=*/true, "information about the lowest range of feerates to succeed in meeting the threshold",
{
{RPCResult::Type::NUM, "startrange", "start of feerate range"},
{RPCResult::Type::NUM, "endrange", "end of feerate range"},
{RPCResult::Type::NUM, "withintarget", "number of txs over history horizon in the feerate range that were confirmed within target"},
{RPCResult::Type::NUM, "totalconfirmed", "number of txs over history horizon in the feerate range that were confirmed at any point"},
{RPCResult::Type::NUM, "inmempool", "current number of txs in mempool in the feerate range unconfirmed for at least target blocks"},
{RPCResult::Type::NUM, "leftmempool", "number of txs over history horizon in the feerate range that left mempool unconfirmed after target"},
}},
{RPCResult::Type::OBJ, "fail", /*optional=*/true, "information about the highest range of feerates to fail to meet the threshold",
{
{RPCResult::Type::ELISION, "", ""},
}},
{RPCResult::Type::ARR, "errors", /*optional=*/true, "Errors encountered during processing (if there are any)",
{
{RPCResult::Type::STR, "error", ""},
}},
}},
FeeEstimateHorizonDoc()},
{RPCResult::Type::OBJ, "medium", /*optional=*/true, "estimate for medium time horizon",
{
{RPCResult::Type::ELISION, "", ""},
}},
FeeEstimateHorizonDoc(/*elide=*/true)},
{RPCResult::Type::OBJ, "long", /*optional=*/true, "estimate for long time horizon",
{
{RPCResult::Type::ELISION, "", ""},
}},
FeeEstimateHorizonDoc(/*elide=*/true)},
}},
RPCExamples{
HelpExampleCli("estimaterawfee", "6 0.9")