From fdbfd250fbf27137f23b1064ae2fcd9bf3c59937 Mon Sep 17 00:00:00 2001 From: Jon Atack Date: Sun, 16 Feb 2025 09:38:15 -0600 Subject: [PATCH] cli, refactor: deduplicate NetworkStringToId() --- src/bitcoin-cli.cpp | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/src/bitcoin-cli.cpp b/src/bitcoin-cli.cpp index 44198b9a9be..a6d84747cdb 100644 --- a/src/bitcoin-cli.cpp +++ b/src/bitcoin-cli.cpp @@ -259,6 +259,14 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx) reply->error = err; } +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; +} + /** Class that handles 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. */ @@ -273,15 +281,6 @@ public: /** 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: UniValue PrepareRequest(const std::string& method, const std::vector& args) override { @@ -396,13 +395,6 @@ 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; } bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }