|
5 | 5 |
|
6 | 6 | #include "validationinterface.h"
|
7 | 7 |
|
| 8 | +#include <boost/signals2/signal.hpp> |
| 9 | + |
| 10 | +struct MainSignalsInstance { |
| 11 | + boost::signals2::signal<void (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)> UpdatedBlockTip; |
| 12 | + boost::signals2::signal<void (const CTransactionRef &)> TransactionAddedToMempool; |
| 13 | + boost::signals2::signal<void (const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef>&)> BlockConnected; |
| 14 | + boost::signals2::signal<void (const std::shared_ptr<const CBlock> &)> BlockDisconnected; |
| 15 | + boost::signals2::signal<void (const CBlockLocator &)> SetBestChain; |
| 16 | + boost::signals2::signal<void (const uint256 &)> Inventory; |
| 17 | + boost::signals2::signal<void (int64_t nBestBlockTime, CConnman* connman)> Broadcast; |
| 18 | + boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked; |
| 19 | + boost::signals2::signal<void (const CBlockIndex *, const std::shared_ptr<const CBlock>&)> NewPoWValidBlock; |
| 20 | +}; |
| 21 | + |
8 | 22 | static CMainSignals g_signals;
|
9 | 23 |
|
| 24 | +CMainSignals::CMainSignals() { |
| 25 | + m_internals.reset(new MainSignalsInstance()); |
| 26 | +} |
| 27 | + |
10 | 28 | CMainSignals& GetMainSignals()
|
11 | 29 | {
|
12 | 30 | return g_signals;
|
13 | 31 | }
|
14 | 32 |
|
15 | 33 | void RegisterValidationInterface(CValidationInterface* pwalletIn) {
|
16 |
| - g_signals.UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3)); |
17 |
| - g_signals.TransactionAddedToMempool.connect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1)); |
18 |
| - g_signals.BlockConnected.connect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3)); |
19 |
| - g_signals.BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1)); |
20 |
| - g_signals.SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); |
21 |
| - g_signals.Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); |
22 |
| - g_signals.Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2)); |
23 |
| - g_signals.BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); |
24 |
| - g_signals.NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); |
| 34 | + g_signals.m_internals->UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3)); |
| 35 | + g_signals.m_internals->TransactionAddedToMempool.connect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1)); |
| 36 | + g_signals.m_internals->BlockConnected.connect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3)); |
| 37 | + g_signals.m_internals->BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1)); |
| 38 | + g_signals.m_internals->SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); |
| 39 | + g_signals.m_internals->Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); |
| 40 | + g_signals.m_internals->Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2)); |
| 41 | + g_signals.m_internals->BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); |
| 42 | + g_signals.m_internals->NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); |
25 | 43 | }
|
26 | 44 |
|
27 | 45 | void UnregisterValidationInterface(CValidationInterface* pwalletIn) {
|
28 |
| - g_signals.BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); |
29 |
| - g_signals.Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2)); |
30 |
| - g_signals.Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); |
31 |
| - g_signals.SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); |
32 |
| - g_signals.TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1)); |
33 |
| - g_signals.BlockConnected.disconnect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3)); |
34 |
| - g_signals.BlockDisconnected.disconnect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1)); |
35 |
| - g_signals.UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3)); |
36 |
| - g_signals.NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); |
| 46 | + g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2)); |
| 47 | + g_signals.m_internals->Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2)); |
| 48 | + g_signals.m_internals->Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1)); |
| 49 | + g_signals.m_internals->SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1)); |
| 50 | + g_signals.m_internals->TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1)); |
| 51 | + g_signals.m_internals->BlockConnected.disconnect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3)); |
| 52 | + g_signals.m_internals->BlockDisconnected.disconnect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1)); |
| 53 | + g_signals.m_internals->UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3)); |
| 54 | + g_signals.m_internals->NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2)); |
37 | 55 | }
|
38 | 56 |
|
39 | 57 | void UnregisterAllValidationInterfaces() {
|
40 |
| - g_signals.BlockChecked.disconnect_all_slots(); |
41 |
| - g_signals.Broadcast.disconnect_all_slots(); |
42 |
| - g_signals.Inventory.disconnect_all_slots(); |
43 |
| - g_signals.SetBestChain.disconnect_all_slots(); |
44 |
| - g_signals.TransactionAddedToMempool.disconnect_all_slots(); |
45 |
| - g_signals.BlockConnected.disconnect_all_slots(); |
46 |
| - g_signals.BlockDisconnected.disconnect_all_slots(); |
47 |
| - g_signals.UpdatedBlockTip.disconnect_all_slots(); |
48 |
| - g_signals.NewPoWValidBlock.disconnect_all_slots(); |
| 58 | + g_signals.m_internals->BlockChecked.disconnect_all_slots(); |
| 59 | + g_signals.m_internals->Broadcast.disconnect_all_slots(); |
| 60 | + g_signals.m_internals->Inventory.disconnect_all_slots(); |
| 61 | + g_signals.m_internals->SetBestChain.disconnect_all_slots(); |
| 62 | + g_signals.m_internals->TransactionAddedToMempool.disconnect_all_slots(); |
| 63 | + g_signals.m_internals->BlockConnected.disconnect_all_slots(); |
| 64 | + g_signals.m_internals->BlockDisconnected.disconnect_all_slots(); |
| 65 | + g_signals.m_internals->UpdatedBlockTip.disconnect_all_slots(); |
| 66 | + g_signals.m_internals->NewPoWValidBlock.disconnect_all_slots(); |
| 67 | +} |
| 68 | + |
| 69 | +void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) { |
| 70 | + m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload); |
| 71 | +} |
| 72 | + |
| 73 | +void CMainSignals::TransactionAddedToMempool(const CTransactionRef &ptx) { |
| 74 | + m_internals->TransactionAddedToMempool(ptx); |
| 75 | +} |
| 76 | + |
| 77 | +void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) { |
| 78 | + m_internals->BlockConnected(pblock, pindex, vtxConflicted); |
| 79 | +} |
| 80 | + |
| 81 | +void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock> &pblock) { |
| 82 | + m_internals->BlockDisconnected(pblock); |
| 83 | +} |
| 84 | + |
| 85 | +void CMainSignals::SetBestChain(const CBlockLocator &locator) { |
| 86 | + m_internals->SetBestChain(locator); |
| 87 | +} |
| 88 | + |
| 89 | +void CMainSignals::Inventory(const uint256 &hash) { |
| 90 | + m_internals->Inventory(hash); |
| 91 | +} |
| 92 | + |
| 93 | +void CMainSignals::Broadcast(int64_t nBestBlockTime, CConnman* connman) { |
| 94 | + m_internals->Broadcast(nBestBlockTime, connman); |
| 95 | +} |
| 96 | + |
| 97 | +void CMainSignals::BlockChecked(const CBlock& block, const CValidationState& state) { |
| 98 | + m_internals->BlockChecked(block, state); |
| 99 | +} |
| 100 | + |
| 101 | +void CMainSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) { |
| 102 | + m_internals->NewPoWValidBlock(pindex, block); |
49 | 103 | }
|
0 commit comments