Browse Source

Introduce (and use) an IsArgSet accessor method

pull/1/head
Matt Corallo 6 years ago
parent
commit
0cf86a6678
  1. 4
      src/bitcoin-cli.cpp
  2. 2
      src/bitcoin-tx.cpp
  3. 4
      src/bitcoind.cpp
  4. 4
      src/httpserver.cpp
  5. 20
      src/init.cpp
  6. 4
      src/miner.cpp
  7. 2
      src/net_processing.cpp
  8. 6
      src/qt/bitcoin.cpp
  9. 4
      src/test/util_tests.cpp
  10. 7
      src/util.cpp
  11. 8
      src/util.h
  12. 10
      src/wallet/wallet.cpp

4
src/bitcoin-cli.cpp

@ -76,9 +76,9 @@ static int AppInitRPC(int argc, char* argv[]) @@ -76,9 +76,9 @@ static int AppInitRPC(int argc, char* argv[])
// Parameters
//
ParseParameters(argc, argv);
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version")) {
if (argc<2 || IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version")) {
std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
if (!mapArgs.count("-version")) {
if (!IsArgSet("-version")) {
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoin-cli [options] <command> [params] " + strprintf(_("Send command to %s"), _(PACKAGE_NAME)) + "\n" +
" bitcoin-cli [options] help " + _("List commands") + "\n" +

2
src/bitcoin-tx.cpp

@ -51,7 +51,7 @@ static int AppInitRawTx(int argc, char* argv[]) @@ -51,7 +51,7 @@ static int AppInitRawTx(int argc, char* argv[])
fCreateBlank = GetBoolArg("-create", false);
if (argc<2 || mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help"))
if (argc<2 || IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help"))
{
// First part of help message is specific to this utility
std::string strUsage = strprintf(_("%s bitcoin-tx utility version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n\n" +

4
src/bitcoind.cpp

@ -75,11 +75,11 @@ bool AppInit(int argc, char* argv[]) @@ -75,11 +75,11 @@ bool AppInit(int argc, char* argv[])
ParseParameters(argc, argv);
// Process help and version before taking care about datadir
if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
if (IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version"))
{
std::string strUsage = strprintf(_("%s Daemon"), _(PACKAGE_NAME)) + " " + _("version") + " " + FormatFullVersion() + "\n";
if (mapArgs.count("-version"))
if (IsArgSet("-version"))
{
strUsage += FormatParagraph(LicenseInfo());
}

4
src/httpserver.cpp

@ -322,10 +322,10 @@ static bool HTTPBindAddresses(struct evhttp* http) @@ -322,10 +322,10 @@ static bool HTTPBindAddresses(struct evhttp* http)
std::vector<std::pair<std::string, uint16_t> > endpoints;
// Determine what addresses to bind to
if (!mapArgs.count("-rpcallowip")) { // Default to loopback if not allowing external IPs
if (!IsArgSet("-rpcallowip")) { // Default to loopback if not allowing external IPs
endpoints.push_back(std::make_pair("::1", defaultPort));
endpoints.push_back(std::make_pair("127.0.0.1", defaultPort));
if (mapArgs.count("-rpcbind")) {
if (IsArgSet("-rpcbind")) {
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
}
} else if (mapMultiArgs.count("-rpcbind")) { // Specific bind address

20
src/init.cpp

@ -708,11 +708,11 @@ void InitParameterInteraction() @@ -708,11 +708,11 @@ void InitParameterInteraction()
{
// when specifying an explicit binding address, you want to listen on it
// even when -connect or -proxy is specified
if (mapArgs.count("-bind")) {
if (IsArgSet("-bind")) {
if (SoftSetBoolArg("-listen", true))
LogPrintf("%s: parameter interaction: -bind set -> setting -listen=1\n", __func__);
}
if (mapArgs.count("-whitebind")) {
if (IsArgSet("-whitebind")) {
if (SoftSetBoolArg("-listen", true))
LogPrintf("%s: parameter interaction: -whitebind set -> setting -listen=1\n", __func__);
}
@ -725,7 +725,7 @@ void InitParameterInteraction() @@ -725,7 +725,7 @@ void InitParameterInteraction()
LogPrintf("%s: parameter interaction: -connect set -> setting -listen=0\n", __func__);
}
if (mapArgs.count("-proxy")) {
if (IsArgSet("-proxy")) {
// to protect privacy, do not listen by default if a default proxy server is specified
if (SoftSetBoolArg("-listen", false))
LogPrintf("%s: parameter interaction: -proxy set -> setting -listen=0\n", __func__);
@ -748,7 +748,7 @@ void InitParameterInteraction() @@ -748,7 +748,7 @@ void InitParameterInteraction()
LogPrintf("%s: parameter interaction: -listen=0 -> setting -listenonion=0\n", __func__);
}
if (mapArgs.count("-externalip")) {
if (IsArgSet("-externalip")) {
// if an explicit public IP is specified, do not try to find others
if (SoftSetBoolArg("-discover", false))
LogPrintf("%s: parameter interaction: -externalip set -> setting -discover=0\n", __func__);
@ -892,7 +892,7 @@ bool AppInitParameterInteraction() @@ -892,7 +892,7 @@ bool AppInitParameterInteraction()
if (GetBoolArg("-debugnet", false))
InitWarning(_("Unsupported argument -debugnet ignored, use -debug=net."));
// Check for -socks - as this is a privacy risk to continue, exit here
if (mapArgs.count("-socks"))
if (IsArgSet("-socks"))
return InitError(_("Unsupported argument -socks found. Setting SOCKS version isn't possible anymore, only SOCKS5 proxies are supported."));
// Check for -tor - as this is a privacy risk to continue, exit here
if (GetBoolArg("-tor", false))
@ -904,7 +904,7 @@ bool AppInitParameterInteraction() @@ -904,7 +904,7 @@ bool AppInitParameterInteraction()
if (GetBoolArg("-whitelistalwaysrelay", false))
InitWarning(_("Unsupported argument -whitelistalwaysrelay ignored, use -whitelistrelay and/or -whitelistforcerelay."));
if (mapArgs.count("-blockminsize"))
if (IsArgSet("-blockminsize"))
InitWarning("Unsupported argument -blockminsize ignored.");
// Checkmempool and checkblockindex default to true in regtest mode
@ -959,7 +959,7 @@ bool AppInitParameterInteraction() @@ -959,7 +959,7 @@ bool AppInitParameterInteraction()
// a transaction spammer can cheaply fill blocks using
// 1-satoshi-fee transactions. It should be set above the real
// cost to you of processing a transaction.
if (mapArgs.count("-minrelaytxfee"))
if (IsArgSet("-minrelaytxfee"))
{
CAmount n = 0;
if (!ParseMoney(mapArgs["-minrelaytxfee"], n) || 0 == n)
@ -997,7 +997,7 @@ bool AppInitParameterInteraction() @@ -997,7 +997,7 @@ bool AppInitParameterInteraction()
nMaxTipAge = GetArg("-maxtipage", DEFAULT_MAX_TIP_AGE);
fEnableReplacement = GetBoolArg("-mempoolreplacement", DEFAULT_ENABLE_REPLACEMENT);
if ((!fEnableReplacement) && mapArgs.count("-mempoolreplacement")) {
if ((!fEnableReplacement) && IsArgSet("-mempoolreplacement")) {
// Minimal effort at forwards compatibility
std::string strReplacementModeList = GetArg("-mempoolreplacement", ""); // default is impossible
std::vector<std::string> vstrReplacementModes;
@ -1291,7 +1291,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) @@ -1291,7 +1291,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
uint64_t nMaxOutboundLimit = 0; //unlimited unless -maxuploadtarget is set
uint64_t nMaxOutboundTimeframe = MAX_UPLOAD_TIMEFRAME;
if (mapArgs.count("-maxuploadtarget")) {
if (IsArgSet("-maxuploadtarget")) {
nMaxOutboundLimit = GetArg("-maxuploadtarget", DEFAULT_MAX_UPLOAD_TARGET)*1024*1024;
}
@ -1523,7 +1523,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler) @@ -1523,7 +1523,7 @@ bool AppInitMain(boost::thread_group& threadGroup, CScheduler& scheduler)
fHaveGenesis = true;
}
if (mapArgs.count("-blocknotify"))
if (IsArgSet("-blocknotify"))
uiInterface.NotifyBlockTip.connect(BlockNotifyCallback);
std::vector<boost::filesystem::path> vImportFiles;

4
src/miner.cpp

@ -84,12 +84,12 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams) @@ -84,12 +84,12 @@ BlockAssembler::BlockAssembler(const CChainParams& _chainparams)
nBlockMaxWeight = DEFAULT_BLOCK_MAX_WEIGHT;
nBlockMaxSize = DEFAULT_BLOCK_MAX_SIZE;
bool fWeightSet = false;
if (mapArgs.count("-blockmaxweight")) {
if (IsArgSet("-blockmaxweight")) {
nBlockMaxWeight = GetArg("-blockmaxweight", DEFAULT_BLOCK_MAX_WEIGHT);
nBlockMaxSize = MAX_BLOCK_SERIALIZED_SIZE;
fWeightSet = true;
}
if (mapArgs.count("-blockmaxsize")) {
if (IsArgSet("-blockmaxsize")) {
nBlockMaxSize = GetArg("-blockmaxsize", DEFAULT_BLOCK_MAX_SIZE);
if (!fWeightSet) {
nBlockMaxWeight = nBlockMaxSize * WITNESS_SCALE_FACTOR;

2
src/net_processing.cpp

@ -1060,7 +1060,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv, @@ -1060,7 +1060,7 @@ bool static ProcessMessage(CNode* pfrom, string strCommand, CDataStream& vRecv,
unsigned int nMaxSendBufferSize = connman.GetSendBufferSize();
LogPrint("net", "received: %s (%u bytes) peer=%d\n", SanitizeString(strCommand), vRecv.size(), pfrom->id);
if (mapArgs.count("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
if (IsArgSet("-dropmessagestest") && GetRand(atoi(mapArgs["-dropmessagestest"])) == 0)
{
LogPrintf("dropmessagestest DROPPING RECV MESSAGE\n");
return true;

6
src/qt/bitcoin.cpp

@ -587,9 +587,9 @@ int main(int argc, char *argv[]) @@ -587,9 +587,9 @@ int main(int argc, char *argv[])
// Show help message immediately after parsing command-line options (for "-lang") and setting locale,
// but before showing splash screen.
if (mapArgs.count("-?") || mapArgs.count("-h") || mapArgs.count("-help") || mapArgs.count("-version"))
if (IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version"))
{
HelpMessageDialog help(NULL, mapArgs.count("-version"));
HelpMessageDialog help(NULL, IsArgSet("-version"));
help.showOrPrint();
return EXIT_SUCCESS;
}
@ -672,7 +672,7 @@ int main(int argc, char *argv[]) @@ -672,7 +672,7 @@ int main(int argc, char *argv[])
// Allow parameter interaction before we create the options model
app.parameterSetup();
// Load GUI settings from QSettings
app.createOptionsModel(mapArgs.count("-resetguisettings") != 0);
app.createOptionsModel(IsArgSet("-resetguisettings"));
// Subscribe to global signals from core
uiInterface.InitMessage.connect(InitMessage);

4
src/test/util_tests.cpp

@ -115,8 +115,8 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters) @@ -115,8 +115,8 @@ BOOST_AUTO_TEST_CASE(util_ParseParameters)
// -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")
&& !mapArgs.count("f") && !mapArgs.count("-d"));
BOOST_CHECK(IsArgSet("-a") && IsArgSet("-b") && IsArgSet("-ccc")
&& !IsArgSet("f") && !IsArgSet("-d"));
BOOST_CHECK(mapMultiArgs.count("-a") && mapMultiArgs.count("-b") && mapMultiArgs.count("-ccc")
&& !mapMultiArgs.count("f") && !mapMultiArgs.count("-d"));

7
src/util.cpp

@ -379,6 +379,11 @@ void ParseParameters(int argc, const char* const argv[]) @@ -379,6 +379,11 @@ void ParseParameters(int argc, const char* const argv[])
}
}
bool IsArgSet(const std::string& strArg)
{
return mapArgs.count(strArg);
}
std::string GetArg(const std::string& strArg, const std::string& strDefault)
{
if (mapArgs.count(strArg))
@ -498,7 +503,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific) @@ -498,7 +503,7 @@ const boost::filesystem::path &GetDataDir(bool fNetSpecific)
if (!path.empty())
return path;
if (mapArgs.count("-datadir")) {
if (IsArgSet("-datadir")) {
path = fs::system_complete(mapArgs["-datadir"]);
if (!fs::is_directory(path)) {
path = "";

8
src/util.h

@ -123,6 +123,14 @@ inline bool IsSwitchChar(char c) @@ -123,6 +123,14 @@ inline bool IsSwitchChar(char c)
#endif
}
/**
* Return true if the given argument has been manually set
*
* @param strArg Argument to get (e.g. "-foo")
* @return true if the argument has been set
*/
bool IsArgSet(const std::string& strArg);
/**
* Return string argument or default value
*

10
src/wallet/wallet.cpp

@ -3494,7 +3494,7 @@ bool CWallet::InitLoadWallet() @@ -3494,7 +3494,7 @@ bool CWallet::InitLoadWallet()
walletInstance->SetBestChain(chainActive.GetLocator());
}
else if (mapArgs.count("-usehd")) {
else if (IsArgSet("-usehd")) {
bool useHD = GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET);
if (walletInstance->IsHDEnabled() && !useHD)
return InitError(strprintf(_("Error loading %s: You can't disable HD on a already existing HD wallet"), walletFile));
@ -3618,7 +3618,7 @@ bool CWallet::ParameterInteraction() @@ -3618,7 +3618,7 @@ bool CWallet::ParameterInteraction()
InitWarning(AmountHighWarn("-minrelaytxfee") + " " +
_("The wallet will avoid paying less than the minimum relay fee."));
if (mapArgs.count("-mintxfee"))
if (IsArgSet("-mintxfee"))
{
CAmount n = 0;
if (!ParseMoney(mapArgs["-mintxfee"], n) || 0 == n)
@ -3628,7 +3628,7 @@ bool CWallet::ParameterInteraction() @@ -3628,7 +3628,7 @@ bool CWallet::ParameterInteraction()
_("This is the minimum transaction fee you pay on every transaction."));
CWallet::minTxFee = CFeeRate(n);
}
if (mapArgs.count("-fallbackfee"))
if (IsArgSet("-fallbackfee"))
{
CAmount nFeePerK = 0;
if (!ParseMoney(mapArgs["-fallbackfee"], nFeePerK))
@ -3638,7 +3638,7 @@ bool CWallet::ParameterInteraction() @@ -3638,7 +3638,7 @@ bool CWallet::ParameterInteraction()
_("This is the transaction fee you may pay when fee estimates are not available."));
CWallet::fallbackFee = CFeeRate(nFeePerK);
}
if (mapArgs.count("-paytxfee"))
if (IsArgSet("-paytxfee"))
{
CAmount nFeePerK = 0;
if (!ParseMoney(mapArgs["-paytxfee"], nFeePerK))
@ -3654,7 +3654,7 @@ bool CWallet::ParameterInteraction() @@ -3654,7 +3654,7 @@ bool CWallet::ParameterInteraction()
mapArgs["-paytxfee"], ::minRelayTxFee.ToString()));
}
}
if (mapArgs.count("-maxtxfee"))
if (IsArgSet("-maxtxfee"))
{
CAmount nMaxFee = 0;
if (!ParseMoney(mapArgs["-maxtxfee"], nMaxFee))

Loading…
Cancel
Save