From ed39219aca66d26eff9f749b544bf8c715add2e6 Mon Sep 17 00:00:00 2001 From: backpacker69 Date: Thu, 8 Aug 2019 15:12:37 +0300 Subject: [PATCH] estimatefee and estimatesmartfee methods --- src/rpc/client.cpp | 2 ++ src/rpc/mining.cpp | 73 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/src/rpc/client.cpp b/src/rpc/client.cpp index 80acce865cf..ab9ea28e2b4 100644 --- a/src/rpc/client.cpp +++ b/src/rpc/client.cpp @@ -112,6 +112,8 @@ static const CRPCConvertParam vRPCConvertParams[] = { "pruneblockchain", 0, "height" }, { "keypoolrefill", 0, "newsize" }, { "getrawmempool", 0, "verbose" }, + { "estimatefee", 0, "nblocks" }, + { "estimatesmartfee", 0, "conf_target" }, { "prioritisetransaction", 1, "dummy" }, { "prioritisetransaction", 2, "fee_delta" }, { "setban", 2, "bantime" }, diff --git a/src/rpc/mining.cpp b/src/rpc/mining.cpp index f9b0808f374..b3144eba306 100644 --- a/src/rpc/mining.cpp +++ b/src/rpc/mining.cpp @@ -771,6 +771,76 @@ UniValue submitblock(const JSONRPCRequest& request) return BIP22ValidationResult(sc.state); } +UniValue estimatefee(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() != 1) + throw std::runtime_error( + "estimatefee nblocks\n" + "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" + "confirmation within nblocks blocks. Uses virtual transaction size of transaction\n" + "as defined in BIP 141 (witness data is discounted).\n" + "\nArguments:\n" + "1. nblocks (numeric, required)\n" + "\nResult:\n" + "n (numeric) estimated fee-per-kilobyte\n" + "\n" + "A negative value is returned if not enough transactions and blocks\n" + "have been observed to make an estimate.\n" + "-1 is always returned for nblocks == 1 as it is impossible to calculate\n" + "a fee that is high enough to get reliably included in the next block.\n" + "\nExample:\n" + + HelpExampleCli("estimatefee", "6") + ); + + RPCTypeCheck(request.params, {UniValue::VNUM}); + + return 0.01; +} + +UniValue estimatesmartfee(const JSONRPCRequest& request) +{ + if (request.fHelp || request.params.size() < 1 || request.params.size() > 2) + throw std::runtime_error( + "estimatesmartfee conf_target (\"estimate_mode\")\n" + "\nEstimates the approximate fee per kilobyte needed for a transaction to begin\n" + "confirmation within conf_target blocks if possible and return the number of blocks\n" + "for which the estimate is valid. Uses virtual transaction size as defined\n" + "in BIP 141 (witness data is discounted).\n" + "\nArguments:\n" + "1. conf_target (numeric) Confirmation target in blocks (1 - 1008)\n" + "2. \"estimate_mode\" (string, optional, default=CONSERVATIVE) The fee estimate mode.\n" + " Whether to return a more conservative estimate which also satisfies\n" + " a longer history. A conservative estimate potentially returns a\n" + " higher feerate and is more likely to be sufficient for the desired\n" + " target, but is not as responsive to short term drops in the\n" + " prevailing fee market. Must be one of:\n" + " \"UNSET\" (defaults to CONSERVATIVE)\n" + " \"ECONOMICAL\"\n" + " \"CONSERVATIVE\"\n" + "\nResult:\n" + "{\n" + " \"feerate\" : x.x, (numeric, optional) estimate fee rate in " + CURRENCY_UNIT + "/kB\n" + " \"errors\": [ str... ] (json array of strings, optional) Errors encountered during processing\n" + " \"blocks\" : n (numeric) block number where estimate was found\n" + "}\n" + "\n" + "The request target will be clamped between 2 and the highest target\n" + "fee estimation is able to return based on how long it has been running.\n" + "An error is returned if not enough transactions and blocks\n" + "have been observed to make an estimate for any number of blocks.\n" + "\nExample:\n" + + HelpExampleCli("estimatesmartfee", "6") + ); + + RPCTypeCheck(request.params, {UniValue::VNUM, UniValue::VSTR}); + RPCTypeCheckArgument(request.params[0], UniValue::VNUM); + + UniValue result(UniValue::VOBJ); + result.push_back(Pair("feerate", 0.01)); + result.push_back(Pair("blocks", chainActive.Height())); + return result; +} + static const CRPCCommand commands[] = { // category name actor (function) argNames // --------------------- ------------------------ ----------------------- ---------- @@ -782,6 +852,9 @@ static const CRPCCommand commands[] = { "generating", "generatetoaddress", &generatetoaddress, {"nblocks","address","maxtries"} }, + + { "util", "estimatefee", &estimatefee, {"nblocks"} }, + { "util", "estimatesmartfee", &estimatesmartfee, {"conf_target", "estimate_mode"} }, }; void RegisterMiningRPCCommands(CRPCTable &t)