refactor: Add and use EnsureConnman in rpc code

This commit is contained in:
MarcoFalke
2021-04-17 20:59:17 +02:00
parent faabeb854a
commit fafb68add5
4 changed files with 70 additions and 51 deletions

View File

@@ -18,6 +18,7 @@
#include <pow.h>
#include <rpc/blockchain.h>
#include <rpc/mining.h>
#include <rpc/net.h>
#include <rpc/server.h>
#include <rpc/util.h>
#include <script/descriptor.h>
@@ -671,11 +672,9 @@ static RPCHelpMan getblocktemplate()
if (strMode != "template")
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid mode");
if(!node.connman)
throw JSONRPCError(RPC_CLIENT_P2P_DISABLED, "Error: Peer-to-peer functionality missing or disabled");
if (!Params().IsTestChain()) {
if (node.connman->GetNodeCount(ConnectionDirection::Both) == 0) {
const CConnman& connman = EnsureConnman(node);
if (connman.GetNodeCount(ConnectionDirection::Both) == 0) {
throw JSONRPCError(RPC_CLIENT_NOT_CONNECTED, PACKAGE_NAME " is not connected!");
}