mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-13 07:28:59 +01:00
util: make ParseMoney return a std::optional<CAmount>
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user