aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2021-08-24 09:55:35 +0800
committerfanquake <fanquake@gmail.com>2021-08-24 10:43:38 +0800
commit61a843e43bf113df7fa6062c84257c76ee40141f (patch)
treecbf88957727f1baa93a67b5c58630461c71c123f /src/wallet
parentd3203a99d886177eee9d1f9cd8411e215118a4e6 (diff)
parentf7752adba5dd35fccd3f2144cfcf03538ebf275b (diff)
Merge bitcoin/bitcoin#22220: util: make ParseMoney return a std::optional<CAmount>
f7752adba5dd35fccd3f2144cfcf03538ebf275b util: check MoneyRange() inside ParseMoney() (fanquake) 5ef2738089efd396186775ad23aaec71ea44ebb1 util: make ParseMoney return a std::optional<CAmount> (fanquake) Pull request description: Related discussion in #22193. ACKs for top commit: MarcoFalke: review ACK f7752adba5dd35fccd3f2144cfcf03538ebf275b 📄 Tree-SHA512: 88453f9e28f668deff4290d4bc0b2468cbd54699a3be1bfeac63a512276d309354672e7ea7deefa01466c3d9d826e837cc1ea244d4d74b4fa9c11c56f074e098
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 cf869fac0c..dbcfc4dac3 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -2609,72 +2609,73 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
}
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());
@@ -2683,20 +2684,21 @@ std::shared_ptr<CWallet> CWallet::Create(WalletContext& context, const std::stri
}
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) {