aboutsummaryrefslogtreecommitdiff
path: root/src/interface
diff options
context:
space:
mode:
authorRussell Yanofsky <russ@yanofsky.org>2017-04-17 15:37:36 -0400
committerJohn Newbery <john@johnnewbery.com>2018-04-04 16:52:40 -0400
commitfe6f27e6ea68a139d3a98b30a53706008ef8b132 (patch)
treeb464ec4ceb05146ccd8c2f4e7f44559546a6e72c /src/interface
parent5fba3af21e44ab7552c57782de430c1f4cfd6697 (diff)
downloadbitcoin-fe6f27e6ea68a139d3a98b30a53706008ef8b132.tar.xz
Remove direct bitcoin calls from qt/clientmodel.cpp
Diffstat (limited to 'src/interface')
-rw-r--r--src/interface/node.cpp87
-rw-r--r--src/interface/node.h71
2 files changed, 158 insertions, 0 deletions
diff --git a/src/interface/node.cpp b/src/interface/node.cpp
index 5f4f0f2fa7..e053080074 100644
--- a/src/interface/node.cpp
+++ b/src/interface/node.cpp
@@ -4,6 +4,7 @@
#include <interface/node.h>
+#include <chain.h>
#include <chainparams.h>
#include <init.h>
#include <interface/handler.h>
@@ -11,9 +12,13 @@
#include <net.h>
#include <netaddress.h>
#include <netbase.h>
+#include <primitives/block.h>
#include <scheduler.h>
+#include <sync.h>
+#include <txmempool.h>
#include <ui_interface.h>
#include <util.h>
+#include <validation.h>
#include <warnings.h>
#if defined(HAVE_CONFIG_H)
@@ -25,6 +30,7 @@
#define CHECK_WALLET(x) throw std::logic_error("Wallet function called in non-wallet build.")
#endif
+#include <atomic>
#include <boost/thread/thread.hpp>
class CWallet;
@@ -69,6 +75,56 @@ class NodeImpl : public Node
}
std::string helpMessage(HelpMessageMode mode) override { return HelpMessage(mode); }
bool getProxy(Network net, proxyType& proxy_info) override { return GetProxy(net, proxy_info); }
+ size_t getNodeCount(CConnman::NumConnections flags) override
+ {
+ return g_connman ? g_connman->GetNodeCount(flags) : 0;
+ }
+ 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(); }
+ size_t getMempoolDynamicUsage() override { return ::mempool.DynamicMemoryUsage(); }
+ bool getHeaderTip(int& height, int64_t& block_time) override
+ {
+ LOCK(::cs_main);
+ if (::pindexBestHeader) {
+ height = ::pindexBestHeader->nHeight;
+ block_time = ::pindexBestHeader->GetBlockTime();
+ return true;
+ }
+ return false;
+ }
+ int getNumBlocks() override
+ {
+ LOCK(::cs_main);
+ return ::chainActive.Height();
+ }
+ int64_t getLastBlockTime() override
+ {
+ LOCK(::cs_main);
+ if (::chainActive.Tip()) {
+ return ::chainActive.Tip()->GetBlockTime();
+ }
+ return Params().GenesisBlock().GetBlockTime(); // Genesis block's time of current network
+ }
+ double getVerificationProgress() override
+ {
+ const CBlockIndex* tip;
+ {
+ LOCK(::cs_main);
+ tip = ::chainActive.Tip();
+ }
+ return GuessVerificationProgress(::Params().TxData(), tip);
+ }
+ bool isInitialBlockDownload() override { return IsInitialBlockDownload(); }
+ bool getReindex() override { return ::fReindex; }
+ bool getImporting() override { return ::fImporting; }
+ void setNetworkActive(bool active) override
+ {
+ if (g_connman) {
+ g_connman->SetNetworkActive(active);
+ }
+ }
+ bool getNetworkActive() override { return g_connman && g_connman->GetNetworkActive(); }
std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) override
{
return MakeHandler(::uiInterface.InitMessage.connect(fn));
@@ -90,6 +146,37 @@ class NodeImpl : public Node
CHECK_WALLET(
return MakeHandler(::uiInterface.LoadWallet.connect([fn](CWallet* wallet) { fn(MakeWallet(*wallet)); })));
}
+ std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) override
+ {
+ return MakeHandler(::uiInterface.NotifyNumConnectionsChanged.connect(fn));
+ }
+ std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) override
+ {
+ return MakeHandler(::uiInterface.NotifyNetworkActiveChanged.connect(fn));
+ }
+ std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) override
+ {
+ return MakeHandler(::uiInterface.NotifyAlertChanged.connect(fn));
+ }
+ std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) override
+ {
+ return MakeHandler(::uiInterface.BannedListChanged.connect(fn));
+ }
+ std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) override
+ {
+ return MakeHandler(::uiInterface.NotifyBlockTip.connect([fn](bool initial_download, const CBlockIndex* block) {
+ fn(initial_download, block->nHeight, block->GetBlockTime(),
+ GuessVerificationProgress(::Params().TxData(), block));
+ }));
+ }
+ std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) override
+ {
+ return MakeHandler(
+ ::uiInterface.NotifyHeaderTip.connect([fn](bool initial_download, const CBlockIndex* block) {
+ fn(initial_download, block->nHeight, block->GetBlockTime(),
+ GuessVerificationProgress(::Params().TxData(), block));
+ }));
+ }
};
} // namespace
diff --git a/src/interface/node.h b/src/interface/node.h
index d1749871bf..5275030ca1 100644
--- a/src/interface/node.h
+++ b/src/interface/node.h
@@ -6,10 +6,13 @@
#define BITCOIN_INTERFACE_NODE_H
#include <init.h> // For HelpMessageMode
+#include <net.h> // For CConnman::NumConnections
#include <netaddress.h> // For Network
#include <functional>
#include <memory>
+#include <stddef.h>
+#include <stdint.h>
#include <string>
class proxyType;
@@ -73,6 +76,48 @@ public:
//! Get proxy.
virtual bool getProxy(Network net, proxyType& proxy_info) = 0;
+ //! Get number of connections.
+ virtual size_t getNodeCount(CConnman::NumConnections flags) = 0;
+
+ //! Get total bytes recv.
+ virtual int64_t getTotalBytesRecv() = 0;
+
+ //! Get total bytes sent.
+ virtual int64_t getTotalBytesSent() = 0;
+
+ //! Get mempool size.
+ virtual size_t getMempoolSize() = 0;
+
+ //! Get mempool dynamic usage.
+ virtual size_t getMempoolDynamicUsage() = 0;
+
+ //! Get header tip height and time.
+ virtual bool getHeaderTip(int& height, int64_t& block_time) = 0;
+
+ //! Get num blocks.
+ virtual int getNumBlocks() = 0;
+
+ //! Get last block time.
+ virtual int64_t getLastBlockTime() = 0;
+
+ //! Get verification progress.
+ virtual double getVerificationProgress() = 0;
+
+ //! Is initial block download.
+ virtual bool isInitialBlockDownload() = 0;
+
+ //! Get reindex.
+ virtual bool getReindex() = 0;
+
+ //! Get importing.
+ virtual bool getImporting() = 0;
+
+ //! Set network active.
+ virtual void setNetworkActive(bool active) = 0;
+
+ //! Get network active.
+ virtual bool getNetworkActive() = 0;
+
//! Register handler for init messages.
using InitMessageFn = std::function<void(const std::string& message)>;
virtual std::unique_ptr<Handler> handleInitMessage(InitMessageFn fn) = 0;
@@ -96,6 +141,32 @@ public:
//! Register handler for load wallet messages.
using LoadWalletFn = std::function<void(std::unique_ptr<Wallet> wallet)>;
virtual std::unique_ptr<Handler> handleLoadWallet(LoadWalletFn fn) = 0;
+
+ //! Register handler for number of connections changed messages.
+ using NotifyNumConnectionsChangedFn = std::function<void(int new_num_connections)>;
+ virtual std::unique_ptr<Handler> handleNotifyNumConnectionsChanged(NotifyNumConnectionsChangedFn fn) = 0;
+
+ //! Register handler for network active messages.
+ using NotifyNetworkActiveChangedFn = std::function<void(bool network_active)>;
+ virtual std::unique_ptr<Handler> handleNotifyNetworkActiveChanged(NotifyNetworkActiveChangedFn fn) = 0;
+
+ //! Register handler for notify alert messages.
+ using NotifyAlertChangedFn = std::function<void()>;
+ virtual std::unique_ptr<Handler> handleNotifyAlertChanged(NotifyAlertChangedFn fn) = 0;
+
+ //! Register handler for ban list messages.
+ using BannedListChangedFn = std::function<void()>;
+ virtual std::unique_ptr<Handler> handleBannedListChanged(BannedListChangedFn fn) = 0;
+
+ //! Register handler for block tip messages.
+ using NotifyBlockTipFn =
+ std::function<void(bool initial_download, int height, int64_t block_time, double verification_progress)>;
+ virtual std::unique_ptr<Handler> handleNotifyBlockTip(NotifyBlockTipFn fn) = 0;
+
+ //! Register handler for header tip messages.
+ using NotifyHeaderTipFn =
+ std::function<void(bool initial_download, int height, int64_t block_time, double verification_progress)>;
+ virtual std::unique_ptr<Handler> handleNotifyHeaderTip(NotifyHeaderTipFn fn) = 0;
};
//! Return implementation of Node interface.