Skip to content

Commit 0cf86a6

Browse files
committed
Introduce (and use) an IsArgSet accessor method
1 parent 2b5f085 commit 0cf86a6

File tree

12 files changed

+44
-31
lines changed

12 files changed

+44
-31
lines changed

src/bitcoin-cli.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ static int AppInitRPC(int argc, char* argv[])
7676
// Parameters
7777
//
7878
ParseParameters(argc, argv);
79-
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version")) {
79+
if (argc<2 || IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version")) {
8080
std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
81-
if (!mapArgs.count("-version")) {
81+
if (!IsArgSet("-version")) {
8282
strUsage += "\n" + _("Usage:") + "\n" +
8383
" bitcoin-cli [options] <command> [params] " + strprintf(_("Send command to %s"), _(PACKAGE_NAME)) + "\n" +
8484
" bitcoin-cli [options] help " + _("List commands") + "\n" +

src/bitcoin-tx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ static int AppInitRawTx(int argc, char* argv[])
5151

5252
fCreateBlank = GetBoolArg("-create", false);
5353

54-
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help"))
54+
if (argc<2 || IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help"))
5555
{
5656
// First part of help message is specific to this utility
5757
std::string strUsage = strprintf(_("%s bitcoin-tx utility version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n\n" +

src/bitcoind.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ bool AppInit(int argc, char* argv[])
7575
ParseParameters(argc, argv);
7676

7777
// Process help and version before taking care about datadir
78-
if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
78+
if (IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version"))
7979
{
8080
std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";
8181

82-
if (mapArgs.count("-version"))
82+
if (IsArgSet("-version"))
8383
{
8484
strUsage += FormatParagraph(LicenseInfo());
8585
}

src/httpserver.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,10 +322,10 @@ static bool HTTPBindAddresses(struct evhttp* http)
322322
std::vector<std::pair<std::string, uint16_t> > endpoints;
323323

324324
// Determine what addresses to bind to
325-
if (!mapArgs.count("-rpcallowip")) { // Default to loopback if not allowing external IPs
325+
if (!IsArgSet("-rpcallowip")) { // Default to loopback if not allowing external IPs
326326
endpoints.push_back(std::make_pair("::1", defaultPort));
327327
endpoints.push_back(std::make_pair("127.0.0.1", defaultPort));
328-
if (mapArgs.count("-rpcbind")) {
328+
if (IsArgSet("-rpcbind")) {
329329
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
330330
}
331331
} else if (mapMultiArgs.count("-rpcbind")) { // Specific bind address

src/init.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -708,11 +708,11 @@ void InitParameterInteraction()
708708
{
709709
// when specifying an explicit binding address, you want to listen on it
710710
// even when -connect or -proxy is specified
711-
if (mapArgs.count("-bind")) {
711+
if (IsArgSet("-bind")) {
712712
if (SoftSetBoolArg("-listen", true))
713713
LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
714714
}
715-
if (mapArgs.count("-whitebind")) {
715+
if (IsArgSet("-whitebind")) {
716716
if (SoftSetBoolArg("-listen", true))
717717
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
718718
}
@@ -725,7 +725,7 @@ void InitParameterInteraction()
725725
LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
726726
}
727727

728-
if (mapArgs.count("-proxy")) {
728+
if (IsArgSet("-proxy")) {
729729
// to protect privacy, do not listen by default if a default proxy server is specified
730730
if (SoftSetBoolArg("-listen", false))
731731
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
@@ -748,7 +748,7 @@ void InitParameterInteraction()
748748
LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
749749
}
750750

751-
if (mapArgs.count("-externalip")) {
751+
if (IsArgSet("-externalip")) {
752752
// if an explicit public IP is specified, do not try to find others
753753
if (SoftSetBoolArg("-discover", false))
754754
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
@@ -892,7 +892,7 @@ bool AppInitParameterInteraction()
892892
if (GetBoolArg("-debugnet", false))
893893
InitWarning(_("Unsupported argument -debugnet ignored, use -debug=net."));
894894
// Check for -socks - as this is a privacy risk to continue, exit here
895-
if (mapArgs.count("-socks"))
895+
if (IsArgSet("-socks"))
896896
return InitError(_("Unsupported argument -socks found. Setting SOCKS version isn't possible anymore, only SOCKS5 proxies are supported."));
897897
// Check for -tor - as this is a privacy risk to continue, exit here
898898
if (GetBoolArg("-tor", false))
@@ -904,7 +904,7 @@ bool AppInitParameterInteraction()
904904
if (GetBoolArg("-whitelistalwaysrelay", false))
905905
InitWarning(_("Unsupported argument -whitelistalwaysrelay ignored, use -whitelistrelay and/or -whitelistforcerelay."));
906906

907-
if (mapArgs.count("-blockminsize"))
907+
if (IsArgSet("-blockminsize"))
908908
InitWarning("Unsupported argument -blockminsize ignored.");
909909

910910
// Checkmempool and checkblockindex default to true in regtest mode
@@ -959,7 +959,7 @@ bool AppInitParameterInteraction()
959959
// a transaction spammer can cheaply fill blocks using
960960
// 1-satoshi-fee transactions. It should be set above the real
961961
// cost to you of processing a transaction.
962-
if (mapArgs.count("-minrelaytxfee"))
962+
if (IsArgSet("-minrelaytxfee"))
963963
{
964964
CAmount n = 0;
965965
if (!ParseMoney(mapArgs["-minrelaytxfee"], n) || 0 == n)
@@ -997,7 +997,7 @@ bool AppInitParameterInteraction()
997997
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
998998

999999
fEnableReplacement = GetBoolArg("-mempoolreplacement", DEFAULT_ENABLE_REPLACEMENT);
1000-
if ((!fEnableReplacement) && mapArgs.count("-mempoolreplacement")) {
1000+
if ((!fEnableReplacement) && IsArgSet("-mempoolreplacement")) {
10011001
// Minimal effort at forwards compatibility
10021002
std::string strReplacementModeList = GetArg("-mempoolreplacement", ""); // default is impossible
10031003
std::vector<std::string> vstrReplacementModes;
@@ -1291,7 +1291,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
12911291
uint64_t nMaxOutboundLimit = 0; //unlimited unless -maxuploadtarget is set
12921292
uint64_t nMaxOutboundTimeframe = MAX_UPLOAD_TIMEFRAME;
12931293

1294-
if (mapArgs.count("-maxuploadtarget")) {
1294+
if (IsArgSet("-maxuploadtarget")) {
12951295
nMaxOutboundLimit = GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET)*1024*1024;
12961296
}
12971297

@@ -1523,7 +1523,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
15231523
fHaveGenesis = true;
15241524
}
15251525

1526-
if (mapArgs.count("-blocknotify"))
1526+
if (IsArgSet("-blocknotify"))
15271527
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
15281528

15291529
std::vector<boost::filesystem::path> vImportFiles;

src/miner.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,12 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams)
8484
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
8585
nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
8686
bool fWeightSet = false;
87-
if (mapArgs.count("-blockmaxweight")) {
87+
if (IsArgSet("-blockmaxweight")) {
8888
nBlockMaxWeight = GetArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
8989
nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
9090
fWeightSet = true;
9191
}
92-
if (mapArgs.count("-blockmaxsize")) {
92+
if (IsArgSet("-blockmaxsize")) {
9393
nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
9494
if (!fWeightSet) {
9595
nBlockMaxWeight = nBlockMaxSize * WITNESS_SCALE_FACTOR;

src/net_processing.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,7 +1060,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
10601060
unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
10611061

10621062
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
1063-
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
1063+
if (IsArgSet("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
10641064
{
10651065
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
10661066
return true;

src/qt/bitcoin.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,9 +587,9 @@ int main(int argc, char *argv[])
587587

588588
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
589589
// but before showing splash screen.
590-
if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
590+
if (IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version"))
591591
{
592-
HelpMessageDialog help(NULL, mapArgs.count("-version"));
592+
HelpMessageDialog help(NULL, IsArgSet("-version"));
593593
help.showOrPrint();
594594
return EXIT_SUCCESS;
595595
}
@@ -672,7 +672,7 @@ int main(int argc, char *argv[])
672672
// Allow parameter interaction before we create the options model
673673
app.parameterSetup();
674674
// Load GUI settings from QSettings
675-
app.createOptionsModel(mapArgs.count("-resetguisettings") != 0);
675+
app.createOptionsModel(IsArgSet("-resetguisettings"));
676676

677677
// Subscribe to global signals from core
678678
uiInterface.InitMessage.connect(InitMessage);

src/test/util_tests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
115115
// -a, -b and -ccc end up in map, -d ignored because it is after
116116
// a non-option argument (non-GNU option parsing)
117117
BOOST_CHECK(mapArgs.size() == 3 && mapMultiArgs.size() == 3);
118-
BOOST_CHECK(mapArgs.count("-a") && mapArgs.count("-b") && mapArgs.count("-ccc")
119-
&& !mapArgs.count("f") && !mapArgs.count("-d"));
118+
BOOST_CHECK(IsArgSet("-a") && IsArgSet("-b") && IsArgSet("-ccc")
119+
&& !IsArgSet("f") && !IsArgSet("-d"));
120120
BOOST_CHECK(mapMultiArgs.count("-a") && mapMultiArgs.count("-b") && mapMultiArgs.count("-ccc")
121121
&& !mapMultiArgs.count("f") && !mapMultiArgs.count("-d"));
122122

src/util.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,11 @@ void ParseParameters(int argc, const char* const argv[])
379379
}
380380
}
381381

382+
bool IsArgSet(const std::string& strArg)
383+
{
384+
return mapArgs.count(strArg);
385+
}
386+
382387
std::string GetArg(const std::string& strArg, const std::string& strDefault)
383388
{
384389
if (mapArgs.count(strArg))
@@ -498,7 +503,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
498503
if (!path.empty())
499504
return path;
500505

501-
if (mapArgs.count("-datadir")) {
506+
if (IsArgSet("-datadir")) {
502507
path = fs::system_complete(mapArgs["-datadir"]);
503508
if (!fs::is_directory(path)) {
504509
path = "";

0 commit comments

Comments
 (0)