Skip to content

Commit 5d1a411

Browse files
committed
fees: add FeeModes doc helper function
1 parent 91f6d2b commit 5d1a411

File tree

3 files changed

+39
-30
lines changed

3 files changed

+39
-30
lines changed

src/util/fees.cpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
#include <util/fees.h>
77

88
#include <policy/fees.h>
9+
#include <util/strencodings.h>
10+
#include <util/string.h>
911

1012
#include <map>
1113
#include <string>
14+
#include <vector>
15+
#include <utility>
1216

13-
std::string StringForFeeReason(FeeReason reason) {
17+
std::string StringForFeeReason(FeeReason reason)
18+
{
1419
static const std::map<FeeReason, std::string> fee_reason_strings = {
1520
{FeeReason::NONE, "None"},
1621
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
@@ -29,16 +34,29 @@ std::string StringForFeeReason(FeeReason reason) {
2934
return reason_string->second;
3035
}
3136

32-
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) {
33-
static const std::map<std::string, FeeEstimateMode> fee_modes = {
34-
{"UNSET", FeeEstimateMode::UNSET},
35-
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
36-
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
37+
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
38+
{
39+
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
40+
{"unset", FeeEstimateMode::UNSET},
41+
{"economical", FeeEstimateMode::ECONOMICAL},
42+
{"conservative", FeeEstimateMode::CONSERVATIVE},
3743
};
38-
auto mode = fee_modes.find(mode_string);
44+
return FEE_MODES;
45+
}
3946

40-
if (mode == fee_modes.end()) return false;
47+
std::string FeeModes(const std::string& delimiter)
48+
{
49+
return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
50+
}
4151

42-
fee_estimate_mode = mode->second;
43-
return true;
52+
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
53+
{
54+
auto searchkey = ToUpper(mode_string);
55+
for (const auto& pair : FeeModeMap()) {
56+
if (ToUpper(pair.first) == searchkey) {
57+
fee_estimate_mode = pair.second;
58+
return true;
59+
}
60+
}
61+
return false;
4462
}

src/util/fees.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@ enum class FeeReason;
1212

1313
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
1414
std::string StringForFeeReason(FeeReason reason);
15+
std::string FeeModes(const std::string& delimiter);
1516

1617
#endif // BITCOIN_UTIL_FEES_H

src/wallet/rpcwallet.cpp

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,8 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
370370
" The recipient will receive less bitcoins than you enter in the amount field."},
371371
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Allow this transaction to be replaced by a transaction with higher fees via BIP 125"},
372372
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
373-
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
374-
" \"UNSET\"\n"
375-
" \"ECONOMICAL\"\n"
376-
" \"CONSERVATIVE\""},
373+
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
374+
" \"" + FeeModes("\"\n\"") + "\""},
377375
{"avoid_reuse", RPCArg::Type::BOOL, /* default */ "true", "(only available if avoid_reuse wallet flag is set) Avoid spending from dirty addresses; addresses are considered\n"
378376
" dirty if they have previously been used in a transaction."},
379377
},
@@ -781,10 +779,8 @@ static UniValue sendmany(const JSONRPCRequest& request)
781779
},
782780
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Allow this transaction to be replaced by a transaction with higher fees via BIP 125"},
783781
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
784-
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
785-
" \"UNSET\"\n"
786-
" \"ECONOMICAL\"\n"
787-
" \"CONSERVATIVE\""},
782+
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
783+
" \"" + FeeModes("\"\n\"") + "\""},
788784
},
789785
RPCResult{
790786
RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n"
@@ -3073,10 +3069,8 @@ static UniValue fundrawtransaction(const JSONRPCRequest& request)
30733069
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Marks this transaction as BIP125 replaceable.\n"
30743070
" Allows this transaction to be replaced by a transaction with higher fees"},
30753071
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
3076-
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
3077-
" \"UNSET\"\n"
3078-
" \"ECONOMICAL\"\n"
3079-
" \"CONSERVATIVE\""},
3072+
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
3073+
" \"" + FeeModes("\"\n\"") + "\""},
30803074
},
30813075
"options"},
30823076
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
@@ -3252,10 +3246,8 @@ static UniValue bumpfee(const JSONRPCRequest& request)
32523246
" so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
32533247
" still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
32543248
" are replaceable)."},
3255-
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
3256-
" \"UNSET\"\n"
3257-
" \"ECONOMICAL\"\n"
3258-
" \"CONSERVATIVE\""},
3249+
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
3250+
" \"" + FeeModes("\"\n\"") + "\""},
32593251
},
32603252
"options"},
32613253
},
@@ -4036,10 +4028,8 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
40364028
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Marks this transaction as BIP125 replaceable.\n"
40374029
" Allows this transaction to be replaced by a transaction with higher fees"},
40384030
{"conf_target", RPCArg::Type::NUM, /* default */ "fall back to wallet's confirmation target (txconfirmtarget)", "Confirmation target (in blocks)"},
4039-
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
4040-
" \"UNSET\"\n"
4041-
" \"ECONOMICAL\"\n"
4042-
" \"CONSERVATIVE\""},
4031+
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
4032+
" \"" + FeeModes("\"\n\"") + "\""},
40434033
},
40444034
"options"},
40454035
{"bip32derivs", RPCArg::Type::BOOL, /* default */ "true", "Include BIP 32 derivation paths for public keys if we know them"},

0 commit comments

Comments
 (0)