diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 75911d00874..863b495fb25 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -130,14 +130,10 @@ static void libevent_log_cb(int severity, const char *msg) // Exception thrown on connection error. This error is used to determine // when to wait if -rpcwait is given. // -class CConnectionFailed : public std::runtime_error -{ -public: - +struct CConnectionFailed : std::runtime_error { explicit inline CConnectionFailed(const std::string& msg) : std::runtime_error(msg) {} - }; // @@ -259,30 +255,25 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx) reply->error = err; } -/** Class that handles the conversion from a command-line to a JSON-RPC request, +static int8_t NetworkStringToId(const std::string& str) +{ + for (size_t i = 0; i < NETWORKS.size(); ++i) { + if (str == NETWORKS[i]) return i; + } + return UNKNOWN_NETWORK; +} + +/** Handle the conversion from a command-line to a JSON-RPC request, * as well as converting back to a JSON object that can be shown as result. */ -class BaseRequestHandler -{ -public: +struct BaseRequestHandler { virtual ~BaseRequestHandler() = default; virtual UniValue PrepareRequest(const std::string& method, const std::vector& args) = 0; virtual UniValue ProcessReply(const UniValue &batch_in) = 0; }; /** Process addrinfo requests */ -class AddrinfoRequestHandler : public BaseRequestHandler -{ -private: - int8_t NetworkStringToId(const std::string& str) const - { - for (size_t i = 0; i < NETWORKS.size(); ++i) { - if (str == NETWORKS[i]) return i; - } - return UNKNOWN_NETWORK; - } - -public: +struct AddrinfoRequestHandler : BaseRequestHandler { UniValue PrepareRequest(const std::string& method, const std::vector& args) override { if (!args.empty()) { @@ -321,9 +312,7 @@ public: }; /** Process getinfo requests */ -class GetinfoRequestHandler: public BaseRequestHandler -{ -public: +struct GetinfoRequestHandler : BaseRequestHandler { const int ID_NETWORKINFO = 0; const int ID_BLOCKCHAININFO = 1; const int ID_WALLETINFO = 2; @@ -396,15 +385,8 @@ private: std::array, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total) uint8_t m_block_relay_peers_count{0}; uint8_t m_manual_peers_count{0}; - int8_t NetworkStringToId(const std::string& str) const - { - for (size_t i = 0; i < NETWORKS.size(); ++i) { - if (str == NETWORKS[i]) return i; - } - return UNKNOWN_NETWORK; - } uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level - bool DetailsRequested() const { return m_details_level > 0 && m_details_level < 5; } + bool DetailsRequested() const { return m_details_level; } bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; } bool IsVersionSelected() const { return m_details_level == 3 || m_details_level == 4; } bool m_outbound_only_selected{false}; @@ -775,8 +757,7 @@ protected: }; /** Process default single requests */ -class DefaultRequestHandler: public BaseRequestHandler { -public: +struct DefaultRequestHandler : BaseRequestHandler { UniValue PrepareRequest(const std::string& method, const std::vector& args) override { UniValue params; @@ -1267,7 +1248,7 @@ static int CommandLineRPC(int argc, char *argv[]) gArgs.CheckMultipleCLIArgs(); std::unique_ptr rh; std::string method; - if (gArgs.IsArgSet("-getinfo")) { + if (gArgs.GetBoolArg("-getinfo", false)) { rh.reset(new GetinfoRequestHandler()); } else if (gArgs.GetBoolArg("-netinfo", false)) { if (!args.empty() && (args.at(0) == "h" || args.at(0) == "help")) {