Skip to content

Commit

Permalink
Merge #10607: scripted-diff: stop using the gArgs wrappers
Browse files Browse the repository at this point in the history
fcbde90 remove unused gArgs wrappers (Marko Bencun)
bb81e17 scripted-diff: stop using the gArgs wrappers (Marko Bencun)

Tree-SHA512: 49190740dfc723d680a093b625bf4e4e010bc121741b035d790f787e73eedd74966e4ceaf56975050d06b5d7d6cd8f46f9deb5cc78569df1e9faf0d7e543ee21
  • Loading branch information
laanwj committed Aug 14, 2017
2 parents 1227be3 + fcbde90 commit c2704ec
Show file tree
Hide file tree
Showing 41 changed files with 349 additions and 395 deletions.
32 changes: 16 additions & 16 deletions src/bitcoin-cli.cpp
Expand Up @@ -79,10 +79,10 @@ static int AppInitRPC(int argc, char* argv[])
//
// Parameters
//
ParseParameters(argc, argv);
if (argc<2 || IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help") || IsArgSet("-version")) {
gArgs.ParseParameters(argc, argv);
if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.IsArgSet("-help") || gArgs.IsArgSet("-version")) {
std::string strUsage = strprintf(_("%s RPC client version"), _(PACKAGE_NAME)) + " " + FormatFullVersion() + "\n";
if (!IsArgSet("-version")) {
if (!gArgs.IsArgSet("-version")) {
strUsage += "\n" + _("Usage:") + "\n" +
" bitcoin-cli [options] <command> [params] " + strprintf(_("Send command to %s"), _(PACKAGE_NAME)) + "\n" +
" bitcoin-cli [options] -named <command> [name=value] ... " + strprintf(_("Send command to %s (with named arguments)"), _(PACKAGE_NAME)) + "\n" +
Expand All @@ -100,11 +100,11 @@ static int AppInitRPC(int argc, char* argv[])
return EXIT_SUCCESS;
}
if (!fs::is_directory(GetDataDir(false))) {
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str());
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
return EXIT_FAILURE;
}
try {
ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME));
gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
} catch (const std::exception& e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return EXIT_FAILURE;
Expand All @@ -116,7 +116,7 @@ static int AppInitRPC(int argc, char* argv[])
fprintf(stderr, "Error: %s\n", e.what());
return EXIT_FAILURE;
}
if (GetBoolArg("-rpcssl", false))
if (gArgs.GetBoolArg("-rpcssl", false))
{
fprintf(stderr, "Error: SSL mode for RPC (-rpcssl) is no longer supported.\n");
return EXIT_FAILURE;
Expand Down Expand Up @@ -198,15 +198,15 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)
// 2. port in -rpcconnect (ie following : in ipv4 or ]: in ipv6)
// 3. default port for chain
int port = BaseParams().RPCPort();
SplitHostPort(GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host);
port = GetArg("-rpcport", port);
SplitHostPort(gArgs.GetArg("-rpcconnect", DEFAULT_RPCCONNECT), port, host);
port = gArgs.GetArg("-rpcport", port);

// Obtain event base
raii_event_base base = obtain_event_base();

// Synchronously look up hostname
raii_evhttp_connection evcon = obtain_evhttp_connection_base(base.get(), host, port);
evhttp_connection_set_timeout(evcon.get(), GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));
evhttp_connection_set_timeout(evcon.get(), gArgs.GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));

HTTPReply response;
raii_evhttp_request req = obtain_evhttp_request(http_request_done, (void*)&response);
Expand All @@ -218,16 +218,16 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)

// Get credentials
std::string strRPCUserColonPass;
if (GetArg("-rpcpassword", "") == "") {
if (gArgs.GetArg("-rpcpassword", "") == "") {
// Try fall back to cookie-based authentication if no password is provided
if (!GetAuthCookie(&strRPCUserColonPass)) {
throw std::runtime_error(strprintf(
_("Could not locate RPC credentials. No authentication cookie could be found, and no rpcpassword is set in the configuration file (%s)"),
GetConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME)).string().c_str()));
GetConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME)).string().c_str()));

}
} else {
strRPCUserColonPass = GetArg("-rpcuser", "") + ":" + GetArg("-rpcpassword", "");
strRPCUserColonPass = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
}

struct evkeyvalq* output_headers = evhttp_request_get_output_headers(req.get());
Expand All @@ -244,7 +244,7 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params)

