diff --git a/src/bitcoind.cpp b/src/bitcoind.cpp --- a/src/bitcoind.cpp +++ b/src/bitcoind.cpp @@ -80,8 +80,8 @@ SetupServerArgs(); std::string error; if (!gArgs.ParseParameters(argc, argv, error)) { - return InitError( - strprintf("Error parsing command line arguments: %s\n", error)); + return InitError(Untranslated( + strprintf("Error parsing command line arguments: %s\n", error))); } // Process help and version before taking care about datadir @@ -103,13 +103,13 @@ try { if (!CheckDataDirOption()) { - return InitError( + return InitError(Untranslated( strprintf("Specified data directory \"%s\" does not exist.\n", - gArgs.GetArg("-datadir", ""))); + gArgs.GetArg("-datadir", "")))); } if (!gArgs.ReadConfigFiles(error, true)) { - return InitError( - strprintf("Error reading configuration file: %s\n", error)); + return InitError(Untranslated( + strprintf("Error reading configuration file: %s\n", error))); } // Check for -chain, -testnet or -regtest parameter (Params() calls are // only valid after this clause) @@ -117,7 +117,7 @@ SelectParams(gArgs.GetChainName()); node.chain = interfaces::MakeChain(node, config.GetChainParams()); } catch (const std::exception &e) { - return InitError(strprintf("%s\n", e.what())); + return InitError(Untranslated(strprintf("%s\n", e.what()))); } // Make sure we create the net-specific data directory early on: if it @@ -134,10 +134,10 @@ // line for (int i = 1; i < argc; i++) { if (!IsSwitchChar(argv[i][0])) { - return InitError( + return InitError(Untranslated( strprintf("Command line contains unexpected token '%s', " "see bitcoind -h for a list of options.\n", - argv[i])); + argv[i]))); } } @@ -173,15 +173,15 @@ // Daemonize if (daemon(1, 0)) { // don't chdir (1), do close FDs (0) - return InitError( - strprintf("daemon() failed: %s\n", strerror(errno))); + return InitError(Untranslated( + strprintf("daemon() failed: %s\n", strerror(errno)))); } #if defined(MAC_OSX) #pragma GCC diagnostic pop #endif #else - return InitError( - "-daemon is not supported on this operating system\n"); + return InitError(Untranslated( + "-daemon is not supported on this operating system\n")); #endif // HAVE_DECL_DAEMON } diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -112,9 +112,9 @@ #endif return true; } else { - return InitError( - strprintf(_("Unable to create the PID file '%s': %s").translated, - GetPidFile().string(), std::strerror(errno))); + return InitError(strprintf(_("Unable to create the PID file '%s': %s"), + GetPidFile().string(), + std::strerror(errno))); } } @@ -1383,9 +1383,8 @@ */ static bool InitSanityCheck() { if (!ECC_InitSanityCheck()) { - InitError( - "Elliptic curve cryptography sanity check failure. Aborting."); - return false; + return InitError(Untranslated( + "Elliptic curve cryptography sanity check failure. Aborting.")); } if (!glibcxx_sanity_test()) { @@ -1393,8 +1392,8 @@ } if (!Random_SanityCheck()) { - InitError("OS cryptographic RNG sanity check failure. Aborting."); - return false; + return InitError(Untranslated( + "OS cryptographic RNG sanity check failure. Aborting.")); } return true; @@ -1597,7 +1596,7 @@ #endif if (!SetupNetworking()) { - return InitError("Initializing networking failed"); + return InitError(Untranslated("Initializing networking failed")); } #ifndef WIN32 @@ -1636,8 +1635,7 @@ std::string network = gArgs.GetChainName(); for (const auto &arg : gArgs.GetUnsuitableSectionOnlyArgs()) { return InitError(strprintf(_("Config setting for %s only applied on %s " - "network when in [%s] section.") - .translated, + "network when in [%s] section."), arg, network, network)); } @@ -1649,9 +1647,9 @@ } if (!fs::is_directory(GetBlocksDir())) { - return InitError(strprintf( - _("Specified blocks directory \"%s\" does not exist.").translated, - gArgs.GetArg("-blocksdir", ""))); + return InitError( + strprintf(_("Specified blocks directory \"%s\" does not exist."), + gArgs.GetArg("-blocksdir", ""))); } // parse and validate enabled filter types @@ -1666,8 +1664,8 @@ for (const auto &name : names) { BlockFilterType filter_type; if (!BlockFilterTypeByName(name, filter_type)) { - return InitError(strprintf( - _("Unknown -blockfilterindex value %s.").translated, name)); + return InitError( + strprintf(_("Unknown -blockfilterindex value %s."), name)); } g_enabled_filter_types.push_back(filter_type); } @@ -1676,13 +1674,11 @@ // if using block pruning, then disallow txindex if (gArgs.GetArg("-prune", 0)) { if (gArgs.GetBoolArg("-txindex", DEFAULT_TXINDEX)) { - return InitError( - _("Prune mode is incompatible with -txindex.").translated); + return InitError(_("Prune mode is incompatible with -txindex.")); } if (!g_enabled_filter_types.empty()) { return InitError( - _("Prune mode is incompatible with -blockfilterindex.") - .translated); + _("Prune mode is incompatible with -blockfilterindex.")); } } @@ -1690,8 +1686,8 @@ size_t nUserBind = gArgs.GetArgs("-bind").size() + gArgs.GetArgs("-whitebind").size(); if (nUserBind != 0 && !gArgs.GetBoolArg("-listen", DEFAULT_LISTEN)) { - return InitError( - "Cannot set -bind or -whitebind together with -listen=0"); + return InitError(Untranslated( + "Cannot set -bind or -whitebind together with -listen=0")); } // Make sure enough file descriptors are available @@ -1716,8 +1712,7 @@ MAX_ADDNODE_CONNECTIONS), 0); if (nFD < MIN_CORE_FILEDESCRIPTORS) { - return InitError( - _("Not enough file descriptors available.").translated); + return InitError(_("Not enough file descriptors available.")); } nMaxConnections = std::min(nFD - MIN_CORE_FILEDESCRIPTORS - MAX_ADDNODE_CONNECTIONS, @@ -1792,7 +1787,8 @@ gArgs.GetArg("-minimumchainwork", ""); if (!IsHexNumber(minChainWorkStr)) { return InitError(strprintf( - "Invalid non-hex (%s) minimum chain work value specified", + Untranslated( + "Invalid non-hex (%s) minimum chain work value specified"), minChainWorkStr)); } nMinimumChainWork = UintToArith256(uint256S(minChainWorkStr)); @@ -1814,9 +1810,8 @@ gArgs.GetArg("-limitdescendantsize", DEFAULT_DESCENDANT_SIZE_LIMIT) * 1000 * 40; if (nMempoolSizeMax < 0 || nMempoolSizeMax < nMempoolSizeMin) { - return InitError( - strprintf(_("-maxmempool must be at least %d MB").translated, - std::ceil(nMempoolSizeMin / 1000000.0))); + return InitError(strprintf(_("-maxmempool must be at least %d MB"), + std::ceil(nMempoolSizeMin / 1000000.0))); } // Configure excessive block size. @@ -1824,8 +1819,7 @@ gArgs.GetArg("-excessiveblocksize", DEFAULT_MAX_BLOCK_SIZE); if (!config.SetMaxBlockSize(nProposedExcessiveBlockSize)) { return InitError( - _("Excessive block size must be > 1,000,000 bytes (1MB)") - .translated); + _("Excessive block size must be > 1,000,000 bytes (1MB)")); } // Check blockmaxsize does not exceed maximum accepted block size. @@ -1833,8 +1827,7 @@ gArgs.GetArg("-blockmaxsize", DEFAULT_MAX_GENERATED_BLOCK_SIZE); if (nProposedMaxGeneratedBlockSize > config.GetMaxBlockSize()) { auto msg = _("Max generated block size (blockmaxsize) cannot exceed " - "the excessive block size (excessiveblocksize)") - .translated; + "the excessive block size (excessiveblocksize)"); return InitError(msg); } @@ -1843,7 +1836,7 @@ int64_t nPruneArg = gArgs.GetArg("-prune", 0); if (nPruneArg < 0) { return InitError( - _("Prune cannot be configured with a negative value.").translated); + _("Prune cannot be configured with a negative value.")); } nPruneTarget = (uint64_t)nPruneArg * 1024 * 1024; if (nPruneArg == 1) { @@ -1857,8 +1850,7 @@ if (nPruneTarget < MIN_DISK_SPACE_FOR_BLOCK_FILES) { return InitError( strprintf(_("Prune configured below the minimum of %d MiB. " - "Please use a higher number.") - .translated, + "Please use a higher number."), MIN_DISK_SPACE_FOR_BLOCK_FILES / 1024 / 1024)); } LogPrintf("Prune configured to target %u MiB on disk for block and " @@ -1875,8 +1867,8 @@ peer_connect_timeout = gArgs.GetArg("-peertimeout", DEFAULT_PEER_CONNECT_TIMEOUT); if (peer_connect_timeout <= 0) { - return InitError( - "peertimeout cannot be configured with a negative value."); + return InitError(Untranslated( + "peertimeout cannot be configured with a negative value.")); } // Obtain the amount to charge excess UTXO @@ -1884,9 +1876,8 @@ Amount n = Amount::zero(); auto parsed = ParseMoney(gArgs.GetArg("-excessutxocharge", ""), n); if (!parsed || Amount::zero() > n) { - return InitError(AmountErrMsg("excessutxocharge", - gArgs.GetArg("-excessutxocharge", "")) - .translated); + return InitError(AmountErrMsg( + "excessutxocharge", gArgs.GetArg("-excessutxocharge", ""))); } config.SetExcessUTXOCharge(n); } else { @@ -1898,8 +1889,7 @@ auto parsed = ParseMoney(gArgs.GetArg("-minrelaytxfee", ""), n); if (!parsed || n == Amount::zero()) { return InitError(AmountErrMsg("minrelaytxfee", - gArgs.GetArg("-minrelaytxfee", "")) - .translated); + gArgs.GetArg("-minrelaytxfee", ""))); } // High fee check is done afterward in CWallet::CreateWalletFromFile() ::minRelayTxFee = CFeeRate(n); @@ -1912,8 +1902,7 @@ Amount n = Amount::zero(); if (!ParseMoney(gArgs.GetArg("-blockmintxfee", ""), n)) { return InitError(AmountErrMsg("blockmintxfee", - gArgs.GetArg("-blockmintxfee", "")) - .translated); + gArgs.GetArg("-blockmintxfee", ""))); } } @@ -1923,9 +1912,8 @@ Amount n = Amount::zero(); auto parsed = ParseMoney(gArgs.GetArg("-dustrelayfee", ""), n); if (!parsed || Amount::zero() == n) { - return InitError( - AmountErrMsg("dustrelayfee", gArgs.GetArg("-dustrelayfee", "")) - .translated); + return InitError(AmountErrMsg("dustrelayfee", + gArgs.GetArg("-dustrelayfee", ""))); } dustRelayFee = CFeeRate(n); } @@ -1933,9 +1921,10 @@ fRequireStandard = !gArgs.GetBoolArg("-acceptnonstdtxn", !chainparams.RequireStandard()); if (!chainparams.IsTestChain() && !fRequireStandard) { - return InitError( - strprintf("acceptnonstdtxn is not currently supported for %s chain", - chainparams.NetworkIDString())); + return InitError(strprintf( + Untranslated( + "acceptnonstdtxn is not currently supported for %s chain"), + chainparams.NetworkIDString())); } nBytesPerSigOp = gArgs.GetArg("-bytespersigop", nBytesPerSigOp); @@ -1970,14 +1959,12 @@ fs::path datadir = GetDataDir(); if (!DirIsWritable(datadir)) { return InitError(strprintf( - _("Cannot write to data directory '%s'; check permissions.") - .translated, + _("Cannot write to data directory '%s'; check permissions."), datadir.string())); } if (!LockDirectory(datadir, ".lock", probeOnly)) { return InitError(strprintf(_("Cannot obtain a lock on data directory " - "%s. %s is probably already running.") - .translated, + "%s. %s is probably already running."), datadir.string(), PACKAGE_NAME)); } return true; @@ -1996,8 +1983,7 @@ // Sanity check if (!InitSanityCheck()) { return InitError(strprintf( - _("Initialization sanity check failed. %s is shutting down.") - .translated, + _("Initialization sanity check failed. %s is shutting down."), PACKAGE_NAME)); } @@ -2042,8 +2028,9 @@ } if (!logger.StartLogging()) { - return InitError(strprintf("Could not open debug log file %s", - logger.m_file_path.string())); + return InitError( + strprintf(Untranslated("Could not open debug log file %s"), + logger.m_file_path.string())); } if (!logger.m_log_timestamps) { @@ -2162,8 +2149,7 @@ uiInterface.InitMessage_connect(SetRPCWarmupStatus); if (!AppInitServers(config, httpRPCRequestProcessor)) { return InitError( - _("Unable to start HTTP server. See debug log for details.") - .translated); + _("Unable to start HTTP server. See debug log for details.")); } } @@ -2199,9 +2185,7 @@ for (const std::string &cmt : gArgs.GetArgs("-uacomment")) { if (cmt != SanitizeString(cmt, SAFE_CHARS_UA_COMMENT)) { return InitError(strprintf( - _("User Agent comment (%s) contains unsafe characters.") - .translated, - cmt)); + _("User Agent comment (%s) contains unsafe characters."), cmt)); } uacomments.push_back(cmt); } @@ -2210,8 +2194,7 @@ if (strSubVersion.size() > MAX_SUBVERSION_LENGTH) { return InitError(strprintf( _("Total length of network version string (%i) exceeds maximum " - "length (%i). Reduce the number or size of uacomments.") - .translated, + "length (%i). Reduce the number or size of uacomments."), strSubVersion.size(), MAX_SUBVERSION_LENGTH)); } @@ -2221,8 +2204,7 @@ enum Network net = ParseNetwork(snet); if (net == NET_UNROUTABLE) { return InitError(strprintf( - _("Unknown network specified in -onlynet: '%s'").translated, - snet)); + _("Unknown network specified in -onlynet: '%s'"), snet)); } nets.insert(net); } @@ -2249,15 +2231,13 @@ CService proxyAddr; if (!Lookup(proxyArg.c_str(), proxyAddr, 9050, fNameLookup)) { return InitError(strprintf( - _("Invalid -proxy address or hostname: '%s'").translated, - proxyArg)); + _("Invalid -proxy address or hostname: '%s'"), proxyArg)); } proxyType addrProxy = proxyType(proxyAddr, proxyRandomize); if (!addrProxy.IsValid()) { return InitError(strprintf( - _("Invalid -proxy address or hostname: '%s'").translated, - proxyArg)); + _("Invalid -proxy address or hostname: '%s'"), proxyArg)); } SetProxy(NET_IPV4, addrProxy); @@ -2282,14 +2262,12 @@ CService onionProxy; if (!Lookup(onionArg.c_str(), onionProxy, 9050, fNameLookup)) { return InitError(strprintf( - _("Invalid -onion address or hostname: '%s'").translated, - onionArg)); + _("Invalid -onion address or hostname: '%s'"), onionArg)); } proxyType addrOnion = proxyType(onionProxy, proxyRandomize); if (!addrOnion.IsValid()) { return InitError(strprintf( - _("Invalid -onion address or hostname: '%s'").translated, - onionArg)); + _("Invalid -onion address or hostname: '%s'"), onionArg)); } SetProxy(NET_ONION, addrOnion); SetReachable(NET_ONION, true); @@ -2307,7 +2285,8 @@ addrLocal.IsValid()) { AddLocal(addrLocal, LOCAL_MANUAL); } else { - return InitError(ResolveErrMsg("externalip", strAddr)); + return InitError( + Untranslated(ResolveErrMsg("externalip", strAddr))); } } @@ -2442,8 +2421,7 @@ if (!::BlockIndex().empty() && !LookupBlockIndex(params.hashGenesisBlock)) { return InitError(_("Incorrect or no genesis block found. " - "Wrong datadir for network?") - .translated); + "Wrong datadir for network?")); } // Check for changed -prune state. What we are concerned about @@ -2581,7 +2559,7 @@ return false; } } else { - return InitError(strLoadError.translated); + return InitError(strLoadError); } } } @@ -2639,13 +2617,13 @@ // Step 11: import blocks if (!CheckDiskSpace(GetDataDir())) { - InitError(strprintf(_("Error: Disk space is low for %s").translated, - GetDataDir())); + InitError( + strprintf(_("Error: Disk space is low for %s"), GetDataDir())); return false; } if (!CheckDiskSpace(GetBlocksDir())) { - InitError(strprintf(_("Error: Disk space is low for %s").translated, - GetBlocksDir())); + InitError( + strprintf(_("Error: Disk space is low for %s"), GetBlocksDir())); return false; } @@ -2740,7 +2718,7 @@ for (const std::string &strBind : gArgs.GetArgs("-bind")) { CService addrBind; if (!Lookup(strBind.c_str(), addrBind, GetListenPort(), false)) { - return InitError(ResolveErrMsg("bind", strBind)); + return InitError(Untranslated(ResolveErrMsg("bind", strBind))); } connOptions.vBinds.push_back(addrBind); } @@ -2749,7 +2727,7 @@ NetWhitebindPermissions whitebind; std::string error; if (!NetWhitebindPermissions::TryParse(strBind, whitebind, error)) { - return InitError(error); + return InitError(Untranslated(error)); } connOptions.vWhiteBinds.push_back(whitebind); } @@ -2758,7 +2736,7 @@ NetWhitelistPermissions subnet; std::string error; if (!NetWhitelistPermissions::TryParse(net, subnet, error)) { - return InitError(error); + return InitError(Untranslated(error)); } connOptions.vWhitelistedRange.push_back(subnet); } diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -24,6 +24,7 @@ class TxValidationState; struct BlockHash; +struct bilingual_str; struct CBlockLocator; struct NodeContext; @@ -256,7 +257,7 @@ virtual void initWarning(const std::string &message) = 0; //! Send init error. - virtual void initError(const std::string &message) = 0; + virtual void initError(const bilingual_str &message) = 0; //! Send progress indicator. virtual void showProgress(const std::string &title, int progress, diff --git a/src/interfaces/chain.cpp b/src/interfaces/chain.cpp --- a/src/interfaces/chain.cpp +++ b/src/interfaces/chain.cpp @@ -398,7 +398,7 @@ void initWarning(const std::string &message) override { InitWarning(message); } - void initError(const std::string &message) override { + void initError(const bilingual_str &message) override { InitError(message); } void showProgress(const std::string &title, int progress, diff --git a/src/interfaces/node.cpp b/src/interfaces/node.cpp --- a/src/interfaces/node.cpp +++ b/src/interfaces/node.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -64,7 +65,7 @@ class NodeImpl : public Node { public: void initError(const std::string &message) override { - InitError(message); + InitError(Untranslated(message)); } bool parseParameters(int argc, const char *const argv[], std::string &error) override { diff --git a/src/ui_interface.h b/src/ui_interface.h --- a/src/ui_interface.h +++ b/src/ui_interface.h @@ -137,10 +137,11 @@ }; /** Show warning message **/ +// TODO: InitWarning() should take a bilingual_str parameter. void InitWarning(const std::string &str); /** Show error message **/ -bool InitError(const std::string &str); +bool InitError(const bilingual_str &str); extern CClientUIInterface uiInterface; diff --git a/src/ui_interface.cpp b/src/ui_interface.cpp --- a/src/ui_interface.cpp +++ b/src/ui_interface.cpp @@ -89,9 +89,8 @@ return g_ui_signals.BannedListChanged(); } -bool InitError(const std::string &str) { - uiInterface.ThreadSafeMessageBox(Untranslated(str), "", - CClientUIInterface::MSG_ERROR); +bool InitError(const bilingual_str &str) { + uiInterface.ThreadSafeMessageBox(str, "", CClientUIInterface::MSG_ERROR); return false; } diff --git a/src/wallet/init.cpp b/src/wallet/init.cpp --- a/src/wallet/init.cpp +++ b/src/wallet/init.cpp @@ -181,9 +181,9 @@ if (gArgs.GetBoolArg("-salvagewallet", false)) { if (is_multiwallet) { - return InitError( - strprintf("%s is only allowed with a single wallet file", - "-salvagewallet")); + return InitError(strprintf( + Untranslated("%s is only allowed with a single wallet file"), + "-salvagewallet")); } // Rewrite just private keys: rescan to find transactions if (gArgs.SoftSetBoolArg("-rescan", true)) { @@ -204,9 +204,9 @@ // -zapwallettxes implies a rescan if (zapwallettxes) { if (is_multiwallet) { - return InitError( - strprintf("%s is only allowed with a single wallet file", - "-zapwallettxes")); + return InitError(strprintf( + Untranslated("%s is only allowed with a single wallet file"), + "-zapwallettxes")); } if (gArgs.SoftSetBoolArg("-rescan", true)) { LogPrintf("%s: parameter interaction: -zapwallettxes enabled -> " @@ -216,8 +216,9 @@ } if (gArgs.GetBoolArg("-sysperms", false)) { - return InitError("-sysperms is not allowed in combination with enabled " - "wallet functionality"); + return InitError( + Untranslated("-sysperms is not allowed in combination with enabled " + "wallet functionality")); } return true; diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp --- a/src/wallet/load.cpp +++ b/src/wallet/load.cpp @@ -21,21 +21,21 @@ // environment instances for the same directory fs::path canonical_wallet_dir = fs::canonical(wallet_dir, error); if (error || !fs::exists(wallet_dir)) { - chain.initError(strprintf( - _("Specified -walletdir \"%s\" does not exist").translated, - wallet_dir.string())); + chain.initError( + strprintf(_("Specified -walletdir \"%s\" does not exist"), + wallet_dir.string())); return false; } else if (!fs::is_directory(wallet_dir)) { - chain.initError(strprintf( - _("Specified -walletdir \"%s\" is not a directory").translated, - wallet_dir.string())); + chain.initError( + strprintf(_("Specified -walletdir \"%s\" is not a directory"), + wallet_dir.string())); return false; // The canonical path transforms relative paths into absolute ones, // so we check the non-canonical version } else if (!wallet_dir.is_absolute()) { - chain.initError(strprintf( - _("Specified -walletdir \"%s\" is a relative path").translated, - wallet_dir.string())); + chain.initError( + strprintf(_("Specified -walletdir \"%s\" is a relative path"), + wallet_dir.string())); return false; } gArgs.ForceSetArg("-walletdir", canonical_wallet_dir.string()); @@ -59,8 +59,7 @@ if (!wallet_paths.insert(location.GetPath()).second) { chain.initError(strprintf(_("Error loading wallet %s. Duplicate " - "-wallet filename specified.") - .translated, + "-wallet filename specified."), wallet_file)); return false; } @@ -74,7 +73,7 @@ chain.initWarning(Join(warnings, "\n", OpTranslated)); } if (!verify_success) { - chain.initError(error_string.translated); + chain.initError(error_string); return false; } } @@ -93,7 +92,7 @@ chain.initWarning(Join(warnings, "\n", OpTranslated)); } if (!pwallet) { - chain.initError(error.translated); + chain.initError(error); return false; } AddWallet(pwallet);