Skip to content

Commit 5cbc1f6

Browse files
committed
Switch RPC option from conservative_estimate bool to estimate_mode string
1 parent 718a2c7 commit 5cbc1f6

File tree

4 files changed

+63
-16
lines changed

4 files changed

+63
-16
lines changed

src/policy/fees.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ std::string StringForFeeReason(FeeReason reason) {
3636
return reason_string->second;
3737
}
3838

39+
boost::optional<FeeEstimateMode> FeeModeForString(std::string mode_string) {
40+
static const std::map<std::string, FeeEstimateMode> fee_modes = {
41+
{"UNSET", FeeEstimateMode::UNSET},
42+
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
43+
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
44+
};
45+
auto mode = fee_modes.find(mode_string);
46+
47+
if (mode == fee_modes.end()) return boost::none;
48+
49+
return mode->second;
50+
}
51+
3952
/**
4053
* We will instantiate an instance of this class to track transactions that were
4154
* included in a block. We will lump transactions into a bucket according to their

src/policy/fees.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include "random.h"
1212
#include "sync.h"
1313

14+
#include <boost/optional.hpp>
15+
1416
#include <map>
1517
#include <string>
1618
#include <vector>
@@ -97,6 +99,8 @@ enum class FeeEstimateMode {
9799
CONSERVATIVE, //! Force estimateSmartFee to use conservative estimates
98100
};
99101

102+
boost::optional<FeeEstimateMode> FeeModeForString(std::string mode_string);
103+
100104
/* Used to return detailed information about a feerate bucket */
101105
struct EstimatorBucket
102106
{

src/rpc/client.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
3939
{ "sendtoaddress", 4, "subtractfeefromamount" },
4040
{ "sendtoaddress", 5 , "opt_in_rbf" },
4141
{ "sendtoaddress", 6 , "conf_target" },
42-
{ "sendtoaddress", 7 , "conservative_estimate" },
4342
{ "settxfee", 0, "amount" },
4443
{ "getreceivedbyaddress", 1, "minconf" },
4544
{ "getreceivedbyaccount", 1, "minconf" },
@@ -74,7 +73,6 @@ static const CRPCConvertParam vRPCConvertParams[] =
7473
{ "sendmany", 4, "subtractfeefrom" },
7574
{ "sendmany", 5 , "opt_in_rbf" },
7675
{ "sendmany", 6 , "conf_target" },
77-
{ "sendmany", 7 , "conservative_estimate" },
7876
{ "addmultisigaddress", 0, "nrequired" },
7977
{ "addmultisigaddress", 1, "keys" },
8078
{ "createmultisig", 0, "nrequired" },

src/wallet/rpcwallet.cpp

Lines changed: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,10 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
417417
" The recipient will receive less bitcoins than you enter in the amount field.\n"
418418
"6. opt_in_rbf (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees\n"
419419
"7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
420-
"8. conservative_estimate (boolean, optional) Use conservative (potentially higher) fee estimation\n"
420+
"8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
421+
" \"UNSET\"\n"
422+
" \"ECONOMICAL\"\n"
423+
" \"CONSERVATIVE\"\n"
421424
"\nResult:\n"
422425
"\"txid\" (string) The transaction id.\n"
423426
"\nExamples:\n"
@@ -460,7 +463,12 @@ UniValue sendtoaddress(const JSONRPCRequest& request)
460463
}
461464

462465
if (request.params.size() > 7 && !request.params[7].isNull()) {
463-
coin_control.m_fee_mode = request.params[7].get_bool() ? FeeEstimateMode::CONSERVATIVE : FeeEstimateMode::ECONOMICAL;
466+
if (boost::optional<FeeEstimateMode> fee_mode = FeeModeForString(request.params[7].get_str())) {
467+
coin_control.m_fee_mode = *fee_mode;
468+
}
469+
else {
470+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
471+
}
464472
}
465473

466474

@@ -929,7 +937,10 @@ UniValue sendmany(const JSONRPCRequest& request)
929937
" ]\n"
930938
"6. opt_in_rbf (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees\n"
931939
"7. conf_target (numeric, optional) Confirmation target (in blocks)\n"
932-
"8. conservative_estimate (boolean, optional) Use conservative (potentially higher) fee estimation\n"
940+
"8. \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
941+
" \"UNSET\"\n"
942+
" \"ECONOMICAL\"\n"
943+
" \"CONSERVATIVE\"\n"
933944
"\nResult:\n"
934945
"\"txid\" (string) The transaction id for the send. Only 1 transaction is created regardless of \n"
935946
" the number of addresses.\n"
@@ -975,7 +986,12 @@ UniValue sendmany(const JSONRPCRequest& request)
975986
}
976987

977988
if (request.params.size() > 7 && !request.params[7].isNull()) {
978-
coin_control.m_fee_mode = request.params[7].get_bool() ? FeeEstimateMode::CONSERVATIVE : FeeEstimateMode::ECONOMICAL;
989+
if (boost::optional<FeeEstimateMode> fee_mode = FeeModeForString(request.params[7].get_str())) {
990+
coin_control.m_fee_mode = *fee_mode;
991+
}
992+
else {
993+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
994+
}
979995
}
980996

