PIVX Core  5.6.99
P2P Digital Currency
validationinterface.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2017-2021 The PIVX 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 #ifndef PIVX_VALIDATIONINTERFACE_H
8 #define PIVX_VALIDATIONINTERFACE_H
9 
10 #include "optional.h"
12 #include "primitives/transaction.h"
13 
14 #include <functional>
15 #include <memory>
16 
17 class CBlock;
18 struct CBlockLocator;
19 class CBlockIndex;
20 class CConnman;
24 class CValidationState;
25 class uint256;
26 class CScheduler;
27 enum class MemPoolRemovalReason;
28 
29 // These functions dispatch to one or all registered wallets
30 
37 
38 // Alternate registration functions that release a shared_ptr after the last
39 // notification is sent. These are useful for race-free cleanup, since
40 // unregistration is nonblocking and can return before the last notification is
41 // processed.
42 void RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface> pwalletIn);
43 void UnregisterSharedValidationInterface(std::shared_ptr<CValidationInterface> pwalletIn);
44 
54 void CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
65 
82 public:
83  virtual ~CValidationInterface() = default;
84  virtual void AcceptedBlockHeader(const CBlockIndex* pindexNew) {}
85 
86 protected:
96  virtual void UpdatedBlockTip(const CBlockIndex* pindexNew, const CBlockIndex* pindexFork, bool fInitialDownload) {}
102  virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
142  virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex) {}
148  virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const uint256& blockHash, int nBlockHeight, int64_t blockTime) {}
154  virtual void SetBestChain(const CBlockLocator &locator) {}
156  virtual void ResendWalletTransactions(CConnman* connman) {}
157  virtual void BlockChecked(const CBlock&, const CValidationState&) {}
158  friend void ::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface>);
162  virtual void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff) {}
163 };
164 
165 struct MainSignalsInstance;
167 private:
168  std::unique_ptr<MainSignalsInstance> m_internals;
169 
170  friend void ::RegisterSharedValidationInterface(std::shared_ptr<CValidationInterface>);
173  friend void ::CallFunctionInValidationInterfaceQueue(std::function<void ()> func);
174 
175 public:
182 
183  size_t CallbacksPending();
184 
185  void AcceptedBlockHeader(const CBlockIndex* pindexNew);
186  void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
187  void TransactionAddedToMempool(const CTransactionRef &ptxn);
189  void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex);
190  void BlockDisconnected(const std::shared_ptr<const CBlock> &block, const uint256& blockHash, int nBlockHeight, int64_t blockTime);
191  void SetBestChain(const CBlockLocator &);
192  void Broadcast(CConnman* connman);
193  void BlockChecked(const CBlock&, const CValidationState&);
194  void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList& oldMNList, const CDeterministicMNListDiff& diff);
195 };
196 
198 
199 #endif // PIVX_VALIDATIONINTERFACE_H
Definition: block.h:80
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:139
Definition: net.h:145
std::unique_ptr< MainSignalsInstance > m_internals
void SetBestChain(const CBlockLocator &)
void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload)
void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList &oldMNList, const CDeterministicMNListDiff &diff)
void UnregisterBackgroundSignalScheduler()
Unregister a CScheduler to give callbacks which should run in the background - these callbacks will n...
void AcceptedBlockHeader(const CBlockIndex *pindexNew)
void Broadcast(CConnman *connman)
void BlockChecked(const CBlock &, const CValidationState &)
void RegisterBackgroundSignalScheduler(CScheduler &scheduler)
Register a CScheduler to give callbacks which should run in the background (may only be called once)
void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const uint256 &blockHash, int nBlockHeight, int64_t blockTime)
void TransactionAddedToMempool(const CTransactionRef &ptxn)
void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
void FlushBackgroundCallbacks()
Call any remaining callbacks on the calling thread.
void TransactionRemovedFromMempool(const CTransactionRef &, MemPoolRemovalReason)
Implement this to subscribe to events generated in validation.
virtual void BlockDisconnected(const std::shared_ptr< const CBlock > &block, const uint256 &blockHash, int nBlockHeight, int64_t blockTime)
Notifies listeners of a block being disconnected.
virtual void ResendWalletTransactions(CConnman *connman)
Tells listeners to broadcast their data.
virtual ~CValidationInterface()=default
virtual void TransactionAddedToMempool(const CTransactionRef &ptxn)
Notifies listeners of a transaction having been added to mempool.
virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload)
Notifies listeners when the block chain tip advances.
virtual void TransactionRemovedFromMempool(const CTransactionRef &ptx, MemPoolRemovalReason reason)
Notifies listeners of a transaction leaving mempool.
virtual void NotifyMasternodeListChanged(bool undo, const CDeterministicMNList &oldMNList, const CDeterministicMNListDiff &diff)
Notifies listeners of updated deterministic masternode list.
virtual void SetBestChain(const CBlockLocator &locator)
Notifies listeners of the new active block chain on-disk.
virtual void BlockConnected(const std::shared_ptr< const CBlock > &block, const CBlockIndex *pindex)
Notifies listeners of a block being connected.
virtual void AcceptedBlockHeader(const CBlockIndex *pindexNew)
virtual void BlockChecked(const CBlock &, const CValidationState &)
Capture information about block/transaction validation.
Definition: validation.h:24
256-bit opaque blob.
Definition: uint256.h:138
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:154
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:456
MemPoolRemovalReason
Reason why a transaction was removed from the mempool, this is passed to the notification signal.
Definition: txmempool.h:295
CMainSignals & GetMainSignals()
void CallFunctionInValidationInterfaceQueue(std::function< void()> func)
Pushes a function to callback onto the notification queue, guaranteeing any callbacks generated prior...
void UnregisterValidationInterface(CValidationInterface *pwalletIn)
Unregister a wallet from core.
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > pwalletIn)
void UnregisterAllValidationInterfaces()
Unregister all wallets from core.
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > pwalletIn)
void RegisterValidationInterface(CValidationInterface *pwalletIn)
Register a wallet to receive updates from core.
void SyncWithValidationInterfaceQueue()
This is a synonym for the following, which asserts certain locks are not held: std::promise<void> pro...
CScheduler scheduler