Raven Core  3.0.0
P2P Digital Currency
validationinterface.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Copyright (c) 2017-2019 The Raven Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #include "validationinterface.h"
8 
9 #include "init.h"
10 #include "primitives/block.h"
11 #include "scheduler.h"
12 #include "sync.h"
13 #include "util.h"
14 
15 #include <list>
16 #include <atomic>
17 
18 #include <boost/signals2/signal.hpp>
19 
21  boost::signals2::signal<void (const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)> UpdatedBlockTip;
22  boost::signals2::signal<void (const CTransactionRef &)> TransactionAddedToMempool;
23  boost::signals2::signal<void (const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef>&)> BlockConnected;
24  boost::signals2::signal<void (const std::shared_ptr<const CBlock> &)> BlockDisconnected;
25  boost::signals2::signal<void (const CBlockLocator &)> SetBestChain;
26  boost::signals2::signal<void (const uint256 &)> Inventory;
27  boost::signals2::signal<void (int64_t nBestBlockTime, CConnman* connman)> Broadcast;
28  boost::signals2::signal<void (const CBlock&, const CValidationState&)> BlockChecked;
29  boost::signals2::signal<void (const CBlockIndex *, const std::shared_ptr<const CBlock>&)> NewPoWValidBlock;
30  boost::signals2::signal<void (const uint256 &)> BlockFound;
31  boost::signals2::signal<void (const CMessage &)> NewAssetMessage;
32  boost::signals2::signal<void (const std::string &)> AssetInventory;
33 // boost::signals2::signal<void (std::shared_ptr<CReserveScript>&)> ScriptForMining;
34 
35  // We are not allowed to assume the scheduler only runs in one thread,
36  // but must ensure all callbacks happen in-order, so we end up creating
37  // our own queue here :(
39 
40  explicit MainSignalsInstance(CScheduler *pscheduler) : m_schedulerClient(pscheduler) {}
41 };
42 
43 static CMainSignals g_signals;
44 
46  assert(!m_internals);
47  m_internals.reset(new MainSignalsInstance(&scheduler));
48 }
49 
51  m_internals.reset(nullptr);
52 }
53 
55  m_internals->m_schedulerClient.EmptyQueue();
56 }
57 
59 {
60  return g_signals;
61 }
62 
64  g_signals.m_internals->UpdatedBlockTip.connect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
65  g_signals.m_internals->TransactionAddedToMempool.connect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
66  g_signals.m_internals->BlockConnected.connect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
67  g_signals.m_internals->BlockDisconnected.connect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
68  g_signals.m_internals->SetBestChain.connect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
69  g_signals.m_internals->Inventory.connect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
70  g_signals.m_internals->Broadcast.connect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
71  g_signals.m_internals->BlockChecked.connect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
72  g_signals.m_internals->NewPoWValidBlock.connect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
73  g_signals.m_internals->BlockFound.connect(boost::bind(&CValidationInterface::BlockFound, pwalletIn, _1));
74  g_signals.m_internals->NewAssetMessage.connect(boost::bind(&CValidationInterface::NewAssetMessage, pwalletIn, _1));
75 // g_signals.m_internals->ScriptForMining.connect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
76 }
77 
79  g_signals.m_internals->BlockChecked.disconnect(boost::bind(&CValidationInterface::BlockChecked, pwalletIn, _1, _2));
80  g_signals.m_internals->Broadcast.disconnect(boost::bind(&CValidationInterface::ResendWalletTransactions, pwalletIn, _1, _2));
81  g_signals.m_internals->Inventory.disconnect(boost::bind(&CValidationInterface::Inventory, pwalletIn, _1));
82  g_signals.m_internals->SetBestChain.disconnect(boost::bind(&CValidationInterface::SetBestChain, pwalletIn, _1));
83  g_signals.m_internals->TransactionAddedToMempool.disconnect(boost::bind(&CValidationInterface::TransactionAddedToMempool, pwalletIn, _1));
84  g_signals.m_internals->BlockConnected.disconnect(boost::bind(&CValidationInterface::BlockConnected, pwalletIn, _1, _2, _3));
85  g_signals.m_internals->BlockDisconnected.disconnect(boost::bind(&CValidationInterface::BlockDisconnected, pwalletIn, _1));
86  g_signals.m_internals->UpdatedBlockTip.disconnect(boost::bind(&CValidationInterface::UpdatedBlockTip, pwalletIn, _1, _2, _3));
87  g_signals.m_internals->NewPoWValidBlock.disconnect(boost::bind(&CValidationInterface::NewPoWValidBlock, pwalletIn, _1, _2));
88  g_signals.m_internals->BlockFound.disconnect(boost::bind(&CValidationInterface::BlockFound, pwalletIn, _1));
89  g_signals.m_internals->NewAssetMessage.disconnect(boost::bind(&CValidationInterface::NewAssetMessage, pwalletIn, _1));
90 // g_signals.m_internals->ScriptForMining.disconnect(boost::bind(&CValidationInterface::GetScriptForMining, pwalletIn, _1));
91 }
92 
94  g_signals.m_internals->BlockChecked.disconnect_all_slots();
95  g_signals.m_internals->Broadcast.disconnect_all_slots();
96  g_signals.m_internals->Inventory.disconnect_all_slots();
97  g_signals.m_internals->SetBestChain.disconnect_all_slots();
98  g_signals.m_internals->TransactionAddedToMempool.disconnect_all_slots();
99  g_signals.m_internals->BlockConnected.disconnect_all_slots();
100  g_signals.m_internals->BlockDisconnected.disconnect_all_slots();
101  g_signals.m_internals->UpdatedBlockTip.disconnect_all_slots();
102  g_signals.m_internals->NewPoWValidBlock.disconnect_all_slots();
103  g_signals.m_internals->BlockFound.disconnect_all_slots();
104  g_signals.m_internals->NewAssetMessage.disconnect_all_slots();
105 // g_signals.m_internals->ScriptForMining.disconnect_all_slots();
106 }
107 
108 void CMainSignals::UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {
109  m_internals->UpdatedBlockTip(pindexNew, pindexFork, fInitialDownload);
110 }
111 
113  m_internals->TransactionAddedToMempool(ptx);
114 }
115 
116 void CMainSignals::BlockConnected(const std::shared_ptr<const CBlock> &pblock, const CBlockIndex *pindex, const std::vector<CTransactionRef>& vtxConflicted) {
117  m_internals->BlockConnected(pblock, pindex, vtxConflicted);
118 }
119 
120 void CMainSignals::BlockDisconnected(const std::shared_ptr<const CBlock> &pblock) {
121  m_internals->BlockDisconnected(pblock);
122 }
123 
125  m_internals->SetBestChain(locator);
126 }
127 
128 void CMainSignals::Inventory(const uint256 &hash) {
129  m_internals->Inventory(hash);
130 }
131 
132 void CMainSignals::Broadcast(int64_t nBestBlockTime, CConnman* connman) {
133  m_internals->Broadcast(nBestBlockTime, connman);
134 }
135 
136 void CMainSignals::BlockChecked(const CBlock& block, const CValidationState& state) {
137  m_internals->BlockChecked(block, state);
138 }
139 
140 void CMainSignals::NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock> &block) {
141  m_internals->NewPoWValidBlock(pindex, block);
142 }
143 
145  m_internals->BlockFound(hash);
146 }
147 
149  m_internals->NewAssetMessage(message);
150 }
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:94
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:132
boost::signals2::signal< void(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex, const std::vector< CTransactionRef > &)> BlockConnected
Definition: block.h:73
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 NewAssetMessage(const CMessage &)
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.
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:436
virtual void NewAssetMessage(const CMessage &message)
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
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
virtual void BlockFound(const uint256 &hash)
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once) ...
RVN END.
Definition: validation.h:30
256-bit opaque blob.
Definition: uint256.h:123
boost::signals2::signal< void(const std::string &)> AssetInventory
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:172
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
boost::signals2::signal< void(const uint256 &)> BlockFound
boost::signals2::signal< void(const CMessage &)> NewAssetMessage
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 > &)
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 &)