// check if we should use a special wallet endpoint
std::string endpoint = "/";
std::string walletName = GetArg("-rpcwallet", "");
std::string walletName = gArgs.GetArg("-rpcwallet", "");
if (!walletName.empty()) {
char *encodedURI = evhttp_uriencode(walletName.c_str(), walletName.size(), false);
if (encodedURI) {
Expand Down Expand Up @@ -294,7 +294,7 @@ int CommandLineRPC(int argc, char *argv[])
argv++;
}
std::vector<std::string> args = std::vector<std::string>(&argv[1], &argv[argc]);
if (GetBoolArg("-stdin", false)) {
if (gArgs.GetBoolArg("-stdin", false)) {
// Read one arg per line from stdin and append
std::string line;
while (std::getline(std::cin,line))
Expand All @@ -306,14 +306,14 @@ int CommandLineRPC(int argc, char *argv[])
args.erase(args.begin()); // Remove trailing method name from arguments vector

UniValue params;
if(GetBoolArg("-named", DEFAULT_NAMED)) {
if(gArgs.GetBoolArg("-named", DEFAULT_NAMED)) {
params = RPCConvertNamedValues(strMethod, args);
} else {
params = RPCConvertValues(strMethod, args);
}

// Execute and handle connection failures with -rpcwait
const bool fWait = GetBoolArg("-rpcwait", false);
const bool fWait = gArgs.GetBoolArg("-rpcwait", false);
do {
try {
const UniValue reply = CallRPC(strMethod, params);
Expand Down
10 changes: 5 additions & 5 deletions src/bitcoin-tx.cpp
Expand Up @@ -39,7 +39,7 @@ static int AppInitRawTx(int argc, char* argv[])
//
// Parameters
//
ParseParameters(argc, argv);
gArgs.ParseParameters(argc, argv);

// Check for -testnet or -regtest parameter (Params() calls are only valid after this clause)
try {
Expand All @@ -49,9 +49,9 @@ static int AppInitRawTx(int argc, char* argv[])
return EXIT_FAILURE;
}

fCreateBlank = GetBoolArg("-create", false);
fCreateBlank = gArgs.GetBoolArg("-create", false);

if (argc<2 || IsArgSet("-?") || IsArgSet("-h") || IsArgSet("-help"))
if (argc<2 || gArgs.IsArgSet("-?") || gArgs.IsArgSet("-h") || gArgs.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" +
Expand Down Expand Up @@ -737,9 +737,9 @@ static void OutputTxHex(const CTransaction& tx)

static void OutputTx(const CTransaction& tx)
{
if (GetBoolArg("-json", false))
if (gArgs.GetBoolArg("-json", false))
OutputTxJSON(tx);
else if (GetBoolArg("-txid", false))
else if (gArgs.GetBoolArg("-txid", false))
OutputTxHash(tx);
else
OutputTxHex(tx);
Expand Down
14 changes: 7 additions & 7 deletions src/bitcoind.cpp
Expand Up @@ -71,14 +71,14 @@ bool AppInit(int argc, char* argv[])
// Parameters
//
// If Qt is used, parameters/bitcoin.conf are parsed in qt/bitcoin.cpp's main()
ParseParameters(argc, argv);
gArgs.ParseParameters(argc, argv);

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

if (IsArgSet("-version"))
if (gArgs.IsArgSet("-version"))
{
strUsage += FormatParagraph(LicenseInfo());
}
Expand All @@ -98,12 +98,12 @@ bool AppInit(int argc, char* argv[])
{
if (!fs::is_directory(GetDataDir(false)))
{
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", GetArg("-datadir", "").c_str());
fprintf(stderr, "Error: Specified data directory \"%s\" does not exist.\n", gArgs.GetArg("-datadir", "").c_str());
return false;
}
try
{
ReadConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME));
gArgs.ReadConfigFile(gArgs.GetArg("-conf", BITCOIN_CONF_FILENAME));
} catch (const std::exception& e) {
fprintf(stderr,"Error reading configuration file: %s\n", e.what());
return false;
Expand All @@ -125,7 +125,7 @@ bool AppInit(int argc, char* argv[])
}

// -server defaults to true for bitcoind but not for the GUI so do this here
SoftSetBoolArg("-server", true);
gArgs.SoftSetBoolArg("-server", true);
// Set this early so that parameter interactions go to console
InitLogging();
InitParameterInteraction();
Expand All @@ -144,7 +144,7 @@ bool AppInit(int argc, char* argv[])
// InitError will have been called with detailed error, which ends up on console
exit(EXIT_FAILURE);
}
if (GetBoolArg("-daemon", false))
if (gArgs.GetBoolArg("-daemon", false))
{
#if HAVE_DECL_DAEMON
fprintf(stdout, "Bitcoin server starting\n");
Expand Down
4 changes: 2 additions & 2 deletions src/chainparamsbase.cpp
Expand Up @@ -89,8 +89,8 @@ void SelectBaseParams(const std::string& chain)

std::string ChainNameFromCommandLine()
{
bool fRegTest = GetBoolArg("-regtest", false);
bool fTestNet = GetBoolArg("-testnet", false);
bool fRegTest = gArgs.GetBoolArg("-regtest", false);
bool fTestNet = gArgs.GetBoolArg("-testnet", false);

if (fTestNet && fRegTest)
throw std::runtime_error("Invalid combination of -regtest and -testnet.");
Expand Down
2 changes: 1 addition & 1 deletion src/dbwrapper.cpp
Expand Up @@ -115,7 +115,7 @@ CDBWrapper::CDBWrapper(const fs::path& path, size_t nCacheSize, bool fMemory, bo
dbwrapper_private::HandleError(status);
LogPrintf("Opened LevelDB successfully\n");

if (GetBoolArg("-forcecompactdb", false)) {
if (gArgs.GetBoolArg("-forcecompactdb", false)) {
LogPrintf("Starting database compaction of %s\n", path.string());
pdb->CompactRange(nullptr, nullptr);
LogPrintf("Finished database compaction of %s\n", path.string());
Expand Down
4 changes: 2 additions & 2 deletions src/httprpc.cpp
Expand Up @@ -210,7 +210,7 @@ static bool HTTPReq_JSONRPC(HTTPRequest* req, const std::string &)

static bool InitRPCAuthentication()
{
if (GetArg("-rpcpassword", "") == "")
if (gArgs.GetArg("-rpcpassword", "") == "")
{
LogPrintf("No rpcpassword set - using random cookie authentication\n");
if (!GenerateAuthCookie(&strRPCUserColonPass)) {
Expand All @@ -221,7 +221,7 @@ static bool InitRPCAuthentication()
}
} else {
LogPrintf("Config options rpcuser and rpcpassword will soon be deprecated. Locally-run instances may remove rpcuser to use cookie-based auth, or may be replaced with rpcauth. Please see share/rpcuser for rpcauth auth generation.\n");
strRPCUserColonPass = GetArg("-rpcuser", "") + ":" + GetArg("-rpcpassword", "");
strRPCUserColonPass = gArgs.GetArg("-rpcuser", "") + ":" + gArgs.GetArg("-rpcpassword", "");
}
return true;
}
Expand Down
14 changes: 7 additions & 7 deletions src/httpserver.cpp
Expand Up @@ -309,14 +309,14 @@ static bool ThreadHTTP(struct event_base* base, struct evhttp* http)
/** Bind HTTP server to specified addresses */
static bool HTTPBindAddresses(struct evhttp* http)
{
int defaultPort = GetArg("-rpcport", BaseParams().RPCPort());
int defaultPort = gArgs.GetArg("-rpcport", BaseParams().RPCPort());
std::vector<std::pair<std::string, uint16_t> > endpoints;

// Determine what addresses to bind to
if (!IsArgSet("-rpcallowip")) { // Default to loopback if not allowing external IPs
if (!gArgs.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 (IsArgSet("-rpcbind")) {
if (gArgs.IsArgSet("-rpcbind")) {
LogPrintf("WARNING: option -rpcbind was ignored because -rpcallowip was not specified, refusing to allow everyone to connect\n");
}
} else if (gArgs.IsArgSet("-rpcbind")) { // Specific bind address
Expand Down Expand Up @@ -369,7 +369,7 @@ bool InitHTTPServer()
if (!InitHTTPAllowList())
return false;

if (GetBoolArg("-rpcssl", false)) {
if (gArgs.GetBoolArg("-rpcssl", false)) {
uiInterface.ThreadSafeMessageBox(
"SSL mode for RPC (-rpcssl) is no longer supported.",
"", CClientUIInterface::MSG_ERROR);
Expand Down Expand Up @@ -401,7 +401,7 @@ bool InitHTTPServer()
return false;
}

evhttp_set_timeout(http, GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
evhttp_set_timeout(http, gArgs.GetArg("-rpcservertimeout", DEFAULT_HTTP_SERVER_TIMEOUT));
evhttp_set_max_headers_size(http, MAX_HEADERS_SIZE);
evhttp_set_max_body_size(http, MAX_SIZE);
evhttp_set_gencb(http, http_request_cb, nullptr);
Expand All @@ -412,7 +412,7 @@ bool InitHTTPServer()
}

LogPrint(BCLog::HTTP, "Initialized HTTP server\n");
int workQueueDepth = std::max((long)GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
int workQueueDepth = std::max((long)gArgs.GetArg("-rpcworkqueue", DEFAULT_HTTP_WORKQUEUE), 1L);
LogPrintf("HTTP: creating work queue of depth %d\n", workQueueDepth);

workQueue = new WorkQueue<HTTPClosure>(workQueueDepth);
Expand Down Expand Up @@ -442,7 +442,7 @@ std::future<bool> threadResult;
bool StartHTTPServer()
{
LogPrint(BCLog::HTTP, "Starting HTTP server\n");
int rpcThreads = std::max((long)GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
int rpcThreads = std::max((long)gArgs.GetArg("-rpcthreads", DEFAULT_HTTP_THREADS), 1L);
LogPrintf("HTTP: starting %d worker threads\n", rpcThreads);
std::packaged_task<bool(event_base*, evhttp*)> task(ThreadHTTP);
threadResult = task.get_future();
Expand Down

0 comments on commit c2704ec

Please sign in to comment.