util: Make util/error bilingual_str (refactor)

Translated strings should not end up in the debug log, stderr, or
returned by an RPC.

Changing the util methods in util/error to return a bilingual_str paves
the way to achieve this goal in the long term.
This commit is contained in:
MarcoFalke 2019-08-20 11:00:43 -04:00
parent 119e97ae2d
commit fa70d199d0
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
4 changed files with 20 additions and 18 deletions

View file

@ -1060,7 +1060,7 @@ bool AppInitParameterInteraction()
{ {
CAmount n = 0; CAmount n = 0;
if (!ParseMoney(gArgs.GetArg("-incrementalrelayfee", ""), n)) if (!ParseMoney(gArgs.GetArg("-incrementalrelayfee", ""), n))
return InitError(AmountErrMsg("incrementalrelayfee", gArgs.GetArg("-incrementalrelayfee", ""))); return InitError(AmountErrMsg("incrementalrelayfee", gArgs.GetArg("-incrementalrelayfee", "")).translated);
incrementalRelayFee = CFeeRate(n); incrementalRelayFee = CFeeRate(n);
} }
@ -1104,7 +1104,7 @@ bool AppInitParameterInteraction()
if (gArgs.IsArgSet("-minrelaytxfee")) { if (gArgs.IsArgSet("-minrelaytxfee")) {
CAmount n = 0; CAmount n = 0;
if (!ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n)) { if (!ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n)) {
return InitError(AmountErrMsg("minrelaytxfee", gArgs.GetArg("-minrelaytxfee", ""))); return InitError(AmountErrMsg("minrelaytxfee", gArgs.GetArg("-minrelaytxfee", "")).translated);
} }
// High fee check is done afterward in WalletParameterInteraction() // High fee check is done afterward in WalletParameterInteraction()
::minRelayTxFee = CFeeRate(n); ::minRelayTxFee = CFeeRate(n);
@ -1120,7 +1120,7 @@ bool AppInitParameterInteraction()
{ {
CAmount n = 0; CAmount n = 0;
if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n))
return InitError(AmountErrMsg("blockmintxfee", gArgs.GetArg("-blockmintxfee", ""))); return InitError(AmountErrMsg("blockmintxfee", gArgs.GetArg("-blockmintxfee", "")).translated);
} }
// Feerate used to define dust. Shouldn't be changed lightly as old // Feerate used to define dust. Shouldn't be changed lightly as old
@ -1129,7 +1129,7 @@ bool AppInitParameterInteraction()
{ {
CAmount n = 0; CAmount n = 0;
if (!ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n)) if (!ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n))
return InitError(AmountErrMsg("dustrelayfee", gArgs.GetArg("-dustrelayfee", ""))); return InitError(AmountErrMsg("dustrelayfee", gArgs.GetArg("-dustrelayfee", "")).translated);
dustRelayFee = CFeeRate(n); dustRelayFee = CFeeRate(n);
} }

View file

@ -41,12 +41,12 @@ std::string ResolveErrMsg(const std::string& optname, const std::string& strBind
return strprintf(_("Cannot resolve -%s address: '%s'").translated, optname, strBind); return strprintf(_("Cannot resolve -%s address: '%s'").translated, optname, strBind);
} }
std::string AmountHighWarn(const std::string& optname) bilingual_str AmountHighWarn(const std::string& optname)
{ {
return strprintf(_("%s is set very high!").translated, optname); return strprintf(_("%s is set very high!"), optname);
} }
std::string AmountErrMsg(const std::string& optname, const std::string& strValue) bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue)
{ {
return strprintf(_("Invalid amount for -%s=<amount>: '%s'").translated, optname, strValue); return strprintf(_("Invalid amount for -%s=<amount>: '%s'"), optname, strValue);
} }

View file

