diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index a1d76e18..c99b74f1 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -757,7 +757,7 @@ void StartRPCThreads() rpc_io_service = new asio::io_service(); rpc_ssl_context = new ssl::context(*rpc_io_service, ssl::context::sslv23); - const bool fUseSSL = GetBoolArg("-rpcssl"); + const bool fUseSSL = GetBoolArg("-rpcssl", false); if (fUseSSL) { @@ -1037,7 +1037,7 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s // Observe safe mode string strWarning = GetWarnings("rpc"); - if (strWarning != "" && !GetBoolArg("-disablesafemode") && + if (strWarning != "" && !GetBoolArg("-disablesafemode", false) && !pcmd->okSafeMode) throw JSONRPCError(RPC_FORBIDDEN_BY_SAFE_MODE, string("Safe mode: ") + strWarning); @@ -1071,7 +1071,7 @@ Object CallRPC(const string& strMethod, const Array& params) GetConfigFile().string().c_str())); // Connect to localhost - bool fUseSSL = GetBoolArg("-rpcssl"); + bool fUseSSL = GetBoolArg("-rpcssl", false); asio::io_service io_service; ssl::context context(io_service, ssl::context::sslv23); context.set_options(ssl::context::no_sslv2); diff --git a/src/init.cpp b/src/init.cpp index 226e93e9..78f838f7 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -198,7 +198,7 @@ bool AppInit(int argc, char* argv[]) exit(ret); } #if !defined(WIN32) - fDaemon = GetBoolArg("-daemon"); + fDaemon = GetBoolArg("-daemon", false); if (fDaemon) { // Daemonize @@ -495,7 +495,7 @@ bool AppInit2(boost::thread_group& threadGroup) // ********************************************************* Step 2: parameter interactions - fTestNet = GetBoolArg("-testnet"); + fTestNet = GetBoolArg("-testnet", false); Checkpoints::fEnabled = GetBoolArg("-checkpoints", true); if (mapArgs.count("-bind")) { @@ -526,7 +526,7 @@ bool AppInit2(boost::thread_group& threadGroup) SoftSetBoolArg("-discover", false); } - if (GetBoolArg("-salvagewallet")) { + if (GetBoolArg("-salvagewallet", false)) { // Rewrite just private keys: rescan to find transactions SoftSetBoolArg("-rescan", true); } @@ -543,8 +543,8 @@ bool AppInit2(boost::thread_group& threadGroup) // ********************************************************* Step 3: parameter-to-internal-flags - fDebug = GetBoolArg("-debug"); - fBenchmark = GetBoolArg("-benchmark"); + fDebug = GetBoolArg("-debug", false); + fBenchmark = GetBoolArg("-benchmark", false); // -par=0 means autodetect, but nScriptCheckThreads==0 means no concurrency nScriptCheckThreads = GetArg("-par", 0); @@ -559,20 +559,20 @@ bool AppInit2(boost::thread_group& threadGroup) if (fDebug) fDebugNet = true; else - fDebugNet = GetBoolArg("-debugnet"); + fDebugNet = GetBoolArg("-debugnet", false); if (fDaemon) fServer = true; else - fServer = GetBoolArg("-server"); + fServer = GetBoolArg("-server", false); /* force fServer when running without GUI */ #if !defined(QT_GUI) fServer = true; #endif - fPrintToConsole = GetBoolArg("-printtoconsole"); - fPrintToDebugger = GetBoolArg("-printtodebugger"); - fLogTimestamps = GetBoolArg("-logtimestamps"); + fPrintToConsole = GetBoolArg("-printtoconsole", false); + fPrintToDebugger = GetBoolArg("-printtodebugger", false); + fLogTimestamps = GetBoolArg("-logtimestamps", false); if (mapArgs.count("-timeout")) { @@ -677,7 +677,7 @@ bool AppInit2(boost::thread_group& threadGroup) } } - if (GetBoolArg("-salvagewallet")) + if (GetBoolArg("-salvagewallet", false)) { // Recover readable keypairs: if (!CWalletDB::Recover(bitdb, "wallet.dat", true)) @@ -799,7 +799,7 @@ bool AppInit2(boost::thread_group& threadGroup) // ********************************************************* Step 7: load block chain - fReindex = GetBoolArg("-reindex"); + fReindex = GetBoolArg("-reindex", false); // Upgrading to 0.8; hard-link the old blknnnn.dat files into /blocks/ filesystem::path blocksDir = GetDataDir() / "blocks"; @@ -922,7 +922,7 @@ bool AppInit2(boost::thread_group& threadGroup) } printf(" block index %15"PRI64d"ms\n", GetTimeMillis() - nStart); - if (GetBoolArg("-printblockindex") || GetBoolArg("-printblocktree")) + if (GetBoolArg("-printblockindex", false) || GetBoolArg("-printblocktree", false)) { PrintBlockTree(); return false; @@ -1018,7 +1018,7 @@ bool AppInit2(boost::thread_group& threadGroup) RegisterWallet(pwalletMain); CBlockIndex *pindexRescan = pindexBest; - if (GetBoolArg("-rescan")) + if (GetBoolArg("-rescan", false)) pindexRescan = pindexGenesisBlock; else { diff --git a/src/main.cpp b/src/main.cpp index 24e1c233..a98b83b6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2931,7 +2931,7 @@ string GetWarnings(string strFor) string strStatusBar; string strRPC; - if (GetBoolArg("-testsafemode")) + if (GetBoolArg("-testsafemode", false)) strRPC = "test"; if (!CLIENT_VERSION_IS_RELEASE) @@ -4175,7 +4175,7 @@ CBlockTemplate* CreateNewBlock(CReserveKey& reservekey) // Priority order to process transactions list vOrphan; // list memory doesn't move map > mapDependers; - bool fPrintPriority = GetBoolArg("-printpriority"); + bool fPrintPriority = GetBoolArg("-printpriority", false); // This vector will be sorted into a priority queue: vector vecPriority; diff --git a/src/qt/bitcoin.cpp b/src/qt/bitcoin.cpp index 354c5af4..b858e1c1 100644 --- a/src/qt/bitcoin.cpp +++ b/src/qt/bitcoin.cpp @@ -15,6 +15,9 @@ #include "ui_interface.h" #include "paymentserver.h" #include "splashscreen.h" +#ifdef Q_OS_MAC +#include "macdockiconhandler.h" +#endif #include #if QT_VERSION < 0x050000 @@ -25,10 +28,6 @@ #include #include -#ifdef Q_OS_MAC -#include "macdockiconhandler.h" -#endif - #if defined(BITCOIN_NEED_QT_PLUGINS) && !defined(_BITCOIN_QT_PLUGINS_INCLUDED) #define _BITCOIN_QT_PLUGINS_INCLUDED #define __INSURE__ @@ -156,7 +155,7 @@ int main(int argc, char *argv[]) // as it is used to locate QSettings) QApplication::setOrganizationName("Bitcoin"); QApplication::setOrganizationDomain("bitcoin.org"); - if(GetBoolArg("-testnet")) // Separate UI settings for testnet + if (GetBoolArg("-testnet", false)) // Separate UI settings for testnet QApplication::setApplicationName("Bitcoin-Qt-testnet"); else QApplication::setApplicationName("Bitcoin-Qt"); @@ -208,13 +207,14 @@ int main(int argc, char *argv[]) #ifdef Q_OS_MAC // on mac, also change the icon now because it would look strange to have a testnet splash (green) and a std app icon (orange) - if(GetBoolArg("-testnet")) { + if(GetBoolArg("-testnet", false)) + { MacDockIconHandler::instance()->setIcon(QIcon(":icons/bitcoin_testnet")); } #endif SplashScreen splash(QPixmap(), 0); - if (GetBoolArg("-splash", true) && !GetBoolArg("-min")) + if (GetBoolArg("-splash", true) && !GetBoolArg("-min", false)) { splash.show(); splash.setAutoFillBackground(true); @@ -258,7 +258,7 @@ int main(int argc, char *argv[]) window.setCurrentWallet("~Default"); // If -min option passed, start window minimized. - if(GetBoolArg("-min")) + if(GetBoolArg("-min", false)) { window.showMinimized(); } diff --git a/src/qt/splashscreen.cpp b/src/qt/splashscreen.cpp index 95948a6c..e4002781 100644 --- a/src/qt/splashscreen.cpp +++ b/src/qt/splashscreen.cpp @@ -27,7 +27,7 @@ SplashScreen::SplashScreen(const QPixmap &pixmap, Qt::WindowFlags f) : // load the bitmap for writing some text over it QPixmap newPixmap; - if(GetBoolArg("-testnet")) { + if(GetBoolArg("-testnet", false)) { newPixmap = QPixmap(":/images/splash_testnet"); } else { diff --git a/src/rpcmining.cpp b/src/rpcmining.cpp index 845e7f1f..d2cac687 100644 --- a/src/rpcmining.cpp +++ b/src/rpcmining.cpp @@ -33,7 +33,7 @@ Value getgenerate(const Array& params, bool fHelp) "getgenerate\n" "Returns true or false."); - return GetBoolArg("-gen"); + return GetBoolArg("-gen", false); } @@ -84,16 +84,16 @@ Value getmininginfo(const Array& params, bool fHelp) "Returns an object containing mining-related information."); Object obj; - obj.push_back(Pair("blocks", (int)nBestHeight)); - obj.push_back(Pair("currentblocksize",(uint64_t)nLastBlockSize)); - obj.push_back(Pair("currentblocktx",(uint64_t)nLastBlockTx)); - obj.push_back(Pair("difficulty", (double)GetDifficulty())); - obj.push_back(Pair("errors", GetWarnings("statusbar"))); - obj.push_back(Pair("generate", GetBoolArg("-gen"))); - obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); - obj.push_back(Pair("hashespersec", gethashespersec(params, false))); - obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); - obj.push_back(Pair("testnet", fTestNet)); + obj.push_back(Pair("blocks", (int)nBestHeight)); + obj.push_back(Pair("currentblocksize", (uint64_t)nLastBlockSize)); + obj.push_back(Pair("currentblocktx", (uint64_t)nLastBlockTx)); + obj.push_back(Pair("difficulty", (double)GetDifficulty())); + obj.push_back(Pair("errors", GetWarnings("statusbar"))); + obj.push_back(Pair("generate", GetBoolArg("-gen", false))); + obj.push_back(Pair("genproclimit", (int)GetArg("-genproclimit", -1))); + obj.push_back(Pair("hashespersec", gethashespersec(params, false))); + obj.push_back(Pair("pooledtx", (uint64_t)mempool.size())); + obj.push_back(Pair("testnet", fTestNet)); return obj; } diff --git a/src/test/getarg_tests.cpp b/src/test/getarg_tests.cpp index 78953d29..c89d218f 100644 --- a/src/test/getarg_tests.cpp +++ b/src/test/getarg_tests.cpp @@ -6,8 +6,7 @@ BOOST_AUTO_TEST_SUITE(getarg_tests) -static void -ResetArgs(const std::string& strArg) +static void ResetArgs(const std::string& strArg) { std::vector vecArg; boost::split(vecArg, strArg, boost::is_space(), boost::token_compress_on); @@ -26,62 +25,50 @@ ResetArgs(const std::string& strArg) BOOST_AUTO_TEST_CASE(boolarg) { ResetArgs("-foo"); - BOOST_CHECK(GetBoolArg("-foo")); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); - BOOST_CHECK(!GetBoolArg("-fo")); BOOST_CHECK(!GetBoolArg("-fo", false)); BOOST_CHECK(GetBoolArg("-fo", true)); - BOOST_CHECK(!GetBoolArg("-fooo")); BOOST_CHECK(!GetBoolArg("-fooo", false)); BOOST_CHECK(GetBoolArg("-fooo", true)); ResetArgs("-foo=0"); - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo=1"); - BOOST_CHECK(GetBoolArg("-foo")); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); // New 0.6 feature: auto-map -nosomething to !-something: ResetArgs("-nofoo"); - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-nofoo=1"); - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); ResetArgs("-foo -nofoo"); // -foo should win - BOOST_CHECK(GetBoolArg("-foo")); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); ResetArgs("-foo=1 -nofoo=1"); // -foo should win - BOOST_CHECK(GetBoolArg("-foo")); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); ResetArgs("-foo=0 -nofoo=0"); // -foo should win - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); // New 0.6 feature: treat -- same as -: ResetArgs("--foo=1"); - BOOST_CHECK(GetBoolArg("-foo")); BOOST_CHECK(GetBoolArg("-foo", false)); BOOST_CHECK(GetBoolArg("-foo", true)); ResetArgs("--nofoo=1"); - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", false)); BOOST_CHECK(!GetBoolArg("-foo", true)); @@ -133,7 +120,7 @@ BOOST_AUTO_TEST_CASE(intarg) BOOST_AUTO_TEST_CASE(doubledash) { ResetArgs("--foo"); - BOOST_CHECK_EQUAL(GetBoolArg("-foo"), true); + BOOST_CHECK_EQUAL(GetBoolArg("-foo", false), true); ResetArgs("--foo=verbose --bar=1"); BOOST_CHECK_EQUAL(GetArg("-foo", ""), "verbose"); @@ -143,25 +130,24 @@ BOOST_AUTO_TEST_CASE(doubledash) BOOST_AUTO_TEST_CASE(boolargno) { ResetArgs("-nofoo"); - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo=1"); - BOOST_CHECK(!GetBoolArg("-foo")); BOOST_CHECK(!GetBoolArg("-foo", true)); BOOST_CHECK(!GetBoolArg("-foo", false)); ResetArgs("-nofoo=0"); - BOOST_CHECK(GetBoolArg("-foo")); BOOST_CHECK(GetBoolArg("-foo", true)); BOOST_CHECK(GetBoolArg("-foo", false)); ResetArgs("-foo --nofoo"); - BOOST_CHECK(GetBoolArg("-foo")); + BOOST_CHECK(GetBoolArg("-foo", true)); + BOOST_CHECK(GetBoolArg("-foo", false)); ResetArgs("-nofoo -foo"); // foo always wins: - BOOST_CHECK(GetBoolArg("-foo")); + BOOST_CHECK(GetBoolArg("-foo", true)); + BOOST_CHECK(GetBoolArg("-foo", false)); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/util_tests.cpp b/src/test/util_tests.cpp index 1b0ccad5..64bd3a1b 100644 --- a/src/test/util_tests.cpp +++ b/src/test/util_tests.cpp @@ -31,7 +31,7 @@ BOOST_AUTO_TEST_CASE(util_criticalsection) } BOOST_AUTO_TEST_CASE(util_MedianFilter) -{ +{ CMedianFilter filter(5, 15); BOOST_CHECK_EQUAL(filter.median(), 15); @@ -56,10 +56,10 @@ BOOST_AUTO_TEST_CASE(util_MedianFilter) } static const unsigned char ParseHex_expected[65] = { - 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, - 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, - 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, - 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, + 0x04, 0x67, 0x8a, 0xfd, 0xb0, 0xfe, 0x55, 0x48, 0x27, 0x19, 0x67, 0xf1, 0xa6, 0x71, 0x30, 0xb7, + 0x10, 0x5c, 0xd6, 0xa8, 0x28, 0xe0, 0x39, 0x09, 0xa6, 0x79, 0x62, 0xe0, 0xea, 0x1f, 0x61, 0xde, + 0xb6, 0x49, 0xf6, 0xbc, 0x3f, 0x4c, 0xef, 0x38, 0xc4, 0xf3, 0x55, 0x04, 0xe5, 0x1e, 0xc1, 0x12, + 0xde, 0x5c, 0x38, 0x4d, 0xf7, 0xba, 0x0b, 0x8d, 0x57, 0x8a, 0x4c, 0x70, 0x2b, 0x6b, 0xf1, 0x1d, 0x5f }; BOOST_AUTO_TEST_CASE(util_ParseHex) @@ -123,13 +123,13 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters) BOOST_CHECK(mapArgs.empty() && mapMultiArgs.empty()); ParseParameters(5, (char**)argv_test); - // expectation: -ignored is ignored (program name argument), + // expectation: -ignored is ignored (program name argument), // -a, -b and -ccc end up in map, -d ignored because it is after // a non-option argument (non-GNU option parsing) BOOST_CHECK(mapArgs.size() == 3 && mapMultiArgs.size() == 3); - BOOST_CHECK(mapArgs.count("-a") && mapArgs.count("-b") && mapArgs.count("-ccc") + BOOST_CHECK(mapArgs.count("-a") && mapArgs.count("-b") && mapArgs.count("-ccc") && !mapArgs.count("f") && !mapArgs.count("-d")); - BOOST_CHECK(mapMultiArgs.count("-a") && mapMultiArgs.count("-b") && mapMultiArgs.count("-ccc") + BOOST_CHECK(mapMultiArgs.count("-a") && mapMultiArgs.count("-b") && mapMultiArgs.count("-ccc") && !mapMultiArgs.count("f") && !mapMultiArgs.count("-d")); BOOST_CHECK(mapArgs["-a"] == "" && mapArgs["-ccc"] == "multiple"); @@ -154,10 +154,10 @@ BOOST_AUTO_TEST_CASE(util_GetArg) BOOST_CHECK_EQUAL(GetArg("inttest1", -1), 12345); BOOST_CHECK_EQUAL(GetArg("inttest2", -1), 81985529216486895LL); BOOST_CHECK_EQUAL(GetArg("inttest3", -1), -1); - BOOST_CHECK_EQUAL(GetBoolArg("booltest1"), true); - BOOST_CHECK_EQUAL(GetBoolArg("booltest2"), false); - BOOST_CHECK_EQUAL(GetBoolArg("booltest3"), false); - BOOST_CHECK_EQUAL(GetBoolArg("booltest4"), true); + BOOST_CHECK_EQUAL(GetBoolArg("booltest1", false), true); + BOOST_CHECK_EQUAL(GetBoolArg("booltest2", false), false); + BOOST_CHECK_EQUAL(GetBoolArg("booltest3", false), false); + BOOST_CHECK_EQUAL(GetBoolArg("booltest4", false), true); } BOOST_AUTO_TEST_CASE(util_WildcardMatch) diff --git a/src/util.cpp b/src/util.cpp index 4c9b897f..0bd29602 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -518,7 +518,7 @@ static void InterpretNegativeSetting(string name, map& mapSettin positive.append(name.begin()+3, name.end()); if (mapSettingsRet.count(positive) == 0) { - bool value = !GetBoolArg(name); + bool value = !GetBoolArg(name, false); mapSettingsRet[positive] = (value ? "1" : "0"); } } @@ -1171,7 +1171,6 @@ bool TruncateFile(FILE *file, unsigned int length) { #endif } - // this function tries to raise the file descriptor limit to the requested number. // It returns the actual file descriptor limit (which may be more or less than nMinFD) int RaiseFileDescriptorLimit(int nMinFD) { @@ -1257,8 +1256,8 @@ void ShrinkDebugFile() fclose(file); } } - else if(file != NULL) - fclose(file); + else if (file != NULL) + fclose(file); } diff --git a/src/util.h b/src/util.h index d9ad74f6..941e0d99 100644 --- a/src/util.h +++ b/src/util.h @@ -390,7 +390,7 @@ int64 GetArg(const std::string& strArg, int64 nDefault); * @param default (true or false) * @return command-line argument or default value */ -bool GetBoolArg(const std::string& strArg, bool fDefault=false); +bool GetBoolArg(const std::string& strArg, bool fDefault); /** * Set an argument if it doesn't already have a value