Fabcoin Core  0.16.2
P2P Digital Currency
validationinterface.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #include <validationinterface.h>
7 
8 #include <init.h>
9 #include <primitives/block.h>
10 #include <scheduler.h>
11 #include <sync.h>
12 #include <util.h>
13 
14 #include <list>
15 #include <atomic>
16 
17 #include <boost/signals2/signal.hpp>
18 
20  boost::signals2::signal<void (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)> UpdatedBlockTip;
21  boost::signals2::signal<void (const CTransactionRef &)> TransactionAddedToMempool;
22  boost::signals2::signal<void (const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef>&)> BlockConnected;
23  boost::signals2::signal<void (const std::shared_ptr<const CBlock> &)> BlockDisconnected;
24  boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
25  boost::signals2::signal<void (const uint256 &)> Inventory;
26  boost::signals2::signal<void (int64_t nBestBlockTime, CConnman* connman)> Broadcast;
27  boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
28  boost::signals2::signal<void (const CBlockIndex *, const std::shared_ptr<const CBlock>&)> NewPoWValidBlock;
29  boost::signals2::signal<void (std::shared_ptr<CReserveScript>&)> ScriptForMining;
30  boost::signals2::signal<void (const uint256 &)> BlockFound;
31 
32 
33  // We are not allowed to assume the scheduler only runs in one thread,
34  // but must ensure all callbacks happen in-order, so we end up creating
35  // our own queue here :(
37 
38  MainSignalsInstance(CScheduler *pscheduler) : m_schedulerClient(pscheduler) {}
39 };
40 
41 static CMainSignals g_signals;
42 
44  assert(!m_internals);
45  m_internals.reset(new MainSignalsInstance(&scheduler));
46 }
47 
49  m_internals.reset(nullptr);
50 }
51 
53  m_internals->m_schedulerClient.EmptyQueue();
54 }
55 
57 {
58  return g_signals;
59 }
60 
62  g_signals.m_internals->UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
63  g_signals.m_internals->TransactionAddedToMempool.connect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
64  g_signals.m_internals->BlockConnected.connect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
65  g_signals.m_internals->BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
66  g_signals.m_internals->SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
67  g_signals.m_internals->Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
68  g_signals.m_internals->Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
69  g_signals.m_internals->BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
70  g_signals.m_internals->NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
71  g_signals.m_internals->ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
72  g_signals.m_internals->BlockFound.connect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1));
73 }
74 
76  g_signals.m_internals->BlockFound.disconnect(boost::bind(&CValidationInterface::ResetRequestCount, pwalletIn, _1));
77  g_signals.m_internals->ScriptForMining.disconnect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
78  g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
79  g_signals.m_internals->Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
80  g_signals.m_internals->Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
81  g_signals.m_internals->SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
82  g_signals.m_internals->TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
83  g_signals.m_internals->BlockConnected.disconnect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
84  g_signals.m_internals->BlockDisconnected.disconnect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
85  g_signals.m_internals->UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
86  g_signals.m_internals->NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
87 }
88 
90  g_signals.m_internals->BlockFound.disconnect_all_slots();
91  g_signals.m_internals->ScriptForMining.disconnect_all_slots();
92  g_signals.m_internals->BlockChecked.disconnect_all_slots();
93  g_signals.m_internals->Broadcast.disconnect_all_slots();
94  g_signals.m_internals->Inventory.disconnect_all_slots();
95  g_signals.m_internals->SetBestChain.disconnect_all_slots();
96  g_signals.m_internals->TransactionAddedToMempool.disconnect_all_slots();
97  g_signals.m_internals->BlockConnected.disconnect_all_slots();
98  g_signals.m_internals->BlockDisconnected.disconnect_all_slots();
99  g_signals.m_internals->UpdatedBlockTip.disconnect_all_slots();
100  g_signals.m_internals->NewPoWValidBlock.disconnect_all_slots();
101 }
102 
103 void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
104  m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
105 }
106 
108  m_internals->TransactionAddedToMempool(ptx);
109 }
110 
111 void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) {
112  m_internals->BlockConnected(pblock, pindex, vtxConflicted);
113 }
114 
115 void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock> &pblock) {
116  m_internals->BlockDisconnected(pblock);
117 }
118 
120  m_internals->SetBestChain(locator);
121 }
122 
123 void CMainSignals::Inventory(const uint256 &hash) {
124  m_internals->Inventory(hash);
125 }
126 
127 void CMainSignals::Broadcast(int64_t nBestBlockTime, CConnman* connman) {
128  m_internals->Broadcast(nBestBlockTime, connman);
129 }
130 
131 void CMainSignals::BlockChecked(const CBlock& block, const CValidationState& state) {
132  m_internals->BlockChecked(block, state);
133 }
134 
135 void CMainSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
136  m_internals->NewPoWValidBlock(pindex, block);
137 }
138 
139 void CMainSignals::ScriptForMining(std::shared_ptr<CReserveScript> &coinbaseScript){
140  m_internals->ScriptForMining(coinbaseScript);
141 }
142 
144  m_internals->BlockFound(hash);
145 }
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)
Class used by CScheduler clients which may schedule multiple jobs which are required to be run serial...
Definition: scheduler.h:93
virtual void ResetRequestCount(const uint256 &)
boost::signals2::signal< void(const CTransactionRef &)> TransactionAddedToMempool
std::unique_ptr< MainSignalsInstance > m_internals
virtual void BlockChecked(const CBlock &, const CValidationState &)
Notifies listeners of a block validation result.
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:251
boost::signals2::signal< void(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex, const std::vector< CTransactionRef > &)> BlockConnected
Definition: block.h:155
boost::signals2::signal< void(const uint256 &)> Inventory
virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman *connman)
Tells listeners to broadcast their data.
virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr< const CBlock > &block)
Notifies listeners that a block which builds directly on our current tip has been received and connec...
boost::signals2::signal< void(const CBlock &, const CValidationState &)> BlockChecked
void BlockFound(const uint256 &)
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
virtual void SetBestChain(const CBlockLocator &locator)
Notifies listeners of the new active block chain on-disk.
assert(len-trim+(2 *lenIndices)<=WIDTH)
void UnregisterAllValidationInterfaces()
Unregister all wallets from core.
void Inventory(const uint256 &)
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void Broadcast(int64_t nBestBlockTime, CConnman *connman)
void BlockChecked(const CBlock &, const CValidationState &)
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:437
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block)
Notifies listeners of a block being disconnected.
virtual void Inventory(const uint256 &hash)
Notifies listeners about an inventory item being seen on the network.
boost::signals2::signal< void(const CBlockLocator &)> SetBestChain
void BlockConnected(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex, const std::vector< CTransactionRef > &)
SingleThreadedSchedulerClient m_schedulerClient
MainSignalsInstance(CScheduler *pscheduler)
boost::signals2::signal< void(const CBlockIndex *, const std::shared_ptr< const CBlock > &)> NewPoWValidBlock
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
Notifies listeners of updated block chain tip.
CMainSignals & GetMainSignals()
Definition: net.h:120
virtual void GetScriptForMining(std::shared_ptr< CReserveScript > &coinbaseScript)
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once) ...
Capture information about block/transaction validation.
Definition: validation.h:27
256-bit opaque blob.
Definition: uint256.h:132
boost::signals2::signal< void(std::shared_ptr< CReserveScript > &)> ScriptForMining
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:177
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
boost::signals2::signal< void(const uint256 &)> BlockFound
boost::signals2::signal< void(const std::shared_ptr< const CBlock > &)> BlockDisconnected
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn)
Notifies listeners of a transaction having been added to mempool.
virtual void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex, const std::vector< CTransactionRef > &txnConflicted)
Notifies listeners of a block being connected.
void SetBestChain(const CBlockLocator &)
void BlockDisconnected(const std::shared_ptr< const CBlock > &)
void ScriptForMining(std::shared_ptr< CReserveScript > &coinbaseScript)
boost::signals2::signal< void(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)> UpdatedBlockTip
void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr< const CBlock > &)
boost::signals2::signal< void(int64_t nBestBlockTime, CConnman *connman)> Broadcast
void TransactionAddedToMempool(const CTransactionRef &)