aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2021-06-11 12:33:20 +0800
committerfanquake <fanquake@gmail.com>2021-08-04 19:48:24 +0800
commit5ef2738089efd396186775ad23aaec71ea44ebb1 (patch)
tree78b1d357ae955c7481f6dee1d15217a7271b2ecd /src/wallet
parent3308c61091b6b7cb22569f3abadea6d001295c90 (diff)
downloadbitcoin-5ef2738089efd396186775ad23aaec71ea44ebb1.tar.xz
util: make ParseMoney return a std::optional<CAmount>
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/wallet.cpp70
1 files changed, 36 insertions, 34 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index 9a61ca698d..198717f173 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2602,72 +2602,73 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain* chain, const std::st
}
if (gArgs.IsArgSet("-mintxfee")) {
- CAmount n = 0;
- if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
+ std::optional<CAmount> min_tx_fee = ParseMoney(gArgs.GetArg("-mintxfee", ""));
+ if (!min_tx_fee || min_tx_fee.value() == 0) {
error = AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""));
return nullptr;
- }
- if (n > HIGH_TX_FEE_PER_KB) {
+ } else if (min_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-mintxfee") + Untranslated(" ") +
_("This is the minimum transaction fee you pay on every transaction."));
}
- walletInstance->m_min_fee = CFeeRate(n);
+
+ walletInstance->m_min_fee = CFeeRate{min_tx_fee.value()};
}
if (gArgs.IsArgSet("-maxapsfee")) {
const std::string max_aps_fee{gArgs.GetArg("-maxapsfee", "")};
- CAmount n = 0;
if (max_aps_fee == "-1") {
- n = -1;
- } else if (!ParseMoney(max_aps_fee, n)) {
+ walletInstance->m_max_aps_fee = -1;
+ } else if (std::optional<CAmount> max_fee = ParseMoney(max_aps_fee)) {
+ if (max_fee.value() > HIGH_APS_FEE) {
+ warnings.push_back(AmountHighWarn("-maxapsfee") + Untranslated(" ") +
+ _("This is the maximum transaction fee you pay (in addition to the normal fee) to prioritize partial spend avoidance over regular coin selection."));
+ }
+ walletInstance->m_max_aps_fee = max_fee.value();
+ } else {
error = AmountErrMsg("maxapsfee", max_aps_fee);
return nullptr;
}
- if (n > HIGH_APS_FEE) {
- warnings.push_back(AmountHighWarn("-maxapsfee") + Untranslated(" ") +
- _("This is the maximum transaction fee you pay (in addition to the normal fee) to prioritize partial spend avoidance over regular coin selection."));
- }
- walletInstance->m_max_aps_fee = n;
}
if (gArgs.IsArgSet("-fallbackfee")) {
- CAmount nFeePerK = 0;
- if (!ParseMoney(gArgs.GetArg("-fallbackfee", ""), nFeePerK)) {
+ std::optional<CAmount> fallback_fee = ParseMoney(gArgs.GetArg("-fallbackfee", ""));
+ if (!fallback_fee) {
error = strprintf(_("Invalid amount for -fallbackfee=<amount>: '%s'"), gArgs.GetArg("-fallbackfee", ""));
return nullptr;
- }
- if (nFeePerK > HIGH_TX_FEE_PER_KB) {
+ } else if (fallback_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-fallbackfee") + Untranslated(" ") +
_("This is the transaction fee you may pay when fee estimates are not available."));
}
- walletInstance->m_fallback_fee = CFeeRate(nFeePerK);
+ walletInstance->m_fallback_fee = CFeeRate{fallback_fee.value()};
}
+
// Disable fallback fee in case value was set to 0, enable if non-null value
walletInstance->m_allow_fallback_fee = walletInstance->m_fallback_fee.GetFeePerK() != 0;
if (gArgs.IsArgSet("-discardfee")) {
- CAmount nFeePerK = 0;
- if (!ParseMoney(gArgs.GetArg("-discardfee", ""), nFeePerK)) {
+ std::optional<CAmount> discard_fee = ParseMoney(gArgs.GetArg("-discardfee", ""));
+ if (!discard_fee) {
error = strprintf(_("Invalid amount for -discardfee=<amount>: '%s'"), gArgs.GetArg("-discardfee", ""));
return nullptr;
- }
- if (nFeePerK > HIGH_TX_FEE_PER_KB) {
+ } else if (discard_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-discardfee") + Untranslated(" ") +
_("This is the transaction fee you may discard if change is smaller than dust at this level"));
}
- walletInstance->m_discard_rate = CFeeRate(nFeePerK);
+ walletInstance->m_discard_rate = CFeeRate{discard_fee.value()};
}
+
if (gArgs.IsArgSet("-paytxfee")) {
- CAmount nFeePerK = 0;
- if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
+ std::optional<CAmount> pay_tx_fee = ParseMoney(gArgs.GetArg("-paytxfee", ""));
+ if (!pay_tx_fee) {
error = AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", ""));
return nullptr;
- }
- if (nFeePerK > HIGH_TX_FEE_PER_KB) {
+ } else if (pay_tx_fee.value() > HIGH_TX_FEE_PER_KB) {
warnings.push_back(AmountHighWarn("-paytxfee") + Untranslated(" ") +
_("This is the transaction fee you will pay if you send a transaction."));
}
- walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
+
+ walletInstance->m_pay_tx_fee = CFeeRate{pay_tx_fee.value(), 1000};
+
if (chain && walletInstance->m_pay_tx_fee < chain->relayMinFee()) {
error = strprintf(_("Invalid amount for -paytxfee=<amount>: '%s' (must be at least %s)"),
gArgs.GetArg("-paytxfee", ""), chain->relayMinFee().ToString());
@@ -2676,20 +2677,21 @@ std::shared_ptr<CWallet> CWallet::Create(interfaces::Chain* chain, const std::st
}
if (gArgs.IsArgSet("-maxtxfee")) {
- CAmount nMaxFee = 0;
- if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) {
+ std::optional<CAmount> max_fee = ParseMoney(gArgs.GetArg("-maxtxfee", ""));
+ if (!max_fee) {
error = AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", ""));
return nullptr;
- }
- if (nMaxFee > HIGH_MAX_TX_FEE) {
+ } else if (max_fee.value() > HIGH_MAX_TX_FEE) {
warnings.push_back(_("-maxtxfee is set very high! Fees this large could be paid on a single transaction."));
}
- if (chain && CFeeRate(nMaxFee, 1000) < chain->relayMinFee()) {
+
+ if (chain && CFeeRate{max_fee.value(), 1000} < chain->relayMinFee()) {
error = strprintf(_("Invalid amount for -maxtxfee=<amount>: '%s' (must be at least the minrelay fee of %s to prevent stuck transactions)"),
gArgs.GetArg("-maxtxfee", ""), chain->relayMinFee().ToString());
return nullptr;
}
- walletInstance->m_default_max_tx_fee = nMaxFee;
+
+ walletInstance->m_default_max_tx_fee = max_fee.value();
}
if (chain && chain->relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB) {