RPC/Net: Use boolean consistently for networkactive, and remove from getinfo

This commit is contained in:
Luke Dashjr 2016-10-23 05:35:52 +00:00
parent b2b33d9017
commit 54cf99745f
3 changed files with 11 additions and 13 deletions

View file

@ -89,10 +89,8 @@ UniValue getinfo(const UniValue& params, bool fHelp)
#endif #endif
obj.push_back(Pair("blocks", (int)chainActive.Height())); obj.push_back(Pair("blocks", (int)chainActive.Height()));
obj.push_back(Pair("timeoffset", GetTimeOffset())); obj.push_back(Pair("timeoffset", GetTimeOffset()));
if (g_connman) { if(g_connman)
obj.push_back(Pair("networkactive", g_connman->GetNetworkActive()));
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
}
obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string()))); obj.push_back(Pair("proxy", (proxy.IsValid() ? proxy.proxy.ToStringIPPort() : string())));
obj.push_back(Pair("difficulty", (double)GetDifficulty())); obj.push_back(Pair("difficulty", (double)GetDifficulty()));
obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC())); obj.push_back(Pair("testnet", Params().TestnetToBeDeprecatedFieldRPC()));

View file

@ -401,7 +401,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp)
" \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n" " \"localrelay\": true|false, (bool) true if transaction relay is requested from peers\n"
" \"timeoffset\": xxxxx, (numeric) the time offset\n" " \"timeoffset\": xxxxx, (numeric) the time offset\n"
" \"connections\": xxxxx, (numeric) the number of connections\n" " \"connections\": xxxxx, (numeric) the number of connections\n"
" \"networkactive\": x, (numeric) the number of connections\n" " \"networkactive\": true|false, (bool) whether p2p networking is enabled\n"
" \"networks\": [ (array) information per network\n" " \"networks\": [ (array) information per network\n"
" {\n" " {\n"
" \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n" " \"name\": \"xxx\", (string) network (ipv4, ipv6 or onion)\n"
@ -437,7 +437,7 @@ UniValue getnetworkinfo(const UniValue& params, bool fHelp)
obj.push_back(Pair("localrelay", fRelayTxes)); obj.push_back(Pair("localrelay", fRelayTxes));
obj.push_back(Pair("timeoffset", GetTimeOffset())); obj.push_back(Pair("timeoffset", GetTimeOffset()));
if (g_connman) { if (g_connman) {
obj.push_back(Pair("networkactive", (int)g_connman->GetNetworkActive())); obj.push_back(Pair("networkactive", g_connman->GetNetworkActive()));
obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL))); obj.push_back(Pair("connections", (int)g_connman->GetNodeCount(CConnman::CONNECTIONS_ALL)));
} }
obj.push_back(Pair("networks", GetNetworksInfo())); obj.push_back(Pair("networks", GetNetworksInfo()));
@ -578,8 +578,8 @@ UniValue setnetworkactive(const JSONRPCRequest& request)
{ {
if (request.fHelp || request.params.size() != 1) { if (request.fHelp || request.params.size() != 1) {
throw runtime_error( throw runtime_error(
"setnetworkactive \"true|false\"\n" "setnetworkactive true|false\n"
"Disable/Re-Enable all network activity temporarily." "Disable/enable all p2p network activity."
); );
} }

View file

@ -86,21 +86,21 @@ BOOST_AUTO_TEST_CASE(rpc_togglenetwork)
UniValue r; UniValue r;
r = CallRPC("getnetworkinfo"); r = CallRPC("getnetworkinfo");
int netState = find_value(r.get_obj(), "networkactive").get_int(); bool netState = find_value(r.get_obj(), "networkactive").get_bool();
BOOST_CHECK_EQUAL(netState, 1); BOOST_CHECK_EQUAL(netState, true);
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false")); BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive false"));
r = CallRPC("getnetworkinfo"); r = CallRPC("getnetworkinfo");
int numConnection = find_value(r.get_obj(), "connections").get_int(); int numConnection = find_value(r.get_obj(), "connections").get_int();
BOOST_CHECK_EQUAL(numConnection, 0); BOOST_CHECK_EQUAL(numConnection, 0);
netState = find_value(r.get_obj(), "networkactive").get_int(); netState = find_value(r.get_obj(), "networkactive").get_bool();
BOOST_CHECK_EQUAL(netState, 0); BOOST_CHECK_EQUAL(netState, false);
BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive true")); BOOST_CHECK_NO_THROW(CallRPC("setnetworkactive true"));
r = CallRPC("getnetworkinfo"); r = CallRPC("getnetworkinfo");
netState = find_value(r.get_obj(), "networkactive").get_int(); netState = find_value(r.get_obj(), "networkactive").get_bool();
BOOST_CHECK_EQUAL(netState, 1); BOOST_CHECK_EQUAL(netState, true);
} }
BOOST_AUTO_TEST_CASE(rpc_rawsign) BOOST_AUTO_TEST_CASE(rpc_rawsign)