Make ZMQ notification interface instance global.

This moves the used instance of CZMQNotificationInterface from a static
variable in init.cpp to a globally-accessible one declared in
zmq/zmqnotificationinterface.h.  The variable is also renamed to
g_zmq_notification_interface, to be consistent with other globals.

We need this to implement a new RPC method "getzmqnotifications" (see
https://github.com/bitcoin/bitcoin/issues/13526) in a follow up.
This commit is contained in:
Daniel Kraft 2018-06-29 15:16:31 +02:00
parent 2643fa5086
commit caac39b0ac
3 changed files with 11 additions and 11 deletions

View file

@ -99,10 +99,6 @@ void DummyWalletInit::AddWalletOptions() const
const WalletInitInterface& g_wallet_init_interface = DummyWalletInit(); const WalletInitInterface& g_wallet_init_interface = DummyWalletInit();
#endif #endif
#if ENABLE_ZMQ
static CZMQNotificationInterface* pzmqNotificationInterface = nullptr;
#endif
#ifdef WIN32 #ifdef WIN32
// Win32 LevelDB doesn't use filedescriptors, and the ones used for // Win32 LevelDB doesn't use filedescriptors, and the ones used for
// accessing block files don't count towards the fd_set size limit // accessing block files don't count towards the fd_set size limit
@ -279,10 +275,10 @@ void Shutdown()
g_wallet_init_interface.Stop(); g_wallet_init_interface.Stop();
#if ENABLE_ZMQ #if ENABLE_ZMQ
if (pzmqNotificationInterface) { if (g_zmq_notification_interface) {
UnregisterValidationInterface(pzmqNotificationInterface); UnregisterValidationInterface(g_zmq_notification_interface);
delete pzmqNotificationInterface; delete g_zmq_notification_interface;
pzmqNotificationInterface = nullptr; g_zmq_notification_interface = nullptr;
} }
#endif #endif
@ -1409,10 +1405,10 @@ bool AppInitMain()
} }
#if ENABLE_ZMQ #if ENABLE_ZMQ
pzmqNotificationInterface = CZMQNotificationInterface::Create(); g_zmq_notification_interface = CZMQNotificationInterface::Create();
if (pzmqNotificationInterface) { if (g_zmq_notification_interface) {
RegisterValidationInterface(pzmqNotificationInterface); RegisterValidationInterface(g_zmq_notification_interface);
} }
#endif #endif
uint64_t nMaxOutboundLimit = 0; //unlimited unless -maxuploadtarget is set uint64_t nMaxOutboundLimit = 0; //unlimited unless -maxuploadtarget is set

View file

@ -180,3 +180,5 @@ void CZMQNotificationInterface::BlockDisconnected(const std::shared_ptr<const CB
TransactionAddedToMempool(ptx); TransactionAddedToMempool(ptx);
} }
} }
CZMQNotificationInterface* g_zmq_notification_interface = nullptr;

View file

@ -37,4 +37,6 @@ private:
std::list<CZMQAbstractNotifier*> notifiers; std::list<CZMQAbstractNotifier*> notifiers;
}; };
extern CZMQNotificationInterface* g_zmq_notification_interface;
#endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H #endif // BITCOIN_ZMQ_ZMQNOTIFICATIONINTERFACE_H