MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / estimatesmartfee

Function estimatesmartfee

src/rpc/mining.cpp:883–942  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

881}
882
883static UniValue estimatesmartfee(const JSONRPCRequest& request)
884{
885 if (request.fHelp || request.params.size() < 1 || request.params.size() > 2)
886 throw std::runtime_error(
887 "estimatesmartfee conf_target (\"estimate_mode\")\n"
888 "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n"
889 "confirmation within conf_target blocks if possible and return the number of blocks\n"
890 "for which the estimate is valid. Uses virtual transaction size as defined\n"
891 "in BIP 141 (witness data is discounted).\n"
892 "\nArguments:\n"
893 "1. conf_target (numeric) Confirmation target in blocks (1 - 1008)\n"
894 "2. \"estimate_mode\" (string, optional, default=CONSERVATIVE) The fee estimate mode.\n"
895 " Whether to return a more conservative estimate which also satisfies\n"
896 " a longer history. A conservative estimate potentially returns a\n"
897 " higher feerate and is more likely to be sufficient for the desired\n"
898 " target, but is not as responsive to short term drops in the\n"
899 " prevailing fee market. Must be one of:\n"
900 " \"UNSET\" (defaults to CONSERVATIVE)\n"
901 " \"ECONOMICAL\"\n"
902 " \"CONSERVATIVE\"\n"
903 "\nResult:\n"
904 "{\n"
905 " \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n"
906 " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n"
907 " \"blocks\" : n (numeric) block number where estimate was found\n"
908 "}\n"
909 "\n"
910 "The request target will be clamped between 2 and the highest target\n"
911 "fee estimation is able to return based on how long it has been running.\n"
912 "An error is returned if not enough transactions and blocks\n"
913 "have been observed to make an estimate for any number of blocks.\n"
914 "\nExample:\n"
915 + HelpExampleCli("estimatesmartfee", "6")
916 );
917
918 RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR});
919 RPCTypeCheckArgument(request.params[0], UniValue::VNUM);
920 unsigned int conf_target = ParseConfirmTarget(request.params[0]);
921 bool conservative = true;
922 if (!request.params[1].isNull()) {
923 FeeEstimateMode fee_mode;
924 if (!FeeModeFromString(request.params[1].get_str(), fee_mode)) {
925 throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
926 }
927 if (fee_mode == FeeEstimateMode::ECONOMICAL) conservative = false;
928 }
929
930 UniValue result(UniValue::VOBJ);
931 UniValue errors(UniValue::VARR);
932 FeeCalculation feeCalc;
933 CFeeRate feeRate = ::feeEstimator.estimateSmartFee(conf_target, &feeCalc, conservative);
934 if (feeRate != CFeeRate(0)) {
935 result.pushKV("feerate", ValueFromAmount(feeRate.GetFeePerK()));
936 } else {
937 errors.push_back("Insufficient data or no feerate found");
938 result.pushKV("errors", errors);
939 }
940 result.pushKV("blocks", feeCalc.returnedTarget);

Callers

nothing calls this directly

Calls 14

HelpExampleCliFunction · 0.85
RPCTypeCheckFunction · 0.85
RPCTypeCheckArgumentFunction · 0.85
ParseConfirmTargetFunction · 0.85
FeeModeFromStringFunction · 0.85
JSONRPCErrorFunction · 0.85
ValueFromAmountFunction · 0.85
isNullMethod · 0.80
GetFeePerKMethod · 0.80
CFeeRateClass · 0.50
sizeMethod · 0.45
estimateSmartFeeMethod · 0.45

Tested by

no test coverage detected