BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
validationinterface.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2018 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 #ifndef BITCOIN_VALIDATIONINTERFACE_H
7 #define BITCOIN_VALIDATIONINTERFACE_H
8 
9 #include <primitives/transaction.h> // CTransaction(Ref)
10 #include <sync.h>
11 
12 #include <functional>
13 #include <memory>
14 
16 class CBlock;
17 class CBlockIndex;
18 struct CBlockLocator;
19 class CBlockIndex;
20 class CConnman;
21 class CReserveScript;
23 class CValidationState;
24 class uint256;
25 class CScheduler;
26 class CTxMemPool;
27 enum class MemPoolRemovalReason;
28 
29 // These functions dispatch to one or all registered wallets
30 
46 void CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
57 
74 protected:
79  ~CValidationInterface() = default;
89  virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {}
95  virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
106  virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx) {}
113  virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
119  virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block) {}
136  virtual void ChainStateFlushed(const CBlockLocator &locator) {}
138  virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
145  virtual void BlockChecked(const CBlock&, const CValidationState&) {}
149  virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {};
150 
151  virtual void BlockFound(const uint256 &hash) {};
152 
156 };
157 
158 struct MainSignalsInstance;
160 private:
161  std::unique_ptr<MainSignalsInstance> m_internals;
162 
166  friend void ::CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
167 
169 
170 public:
177 
178  size_t CallbacksPending();
179 
184 
185  void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
187  void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::shared_ptr<const std::vector<CTransactionRef>> &);
188  void BlockDisconnected(const std::shared_ptr<const CBlock> &);
189  void ChainStateFlushed(const CBlockLocator &);
190  void Broadcast(int64_t nBestBlockTime, CConnman* connman);
191  void BlockChecked(const CBlock&, const CValidationState&);
192  void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr<const CBlock>&);
193  void BlockFound(const uint256 &);
194 };
195 
197 
198 #endif // BITCOIN_VALIDATIONINTERFACE_H
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)
std::unique_ptr< MainSignalsInstance > m_internals
virtual void ChainStateFlushed(const CBlockLocator &locator)
Notifies listeners of the new active block chain on-disk.
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:128
CCriticalSection cs_main
Definition: validation.cpp:216
Definition: block.h:74
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...
void BlockFound(const uint256 &)
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal...
Definition: txmempool.h:345
void Broadcast(int64_t nBestBlockTime, CConnman *connman)
void BlockChecked(const CBlock &, const CValidationState &)
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:402
Implement this to subscribe to events generated in validation.
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block)
Notifies listeners of a block being disconnected.
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
void SyncWithValidationInterfaceQueue() LOCKS_EXCLUDED(cs_main)
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
Notifies listeners when the block chain tip advances.
void RegisterWithMempoolSignals(CTxMemPool &pool)
Register with mempool to call TransactionRemovedFromMempool callbacks.
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...
void UnregisterWithMempoolSignals(CTxMemPool &pool)
Unregister with mempool.
Definition: net.h:115
void ChainStateFlushed(const CBlockLocator &)
CMainSignals & GetMainSignals()
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) ...
Capture information about block/transaction validation.
Definition: validation.h:26
256-bit opaque blob.
Definition: uint256.h:122
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:441
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:50
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
void MempoolEntryRemoved(CTransactionRef tx, MemPoolRemovalReason reason)
void UnregisterAllValidationInterfaces()
Unregister all wallets from core.
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx)
Notifies listeners of a transaction leaving mempool.
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 BlockDisconnected(const std::shared_ptr< const CBlock > &)
void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr< const CBlock > &)
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void BlockConnected(const std::shared_ptr< const CBlock > &, const CBlockIndex *pindex, const std::shared_ptr< const std::vector< CTransactionRef >> &)
void TransactionAddedToMempool(const CTransactionRef &)