981997
std::set<CBitcoinAddress> setAddress;
@@ -2692,7 +2708,10 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
26922708
" [vout_index,...]\n"
26932709
" \"optIntoRbf\" (boolean, optional) Allow this transaction to be replaced by a transaction with higher fees\n"
26942710
" \"conf_target\" (numeric, optional) Confirmation target (in blocks)\n"
2695-
" \"conservative_estimate\" (boolean, optional) Use conservative (potentially higher) fee estimation\n"
2711+
" \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
2712+
" \"UNSET\"\n"
2713+
" \"ECONOMICAL\"\n"
2714+
" \"CONSERVATIVE\"\n"
26962715
" }\n"
26972716
" for backward compatibility: passing in a true instead of an object will result in {\"includeWatching\":true}\n"
26982717
"\nResult:\n"
@@ -2746,7 +2765,7 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
27462765
{"subtractFeeFromOutputs", UniValueType(UniValue::VARR)},
27472766
{"optIntoRbf", UniValueType(UniValue::VBOOL)},
27482767
{"conf_target", UniValueType(UniValue::VNUM)},
2749-
{"conservative_estimate", UniValueType(UniValue::VBOOL)},
2768+
{"estimate_mode", UniValueType(UniValue::VSTR)},
27502769
},
27512770
true, true);
27522771

@@ -2786,8 +2805,13 @@ UniValue fundrawtransaction(const JSONRPCRequest& request)
27862805
if (options.exists("conf_target")) {
27872806
coinControl.nConfirmTarget = options["conf_target"].get_int();
27882807
}
2789-
if (options.exists("conservative_estimate")) {
2790-
coinControl.m_fee_mode = options["conservative_estimate"].get_bool() ? FeeEstimateMode::CONSERVATIVE : FeeEstimateMode::ECONOMICAL;
2808+
if (options.exists("estimate_mode")) {
2809+
if (boost::optional<FeeEstimateMode> fee_mode = FeeModeForString(options["estimate_mode"].get_str())) {
2810+
coinControl.m_fee_mode = *fee_mode;
2811+
}
2812+
else {
2813+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
2814+
}
27912815
}
27922816
}
27932817
}
@@ -2866,7 +2890,10 @@ UniValue bumpfee(const JSONRPCRequest& request)
28662890
" so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
28672891
" still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
28682892
" are replaceable).\n"
2869-
" \"conservative_estimate\" (boolean, optional) Use conservative (potentially higher) fee estimation\n"
2893+
" \"estimate_mode\" (string, optional, default=UNSET) The fee estimate mode, must be one of:\n"
2894+
" \"UNSET\"\n"
2895+
" \"ECONOMICAL\"\n"
2896+
" \"CONSERVATIVE\"\n"
28702897
" }\n"
28712898
"\nResult:\n"
28722899
"{\n"
@@ -2897,7 +2924,7 @@ UniValue bumpfee(const JSONRPCRequest& request)
28972924
{"confTarget", UniValueType(UniValue::VNUM)},
28982925
{"totalFee", UniValueType(UniValue::VNUM)},
28992926
{"replaceable", UniValueType(UniValue::VBOOL)},
2900-
{"conservative_estimate", UniValueType(UniValue::VBOOL)},
2927+
{"estimate_mode", UniValueType(UniValue::VSTR)},
29012928
},
29022929
true, true);
29032930

@@ -2922,8 +2949,13 @@ UniValue bumpfee(const JSONRPCRequest& request)
29222949
if (options.exists("replaceable")) {
29232950
replaceable = options["replaceable"].get_bool();
29242951
}
2925-
if (options.exists("conservative_estimate")) {
2926-
fee_mode = options["conservative_estimate"].get_bool() ? FeeEstimateMode::CONSERVATIVE : FeeEstimateMode::ECONOMICAL;
2952+
if (options.exists("estimate_mode")) {
2953+
if (boost::optional<FeeEstimateMode> desired_fee_mode = FeeModeForString(options["estimate_mode"].get_str())) {
2954+
fee_mode = *desired_fee_mode;
2955+
}
2956+
else {
2957+
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid estimate_mode parameter");
2958+
}
29272959
}
29282960
}
29292961

@@ -3027,8 +3059,8 @@ static const CRPCCommand commands[] =
30273059
{ "wallet", "lockunspent", &lockunspent, true, {"unlock","transactions"} },
30283060
{ "wallet", "move", &movecmd, false, {"fromaccount","toaccount","amount","minconf","comment"} },
30293061
{ "wallet", "sendfrom", &sendfrom, false, {"fromaccount","toaddress","amount","minconf","comment","comment_to"} },
3030-
{ "wallet", "sendmany", &sendmany, false, {"fromaccount","amounts","minconf","comment","subtractfeefrom","opt_in_rbf","conf_target","conservative_estimate"} },
3031-
{ "wallet", "sendtoaddress", &sendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount","opt_in_rbf","conf_target","conservative_estimate"} },
3062+
{ "wallet", "sendmany", &sendmany, false, {"fromaccount","amounts","minconf","comment","subtractfeefrom","opt_in_rbf","conf_target","estimate_mode"} },
3063+
{ "wallet", "sendtoaddress", &sendtoaddress, false, {"address","amount","comment","comment_to","subtractfeefromamount","opt_in_rbf","conf_target","estimate_mode"} },
30323064
{ "wallet", "setaccount", &setaccount, true, {"address","account"} },
30333065
{ "wallet", "settxfee", &settxfee, true, {"amount"} },
30343066
{ "wallet", "signmessage", &signmessage, true, {"address","message"} },

0 commit comments

Comments
 (0)