24
24
25
25
#include < univalue.h>
26
26
27
- using namespace std ;
28
-
29
27
static const char DEFAULT_RPCCONNECT[] = " 127.0.0.1" ;
30
28
static const int DEFAULT_HTTP_CLIENT_TIMEOUT=900 ;
31
29
static const int CONTINUE_EXECUTION=-1 ;
32
30
33
31
std::string HelpMessageCli ()
34
32
{
35
- string strUsage;
33
+ std:: string strUsage;
36
34
strUsage += HelpMessageGroup (_ (" Options:" ));
37
35
strUsage += HelpMessageOpt (" -?" , _ (" This help message" ));
38
36
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)
187
185
}
188
186
#endif
189
187
190
- UniValue CallRPC (const string& strMethod, const UniValue& params)
188
+ UniValue CallRPC (const std:: string& strMethod, const UniValue& params)
191
189
{
192
190
std::string host = GetArg (" -rpcconnect" , DEFAULT_RPCCONNECT);
193
191
int port = GetArg (" -rpcport" , BaseParams ().RPCPort ());
194
192
195
193
// Create event base
196
194
struct event_base *base = event_base_new (); // TODO RAII
197
195
if (!base)
198
- throw runtime_error (" cannot create event_base" );
196
+ throw std:: runtime_error (" cannot create event_base" );
199
197
200
198
// Synchronously look up hostname
201
199
struct evhttp_connection *evcon = evhttp_connection_base_new (base, NULL , host.c_str (), port); // TODO RAII
202
200
if (evcon == NULL )
203
- throw runtime_error (" create connection failed" );
201
+ throw std:: runtime_error (" create connection failed" );
204
202
evhttp_connection_set_timeout (evcon, GetArg (" -rpcclienttimeout" , DEFAULT_HTTP_CLIENT_TIMEOUT));
205
203
206
204
HTTPReply response;
207
205
struct evhttp_request *req = evhttp_request_new (http_request_done, (void *)&response); // TODO RAII
208
206
if (req == NULL )
209
- throw runtime_error (" create http request failed" );
207
+ throw std:: runtime_error (" create http request failed" );
210
208
#if LIBEVENT_VERSION_NUMBER >= 0x02010300
211
209
evhttp_request_set_error_cb (req, http_error_cb);
212
210
#endif
@@ -216,7 +214,7 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
216
214
if (mapArgs[" -rpcpassword" ] == " " ) {
217
215
// Try fall back to cookie-based authentication if no password is provided
218
216
if (!GetAuthCookie (&strRPCUserColonPass)) {
219
- throw runtime_error (strprintf (
217
+ throw std:: runtime_error (strprintf (
220
218
_ (" Could not locate RPC credentials. No authentication cookie could be found, and no rpcpassword is set in the configuration file (%s)" ),
221
219
GetConfigFile (GetArg (" -conf" , BITCOIN_CONF_FILENAME)).string ().c_str ()));
222
220
@@ -251,26 +249,26 @@ UniValue CallRPC(const string& strMethod, const UniValue& params)
251
249
if (response.status == 0 )
252
250
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 )));
253
251
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)" );
255
253
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 ));
257
255
else if (response.body .empty ())
258
- throw runtime_error (" no response from server" );
256
+ throw std:: runtime_error (" no response from server" );
259
257
260
258
// Parse reply
261
259
UniValue valReply (UniValue::VSTR);
262
260
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" );
264
262
const UniValue& reply = valReply.get_obj ();
265
263
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" );
267
265
268
266
return reply;
269
267
}
270
268
271
269
int CommandLineRPC (int argc, char *argv[])
272
270
{
273
- string strPrint;
271
+ std:: string strPrint;
274
272
int nRet = 0 ;
275
273
try {
276
274
// Skip switches
@@ -286,7 +284,7 @@ int CommandLineRPC(int argc, char *argv[])
286
284
args.push_back (line);
287
285
}
288
286
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)" );
290
288
std::string strMethod = args[0 ];
291
289
UniValue params = RPCConvertValues (strMethod, std::vector<std::string>(args.begin ()+1 , args.end ()));
292
290
@@ -340,7 +338,7 @@ int CommandLineRPC(int argc, char *argv[])
340
338
throw ;
341
339
}
342
340
catch (const std::exception& e) {
343
- strPrint = string (" error: " ) + e.what ();
341
+ strPrint = std:: string (" error: " ) + e.what ();
344
342
nRet = EXIT_FAILURE;
345
343
}
346
344
catch (...) {
0 commit comments