@ -17,6 +17,8 @@
#include <string> #include <string>
struct bilingual_str;
enum class TransactionError { enum class TransactionError {
OK, //!< No error OK, //!< No error
MISSING_INPUTS, MISSING_INPUTS,
@ -34,8 +36,8 @@ std::string TransactionErrorString(const TransactionError error);
std::string ResolveErrMsg(const std::string& optname, const std::string& strBind); std::string ResolveErrMsg(const std::string& optname, const std::string& strBind);
std::string AmountHighWarn(const std::string& optname); bilingual_str AmountHighWarn(const std::string& optname);
std::string AmountErrMsg(const std::string& optname, const std::string& strValue); bilingual_str AmountErrMsg(const std::string& optname, const std::string& strValue);
#endif // BITCOIN_UTIL_ERROR_H #endif // BITCOIN_UTIL_ERROR_H

View file

@ -4407,11 +4407,11 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
if (gArgs.IsArgSet("-mintxfee")) { if (gArgs.IsArgSet("-mintxfee")) {
CAmount n = 0; CAmount n = 0;
if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) { if (!ParseMoney(gArgs.GetArg("-mintxfee", ""), n) || 0 == n) {
chain.initError(AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", ""))); chain.initError(AmountErrMsg("mintxfee", gArgs.GetArg("-mintxfee", "")).translated);
return nullptr; return nullptr;
} }
if (n > HIGH_TX_FEE_PER_KB) { if (n > HIGH_TX_FEE_PER_KB) {
chain.initWarning(AmountHighWarn("-mintxfee") + " " + chain.initWarning(AmountHighWarn("-mintxfee").translated + " " +
_("This is the minimum transaction fee you pay on every transaction.").translated); _("This is the minimum transaction fee you pay on every transaction.").translated);
} }
walletInstance->m_min_fee = CFeeRate(n); walletInstance->m_min_fee = CFeeRate(n);
@ -4425,7 +4425,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
return nullptr; return nullptr;
} }
if (nFeePerK > HIGH_TX_FEE_PER_KB) { if (nFeePerK > HIGH_TX_FEE_PER_KB) {
chain.initWarning(AmountHighWarn("-fallbackfee") + " " + chain.initWarning(AmountHighWarn("-fallbackfee").translated + " " +
_("This is the transaction fee you may pay when fee estimates are not available.").translated); _("This is the transaction fee you may pay when fee estimates are not available.").translated);
} }
walletInstance->m_fallback_fee = CFeeRate(nFeePerK); walletInstance->m_fallback_fee = CFeeRate(nFeePerK);
@ -4438,7 +4438,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
return nullptr; return nullptr;
} }
if (nFeePerK > HIGH_TX_FEE_PER_KB) { if (nFeePerK > HIGH_TX_FEE_PER_KB) {
chain.initWarning(AmountHighWarn("-discardfee") + " " + chain.initWarning(AmountHighWarn("-discardfee").translated + " " +
_("This is the transaction fee you may discard if change is smaller than dust at this level").translated); _("This is the transaction fee you may discard if change is smaller than dust at this level").translated);
} }
walletInstance->m_discard_rate = CFeeRate(nFeePerK); walletInstance->m_discard_rate = CFeeRate(nFeePerK);
@ -4446,11 +4446,11 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
if (gArgs.IsArgSet("-paytxfee")) { if (gArgs.IsArgSet("-paytxfee")) {
CAmount nFeePerK = 0; CAmount nFeePerK = 0;
if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) { if (!ParseMoney(gArgs.GetArg("-paytxfee", ""), nFeePerK)) {
chain.initError(AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", ""))); chain.initError(AmountErrMsg("paytxfee", gArgs.GetArg("-paytxfee", "")).translated);
return nullptr; return nullptr;
} }
if (nFeePerK > HIGH_TX_FEE_PER_KB) { if (nFeePerK > HIGH_TX_FEE_PER_KB) {
chain.initWarning(AmountHighWarn("-paytxfee") + " " + chain.initWarning(AmountHighWarn("-paytxfee").translated + " " +
_("This is the transaction fee you will pay if you send a transaction.").translated); _("This is the transaction fee you will pay if you send a transaction.").translated);
} }
walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000); walletInstance->m_pay_tx_fee = CFeeRate(nFeePerK, 1000);
@ -4465,7 +4465,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
{ {
CAmount nMaxFee = 0; CAmount nMaxFee = 0;
if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) { if (!ParseMoney(gArgs.GetArg("-maxtxfee", ""), nMaxFee)) {
chain.initError(AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", ""))); chain.initError(AmountErrMsg("maxtxfee", gArgs.GetArg("-maxtxfee", "")).translated);
return nullptr; return nullptr;
} }
if (nMaxFee > HIGH_MAX_TX_FEE) { if (nMaxFee > HIGH_MAX_TX_FEE) {
@ -4480,7 +4480,7 @@ std::shared_ptr<CWallet> CWallet::CreateWalletFromFile(interfaces::Chain& chain,
} }
if (chain.relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB) if (chain.relayMinFee().GetFeePerK() > HIGH_TX_FEE_PER_KB)
chain.initWarning(AmountHighWarn("-minrelaytxfee") + " " + chain.initWarning(AmountHighWarn("-minrelaytxfee").translated + " " +
_("The wallet will avoid paying less than the minimum relay fee.").translated); _("The wallet will avoid paying less than the minimum relay fee.").translated);
walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET); walletInstance->m_confirm_target = gArgs.GetArg("-txconfirmtarget", DEFAULT_TX_CONFIRM_TARGET);