mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -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 <util/fees.h>
|
||||||
|
|
||||||
#include <policy/fees.h>
|
#include <policy/fees.h>
|
||||||
|
#include <util/strencodings.h>
|
||||||
|
#include <util/string.h>
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#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 = {
|
static const std::map<FeeReason, std::string> fee_reason_strings = {
|
||||||
{FeeReason::NONE, "None"},
|
{FeeReason::NONE, "None"},
|
||||||
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
|
{FeeReason::HALF_ESTIMATE, "Half Target 60% Threshold"},
|
||||||
|
@ -29,16 +34,29 @@ std::string StringForFeeReason(FeeReason reason) {
|
||||||
return reason_string->second;
|
return reason_string->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode) {
|
const std::vector<std::pair<std::string, FeeEstimateMode>>& FeeModeMap()
|
||||||
static const std::map<std::string, FeeEstimateMode> fee_modes = {
|
{
|
||||||
{"UNSET", FeeEstimateMode::UNSET},
|
static const std::vector<std::pair<std::string, FeeEstimateMode>> FEE_MODES = {
|
||||||
{"ECONOMICAL", FeeEstimateMode::ECONOMICAL},
|
{"unset", FeeEstimateMode::UNSET},
|
||||||
{"CONSERVATIVE", FeeEstimateMode::CONSERVATIVE},
|
{"economical", FeeEstimateMode::ECONOMICAL},
|
||||||
|
{"conservative", FeeEstimateMode::CONSERVATIVE},
|
||||||
};
|
};
|
||||||
auto mode = fee_modes.find(mode_string);
|
return FEE_MODES;
|
||||||
|
}
|
||||||
if (mode == fee_modes.end()) return false;
|
|
||||||
|
std::string FeeModes(const std::string& delimiter)
|
||||||
fee_estimate_mode = mode->second;
|
{
|
||||||
return true;
|
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);
|
bool FeeModeFromString(const std::string& mode_string, FeeEstimateMode& fee_estimate_mode);
|
||||||
std::string StringForFeeReason(FeeReason reason);
|
std::string StringForFeeReason(FeeReason reason);
|
||||||
|
std::string FeeModes(const std::string& delimiter);
|
||||||
|
|
||||||
#endif // BITCOIN_UTIL_FEES_H
|
#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."},
|
" 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"},
|
{"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)"},
|
{"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"
|
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||||
" \"UNSET\"\n"
|
" \"" + FeeModes("\"\n\"") + "\""},
|
||||||
" \"ECONOMICAL\"\n"
|
|
||||||
" \"CONSERVATIVE\""},
|
|
||||||
{"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"
|
{"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."},
|
" 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"},
|
{"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)"},
|
{"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"
|
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||||
" \"UNSET\"\n"
|
" \"" + FeeModes("\"\n\"") + "\""},
|
||||||
" \"ECONOMICAL\"\n"
|
|
||||||
" \"CONSERVATIVE\""},
|
|
||||||
},
|
},
|
||||||
RPCResult{
|
RPCResult{
|
||||||
RPCResult::Type::STR_HEX, "txid", "The transaction id for the send. Only 1 transaction is created regardless of\n"
|
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"
|
{"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"},
|
" Allows this transaction to be replaced by a transaction with higher fees"},
|
||||||
{"conf_target", RPCArg::Type::NUM, /* default */ "wallet default", "Confirmation target (in blocks)"},
|
{"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"
|
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||||
" \"UNSET\"\n"
|
" \"" + FeeModes("\"\n\"") + "\""},
|
||||||
" \"ECONOMICAL\"\n"
|
|
||||||
" \"CONSERVATIVE\""},
|
|
||||||
},
|
},
|
||||||
"options"},
|
"options"},
|
||||||
{"iswitness", RPCArg::Type::BOOL, /* default */ "depends on heuristic tests", "Whether the transaction hex is a serialized witness transaction.\n"
|
{"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"
|
" 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"
|
" still be replaceable in practice, for example if it has unconfirmed ancestors which\n"
|
||||||
" are replaceable)."},
|
" are replaceable)."},
|
||||||
{"estimate_mode", RPCArg::Type::STR, /* default */ "UNSET", "The fee estimate mode, must be one of:\n"
|
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||||
" \"UNSET\"\n"
|
" \"" + FeeModes("\"\n\"") + "\""},
|
||||||
" \"ECONOMICAL\"\n"
|
|
||||||
" \"CONSERVATIVE\""},
|
|
||||||
},
|
},
|
||||||
"options"},
|
"options"},
|
||||||
},
|
},
|
||||||
|
@ -4036,10 +4028,8 @@ UniValue walletcreatefundedpsbt(const JSONRPCRequest& request)
|
||||||
{"replaceable", RPCArg::Type::BOOL, /* default */ "wallet default", "Marks this transaction as BIP125 replaceable.\n"
|
{"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"},
|
" 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)"},
|
{"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"
|
{"estimate_mode", RPCArg::Type::STR, /* default */ "unset", std::string() + "The fee estimate mode, must be one of (case insensitive):\n"
|
||||||
" \"UNSET\"\n"
|
" \"" + FeeModes("\"\n\"") + "\""},
|
||||||
" \"ECONOMICAL\"\n"
|
|
||||||
" \"CONSERVATIVE\""},
|
|
||||||
},
|
},
|
||||||
"options"},
|
"options"},
|
||||||
{"bip32derivs", RPCArg::Type::BOOL, /* default */ "true", "Include BIP 32 derivation paths for public keys if we know them"},
|
{"bip32derivs", RPCArg::Type::BOOL, /* default */ "true", "Include BIP 32 derivation paths for public keys if we know them"},
|
||||||
|
|
Loading…
Add table
Reference in a new issue