mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-14 15:19:52 +02:00
Merge bitcoin/bitcoin#31887: CLI cleanups
d423fd9ec83ae323ac29bdc1b677ed8260bd59c4 cli, bugfix: for -getinfo, replace IsArgSet() with GetBoolArg() (Jon Atack) e99e41b30704f0067e064f92e7f582361f49676c cli, refactor: simplify public-only classes with structs (Jon Atack) fdbfd250fbf27137f23b1064ae2fcd9bf3c59937 cli, refactor: deduplicate NetworkStringToId() (Jon Atack) be82139b2a1e5bcd7c47391672d38fa5aa05bc0b cli, refactor: simplify DetailsRequested() (Jon Atack) Pull request description: These have been accumulating over the past few years. Each is described in its commit message. ACKs for top commit: pablomartin4btc: re-ACK d423fd9ec83ae323ac29bdc1b677ed8260bd59c4 hodlinator: Code review ACK d423fd9ec83ae323ac29bdc1b677ed8260bd59c4 l0rinc: ACK d423fd9ec83ae323ac29bdc1b677ed8260bd59c4 ryanofsky: Code review ACK d423fd9ec83ae323ac29bdc1b677ed8260bd59c4, just running clang-format and updating commit messages since last review Tree-SHA512: a8e5f7827cef308186d5a7c3a627d2cd8f57437f4465d181986e5d3274ff0e2b9faac252dd55d9257d66a7aa99fca62b3000cdc0988d23385df20ff1f870a046
This commit is contained in:
commit
770d39a376
@ -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<std::string>& 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<std::string>& 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<std::array<uint16_t, NETWORKS.size() + 1>, 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<std::string>& args) override
|
||||
{
|
||||
UniValue params;
|
||||
@ -1267,7 +1248,7 @@ static int CommandLineRPC(int argc, char *argv[])
|
||||
gArgs.CheckMultipleCLIArgs();
|
||||
std::unique_ptr<BaseRequestHandler> 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")) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user