Skip to content

Commit df2ced5

Browse files
committed
Merge pull request #7128
02354c9 Constrain rpcport default values to a single location in code (Luke Dashjr)
2 parents 93236c0 + 02354c9 commit df2ced5

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

src/bitcoin-cli.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ std::string HelpMessageCli()
3434
strUsage += HelpMessageOpt("-datadir=<dir>", _("Specify data directory"));
3535
AppendParamsHelpMessages(strUsage);
3636
strUsage += HelpMessageOpt("-rpcconnect=<ip>", strprintf(_("Send commands to node running on <ip> (default: %s)"), DEFAULT_RPCCONNECT));
37-
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), 8332, 18332));
37+
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Connect to JSON-RPC on <port> (default: %u or testnet: %u)"), BaseParams(CBaseChainParams::MAIN).RPCPort(), BaseParams(CBaseChainParams::TESTNET).RPCPort()));
3838
strUsage += HelpMessageOpt("-rpcwait", _("Wait for RPC server to start"));
3939
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
4040
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));

src/chainparamsbase.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,23 @@ const CBaseChainParams& BaseParams()
8686
return *pCurrentBaseParams;
8787
}
8888

89-
void SelectBaseParams(const std::string& chain)
89+
CBaseChainParams& BaseParams(const std::string& chain)
9090
{
9191
if (chain == CBaseChainParams::MAIN)
92-
pCurrentBaseParams = &mainParams;
92+
return mainParams;
9393
else if (chain == CBaseChainParams::TESTNET)
94-
pCurrentBaseParams = &testNetParams;
94+
return testNetParams;
9595
else if (chain == CBaseChainParams::REGTEST)
96-
pCurrentBaseParams = &regTestParams;
96+
return regTestParams;
9797
else
9898
throw std::runtime_error(strprintf("%s: Unknown chain %s.", __func__, chain));
9999
}
100100

101+
void SelectBaseParams(const std::string& chain)
102+
{
103+
pCurrentBaseParams = &BaseParams(chain);
104+
}
105+
101106
std::string ChainNameFromCommandLine()
102107
{
103108
bool fRegTest = GetBoolArg("-regtest", false);

src/chainparamsbase.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ void AppendParamsHelpMessages(std::string& strUsage, bool debugHelp=true);
4242
*/
4343
const CBaseChainParams& BaseParams();
4444

45+
CBaseChainParams& BaseParams(const std::string& chain);
46+
4547
/** Sets the params returned by Params() to those for the given network. */
4648
void SelectBaseParams(const std::string& chain);
4749

src/init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ std::string HelpMessage(HelpMessageMode mode)
491491
strUsage += HelpMessageOpt("-rpcuser=<user>", _("Username for JSON-RPC connections"));
492492
strUsage += HelpMessageOpt("-rpcpassword=<pw>", _("Password for JSON-RPC connections"));
493493
strUsage += HelpMessageOpt("-rpcauth=<userpw>", _("Username and hashed password for JSON-RPC connections. The field <userpw> comes in the format: <USERNAME>:<SALT>$<HASH>. A canonical python script is included in share/rpcuser. This option can be specified multiple times"));
494-
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), 8332, 18332));
494+
strUsage += HelpMessageOpt("-rpcport=<port>", strprintf(_("Listen for JSON-RPC connections on <port> (default: %u or testnet: %u)"), BaseParams(CBaseChainParams::MAIN).RPCPort(), BaseParams(CBaseChainParams::TESTNET).RPCPort()));
495495
strUsage += HelpMessageOpt("-rpcallowip=<ip>", _("Allow JSON-RPC connections from specified source. Valid for <ip> are a single IP (e.g. 1.2.3.4), a network/netmask (e.g. 1.2.3.4/255.255.255.0) or a network/CIDR (e.g. 1.2.3.4/24). This option can be specified multiple times"));
496496
strUsage += HelpMessageOpt("-rpcthreads=<n>", strprintf(_("Set the number of threads to service RPC calls (default: %d)"), DEFAULT_HTTP_THREADS));
497497
if (showDebug) {

0 commit comments

Comments
 (0)