diff options
author | Russell Yanofsky <russ@yanofsky.org> | 2017-04-17 16:38:51 -0400 |
---|---|---|
committer | John Newbery <john@johnnewbery.com> | 2018-04-04 16:52:40 -0400 |
commit | 582daf6d22da5394d02a12003b9542d9f5865ae2 (patch) | |
tree | ba93cc572b10671ddf6aea64cf331baf2b7a1970 /src/interface | |
parent | 3034a462a5d30144cf0ec801d07f0c8c36d560f3 (diff) |
Remove direct bitcoin calls from qt/rpcconsole.cpp
Diffstat (limited to 'src/interface')
-rw-r--r-- | src/interface/node.cpp | 36 | ||||
-rw-r--r-- | src/interface/node.h | 23 |
2 files changed, 59 insertions, 0 deletions
diff --git a/src/interface/node.cpp b/src/interface/node.cpp index 740878b675..2f0114f5e4 100644 --- a/src/interface/node.cpp +++ b/src/interface/node.cpp @@ -15,6 +15,7 @@ #include <netaddress.h> #include <netbase.h> #include <primitives/block.h> +#include <rpc/server.h> #include <scheduler.h> #include <sync.h> #include <txmempool.h> @@ -34,6 +35,7 @@ #include <atomic> #include <boost/thread/thread.hpp> +#include <univalue.h> class CWallet; @@ -114,6 +116,29 @@ class NodeImpl : public Node } return false; } + bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) override + { + if (g_connman) { + g_connman->Ban(net_addr, reason, ban_time_offset); + return true; + } + return false; + } + bool unban(const CSubNet& ip) override + { + if (g_connman) { + g_connman->Unban(ip); + return true; + } + return false; + } + bool disconnect(NodeId id) override + { + if (g_connman) { + return g_connman->DisconnectNode(id); + } + return false; + } int64_t getTotalBytesRecv() override { return g_connman ? g_connman->GetTotalBytesRecv() : 0; } int64_t getTotalBytesSent() override { return g_connman ? g_connman->GetTotalBytesSent() : 0; } size_t getMempoolSize() override { return ::mempool.size(); } @@ -160,6 +185,17 @@ class NodeImpl : public Node } } bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); } + UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) override + { + JSONRPCRequest req; + req.params = params; + req.strMethod = command; + req.URI = uri; + return ::tableRPC.execute(req); + } + std::vector<std::string> listRpcCommands() override { return ::tableRPC.listCommands(); } + void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) override { RPCSetTimerInterfaceIfUnset(iface); } + void rpcUnsetTimerInterface(RPCTimerInterface* iface) override { RPCUnsetTimerInterface(iface); } std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override { return MakeHandler(::uiInterface.InitMessage.connect(fn)); diff --git a/src/interface/node.h b/src/interface/node.h index 880232d9e7..aeac1d6215 100644 --- a/src/interface/node.h +++ b/src/interface/node.h @@ -19,6 +19,8 @@ #include <vector> class CNodeStats; +class RPCTimerInterface; +class UniValue; class proxyType; struct CNodeStateStats; @@ -91,6 +93,15 @@ public: //! Get ban map entries. virtual bool getBanned(banmap_t& banmap) = 0; + //! Ban node. + virtual bool ban(const CNetAddr& net_addr, BanReason reason, int64_t ban_time_offset) = 0; + + //! Unban node. + virtual bool unban(const CSubNet& ip) = 0; + + //! Disconnect node. + virtual bool disconnect(NodeId id) = 0; + //! Get total bytes recv. virtual int64_t getTotalBytesRecv() = 0; @@ -130,6 +141,18 @@ public: //! Get network active. virtual bool getNetworkActive() = 0; + //! Execute rpc command. + virtual UniValue executeRpc(const std::string& command, const UniValue& params, const std::string& uri) = 0; + + //! List rpc commands. + virtual std::vector<std::string> listRpcCommands() = 0; + + //! Set RPC timer interface if unset. + virtual void rpcSetTimerInterfaceIfUnset(RPCTimerInterface* iface) = 0; + + //! Unset RPC timer interface. + virtual void rpcUnsetTimerInterface(RPCTimerInterface* iface) = 0; + //! Register handler for init messages. using InitMessageFn = std::function<void(const std::string& message)>; virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0; |