mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
fees: add FeeModes doc helper function
This commit is contained in:
parent
91f6d2bc8f
commit
5d1a411eb1
3 changed files with 41 additions and 32 deletions
|
@ -6,11 +6,16 @@
|
|||
#include <util/fees.h>
|
||||
|
||||
#include <policy/fees.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/string.h>
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
std::string StringForFeeReason(FeeReason reason) {
|
||||
std::string StringForFeeReason(FeeReason reason)
|
||||
{
|
||||
static const std::map<FeeReason, std::string> fee_reason_strings = {
|
||||
{FeeReason::NONE, "None"},
|
||||
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
|
||||
|
@ -29,16 +34,29 @@ std::string StringForFeeReason(FeeReason reason) {
|
|||
return reason_string->second;
|
||||
}
|
||||
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) {
|
||||
static const std::map<std::string, FeeEstimateMode> fee_modes = {
|
||||
{"UNSET", FeeEstimateMode::UNSET},
|
||||
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
|
||||
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
|
||||
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
|
||||
{
|
||||
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
|
||||
{"unset", FeeEstimateMode::UNSET},
|
||||
{"economical", FeeEstimateMode::ECONOMICAL},
|
||||
{"conservative", FeeEstimateMode::CONSERVATIVE},
|
||||
};
|
||||
auto mode = fee_modes.find(mode_string);
|
||||
|
||||
if (mode == fee_modes.end()) return false;
|
||||
|
||||
fee_estimate_mode = mode->second;
|
||||
return true;
|
||||
return FEE_MODES;
|
||||
}
|
||||
|
||||
std::string FeeModes(const std::string& delimiter)
|
||||
{
|
||||
return Join(FeeModeMap(), delimiter, [&](const std::pair<std::string, FeeEstimateMode>& i) { return i.first; });
|
||||
}
|
||||
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode)
|
||||
{
|
||||
auto searchkey = ToUpper(mode_string);
|
||||
for (const auto& pair : FeeModeMap()) {
|
||||
if (ToUpper(pair.first) == searchkey) {
|
||||
fee_estimate_mode = pair.second;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -12,5 +12,6 @@ enum class FeeReason;
|
|||
|
||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
|
||||
std::string StringForFeeReason(FeeReason reason);
|
||||
std::string FeeModes(const std::string& delimiter);
|
||||
|
||||
#endif // BITCOIN_UTIL_FEES_H
|
||||
|
|
|
@ -370,10 +370,8 @@ static UniValue sendtoaddress(const JSONRPCRequest& request)
|
|||
" The recipient will receive less bitcoins than you enter in the amount field."},
|
||||
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Allow this transaction to be replaced by a transaction with higher fees via BIP 125"},
|
||||
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
|
||||
" \"UNSET\"\n"
|
||||
" \"ECONOMICAL\"\n"
|
||||
" \"CONSERVATIVE\""},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||
" \"" + FeeModes("\"\n\"") + "\""},
|
||||
{"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"
|
||||
" dirty if they have previously been used in a transaction."},
|
||||
},
|
||||
|
@ -781,10 +779,8 @@ static UniValue sendmany(const JSONRPCRequest& request)
|
|||
},
|
||||
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Allow this transaction to be replaced by a transaction with higher fees via BIP 125"},
|
||||
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
|
||||
" \"UNSET\"\n"
|
||||
" \"ECONOMICAL\"\n"
|
||||
" \"CONSERVATIVE\""},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||
" \"" + FeeModes("\"\n\"") + "\""},
|
||||
},
|
||||
RPCResult{
|
||||
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)
|
|||
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Marks this transaction as BIP125 replaceable.\n"
|
||||
" Allows this transaction to be replaced by a transaction with higher fees"},
|
||||
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
|
||||
" \"UNSET\"\n"
|
||||
" \"ECONOMICAL\"\n"
|
||||
" \"CONSERVATIVE\""},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||
" \"" + FeeModes("\"\n\"") + "\""},
|
||||
},
|
||||
"options"},
|
||||
{"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)
|
|||
" so the new transaction will not be explicitly bip-125 replaceable (though it may\n"
|
||||
" still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
|
||||
" are replaceable)."},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
|
||||
" \"UNSET\"\n"
|
||||
" \"ECONOMICAL\"\n"
|
||||
" \"CONSERVATIVE\""},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||
" \"" + FeeModes("\"\n\"") + "\""},
|
||||
},
|
||||
"options"},
|
||||
},
|
||||
|
@ -4036,10 +4028,8 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
|
|||
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Marks this transaction as BIP125 replaceable.\n"
|
||||
" Allows this transaction to be replaced by a transaction with higher fees"},
|
||||
{"conf_target", RPCArg::Type::NUM, /* default */ "fall back to wallet's confirmation target (txconfirmtarget)", "Confirmation target (in blocks)"},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
|
||||
" \"UNSET\"\n"
|
||||
" \"ECONOMICAL\"\n"
|
||||
" \"CONSERVATIVE\""},
|
||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||
" \"" + FeeModes("\"\n\"") + "\""},
|
||||
},
|
||||
"options"},
|
||||
{"bip32derivs", RPCArg::Type::BOOL, /* default */ "true", "Include BIP 32 derivation paths for public keys if we know them"},
|
||||
|
|
Loading…
Reference in a new issue