Skip to content

Commit fdbfd25

Browse files
committed
cli, refactor: deduplicate NetworkStringToId()
1 parent be82139 commit fdbfd25

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

src/bitcoin-cli.cpp

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,14 @@ static void http_error_cb(enum evhttp_request_error err, void *ctx)
259259
reply->error = err;
260260
}
261261

262+
static int8_t NetworkStringToId(const std::string& str)
263+
{
264+
for (size_t i = 0; i < NETWORKS.size(); ++i) {
265+
if (str == NETWORKS[i]) return i;
266+
}
267+
return UNKNOWN_NETWORK;
268+
}
269+
262270
/** Class that handles the conversion from a command-line to a JSON-RPC request,
263271
* as well as converting back to a JSON object that can be shown as result.
264272
*/
@@ -273,15 +281,6 @@ class BaseRequestHandler
273281
/** Process addrinfo requests */
274282
class AddrinfoRequestHandler : public BaseRequestHandler
275283
{
276-
private:
277-
int8_t NetworkStringToId(const std::string& str) const
278-
{
279-
for (size_t i = 0; i < NETWORKS.size(); ++i) {
280-
if (str == NETWORKS[i]) return i;
281-
}
282-
return UNKNOWN_NETWORK;
283-
}
284-
285284
public:
286285
UniValue PrepareRequest(const std::string& method, const std::vector<std::string>& args) override
287286
{
@@ -396,13 +395,6 @@ class NetinfoRequestHandler : public BaseRequestHandler
396395
std::array<std::array<uint16_t, NETWORKS.size() + 1>, 3> m_counts{{{}}}; //!< Peer counts by (in/out/total, networks/total)
397396
uint8_t m_block_relay_peers_count{0};
398397
uint8_t m_manual_peers_count{0};
399-
int8_t NetworkStringToId(const std::string& str) const
400-
{
401-
for (size_t i = 0; i < NETWORKS.size(); ++i) {
402-
if (str == NETWORKS[i]) return i;
403-
}
404-
return UNKNOWN_NETWORK;
405-
}
406398
uint8_t m_details_level{0}; //!< Optional user-supplied arg to set dashboard details level
407399
bool DetailsRequested() const { return m_details_level; }
408400
bool IsAddressSelected() const { return m_details_level == 2 || m_details_level == 4; }

0 commit comments

Comments
 (0)