Skip to content

Commit e22f409

Browse files
author
MarcoFalke
committed
Merge #9220: Refactor: Stop using namespace std (bitcoin-cli/-tx).
2f2625a Removed using namespace std from bitcoin-cli/-tx and added std:: in appropriate places. (Karl-Johan Alm)
2 parents 97ec6e5 + 2f2625a commit e22f409

File tree

2 files changed

+108
-112
lines changed

2 files changed

+108
-112
lines changed

src/bitcoin-cli.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424

2525
#include <univalue.h>
2626

27-
using namespace std;
28-
2927
static const char DEFAULT_RPCCONNECT[] = "127.0.0.1";
3028
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900;
3129
static const int CONTINUE_EXECUTION=-1;
3230

3331
std::string HelpMessageCli()
3432
{
35-
string strUsage;
33+
std::string strUsage;
3634
strUsage += HelpMessageGroup(_("Options:"));
3735
strUsage += HelpMessageOpt("-?", _("This help message"));
3836
strUsage += HelpMessageOpt("-conf=<file>", strprintf(_("Specify configuration file (default: %s)"), BITCOIN_CONF_FILENAME));
@@ -187,26 +185,26 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx)
187185
}
188186
#endif
189187

190-
UniValue CallRPC(const string& strMethod, const UniValue& params)
188+
UniValue CallRPC(const std::string& strMethod, const UniValue& params)
191189
{
192190
std::string host = GetArg("-rpcconnect", DEFAULT_RPCCONNECT);
193191
int port = GetArg("-rpcport", BaseParams().RPCPort());
194192

195193
// Create event base
196194
struct event_base *base = event_base_new(); // TODO RAII
197195
if (!base)
198-
throw runtime_error("cannot create event_base");
196+
throw std::runtime_error("cannot create event_base");
199197

200198
// Synchronously look up hostname
201199
struct evhttp_connection *evcon = evhttp_connection_base_new(base, NULL, host.c_str(), port); // TODO RAII
202200
if (evcon == NULL)
203-
throw runtime_error("create connection failed");
201+
throw std::runtime_error("create connection failed");
204202
evhttp_connection_set_timeout(evcon, GetArg("-rpcclienttimeout", DEFAULT_HTTP_CLIENT_TIMEOUT));
205203

206204
HTTPReply response;
207205
struct evhttp_request *req = evhttp_request_new(http_request_done, (void*)&response); // TODO RAII
208206
if (req == NULL)
209-
throw runtime_error("create http request failed");
207+
throw std::runtime_error("create http request failed");
210208
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
211209
evhttp_request_set_error_cb(req, http_error_cb);
212210
#endif
@@ -216,7 +214,7 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
216214
if (mapArgs["-rpcpassword"] == "") {
217215
// Try fall back to cookie-based authentication if no password is provided
218216
if (!GetAuthCookie(&strRPCUserColonPass)) {
219-
throw runtime_error(strprintf(
217+
throw std::runtime_error(strprintf(
220218
_("Could not locate RPC credentials. No authentication cookie could be found, and no rpcpassword is set in the configuration file (%s)"),
221219
GetConfigFile(GetArg("-conf", BITCOIN_CONF_FILENAME)).string().c_str()));
222220

@@ -251,26 +249,26 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
251249
if (response.status == 0)
252250
throw CConnectionFailed(strprintf("couldn't connect to server\n(make sure server is running and you are connecting to the correct RPC port: %d %s)", response.error, http_errorstring(response.error)));
253251
else if (response.status == HTTP_UNAUTHORIZED)
254-
throw runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
252+
throw std::runtime_error("incorrect rpcuser or rpcpassword (authorization failed)");
255253
else if (response.status >= 400 && response.status != HTTP_BAD_REQUEST && response.status != HTTP_NOT_FOUND && response.status != HTTP_INTERNAL_SERVER_ERROR)
256-
throw runtime_error(strprintf("server returned HTTP error %d", response.status));
254+
throw std::runtime_error(strprintf("server returned HTTP error %d", response.status));
257255
else if (response.body.empty())
258-
throw runtime_error("no response from server");
256+
throw std::runtime_error("no response from server");
259257

260258
// Parse reply
261259
UniValue valReply(UniValue::VSTR);
262260
if (!valReply.read(response.body))
263-
throw runtime_error("couldn't parse reply from server");
261+
throw std::runtime_error("couldn't parse reply from server");
264262
const UniValue& reply = valReply.get_obj();
265263
if (reply.empty())
266-
throw runtime_error("expected reply to have result, error and id properties");
264+
throw std::runtime_error("expected reply to have result, error and id properties");
267265

268266
return reply;
269267
}
270268

271269
int CommandLineRPC(int argc, char *argv[])
272270
{
273-
string strPrint;
271+
std::string strPrint;
274272
int nRet = 0;
275273
try {
276274
// Skip switches
@@ -286,7 +284,7 @@ int CommandLineRPC(int argc, char *argv[])
286284
args.push_back(line);
287285
}
288286
if (args.size() < 1)
289-
throw runtime_error("too few parameters (need at least command)");
287+
throw std::runtime_error("too few parameters (need at least command)");
290288
std::string strMethod = args[0];
291289
UniValue params = RPCConvertValues(strMethod, std::vector<std::string>(args.begin()+1, args.end()));
292290

@@ -340,7 +338,7 @@ int CommandLineRPC(int argc, char *argv[])
340338
throw;
341339
}
342340
catch (const std::exception& e) {
343-
strPrint = string("error: ") + e.what();
341+
strPrint = std::string("error: ") + e.what();
344342
nRet = EXIT_FAILURE;
345343
}
346344
catch (...) {

0 commit comments

Comments
 (0)