Skip to content

Commit 54cf997

Browse files
committed
RPC/Net: Use boolean consistently for networkactive, and remove from getinfo
1 parent b2b33d9 commit 54cf997

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/rpc/misc.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,8 @@ UniValue getinfo(const UniValue& params, bool fHelp)
8989
#endif
9090
obj.push_back(Pair("blocks", (int)chainActive.Height()));
9191
obj.push_back(Pair("timeoffset", GetTimeOffset()));
92-
if (g_connman) {
93-
obj.push_back(Pair("networkactive", g_connman->GetNetworkActive()));
92+
if(g_connman)
9493
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
95-
}
9694
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())));
9795
obj.push_back(Pair("difficulty", (double)GetDifficulty()));
9896
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));

src/rpc/net.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp)
401401
" \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n"
402402
" \"timeoffset\": xxxxx, (numeric) the time offset\n"
403403
" \"connections\": xxxxx, (numeric) the number of connections\n"
404-
" \"networkactive\": x, (numeric) the number of connections\n"
404+
" \"networkactive\": true|false, (bool) whether p2p networking is enabled\n"
405405
" \"networks\": [ (array) information per network\n"
406406
" {\n"
407407
" \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n"
@@ -437,7 +437,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp)
437437
obj.push_back(Pair("localrelay", fRelayTxes));
438438
obj.push_back(Pair("timeoffset", GetTimeOffset()));
439439
if (g_connman) {
440-
obj.push_back(Pair("networkactive", (int)g_connman->GetNetworkActive()));
440+
obj.push_back(Pair("networkactive", g_connman->GetNetworkActive()));
441441
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
442442
}
443443
obj.push_back(Pair("networks", GetNetworksInfo()));
@@ -578,8 +578,8 @@ UniValue setnetworkactive(const JSONRPCRequest& request)
578578
{
579579
if (request.fHelp || request.params.size() != 1) {
580580
throw runtime_error(
581-
"setnetworkactive \"true|false\"\n"
582-
"Disable/Re-Enable all network activity temporarily."
581+
"setnetworkactive true|false\n"
582+
"Disable/enable all p2p network activity."
583583
);
584584
}
585585

src/test/rpc_tests.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,21 @@ BOOST_AUTO_TEST_CASE(rpc_togglenetwork)
8686
UniValue r;
8787

8888
r = CallRPC("getnetworkinfo");
89-
int netState = find_value(r.get_obj(), "networkactive").get_int();
90-
BOOST_CHECK_EQUAL(netState, 1);
89+
bool netState = find_value(r.get_obj(), "networkactive").get_bool();
90+
BOOST_CHECK_EQUAL(netState, true);
9191

9292
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false"));
9393
r = CallRPC("getnetworkinfo");
9494
int numConnection = find_value(r.get_obj(), "connections").get_int();
9595
BOOST_CHECK_EQUAL(numConnection, 0);
9696

97-
netState = find_value(r.get_obj(), "networkactive").get_int();
98-
BOOST_CHECK_EQUAL(netState, 0);
97+
netState = find_value(r.get_obj(), "networkactive").get_bool();
98+
BOOST_CHECK_EQUAL(netState, false);
9999

100100
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive true"));
101101
r = CallRPC("getnetworkinfo");
102-
netState = find_value(r.get_obj(), "networkactive").get_int();
103-
BOOST_CHECK_EQUAL(netState, 1);
102+
netState = find_value(r.get_obj(), "networkactive").get_bool();
103+
BOOST_CHECK_EQUAL(netState, true);
104104
}
105105

106106
BOOST_AUTO_TEST_CASE(rpc_rawsign)

0 commit comments

Comments
 (0)