1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 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.
6 #ifndef BITCOIN_VALIDATIONINTERFACE_H
7 #define BITCOIN_VALIDATIONINTERFACE_H
11 #include "primitives/transaction.h" // CTransaction(Ref)
19 class CValidationInterface
;
20 class CValidationState
;
24 // These functions dispatch to one or all registered wallets
26 /** Register a wallet to receive updates from core */
27 void RegisterValidationInterface(CValidationInterface
* pwalletIn
);
28 /** Unregister a wallet from core */
29 void UnregisterValidationInterface(CValidationInterface
* pwalletIn
);
30 /** Unregister all wallets from core */
31 void UnregisterAllValidationInterfaces();
33 class CValidationInterface
{
35 /** Notifies listeners of updated block chain tip */
36 virtual void UpdatedBlockTip(const CBlockIndex
*pindexNew
, const CBlockIndex
*pindexFork
, bool fInitialDownload
) {}
37 /** Notifies listeners of a transaction having been added to mempool. */
38 virtual void TransactionAddedToMempool(const CTransactionRef
&ptxn
) {}
40 * Notifies listeners of a block being connected.
41 * Provides a vector of transactions evicted from the mempool as a result.
43 virtual void BlockConnected(const std::shared_ptr
<const CBlock
> &block
, const CBlockIndex
*pindex
, const std::vector
<CTransactionRef
> &txnConflicted
) {}
44 /** Notifies listeners of a block being disconnected */
45 virtual void BlockDisconnected(const std::shared_ptr
<const CBlock
> &block
) {}
46 /** Notifies listeners of the new active block chain on-disk. */
47 virtual void SetBestChain(const CBlockLocator
&locator
) {}
48 /** Notifies listeners about an inventory item being seen on the network. */
49 virtual void Inventory(const uint256
&hash
) {}
50 /** Tells listeners to broadcast their data. */
51 virtual void ResendWalletTransactions(int64_t nBestBlockTime
, CConnman
* connman
) {}
53 * Notifies listeners of a block validation result.
54 * If the provided CValidationState IsValid, the provided block
55 * is guaranteed to be the current best block at the time the
56 * callback was generated (not necessarily now)
58 virtual void BlockChecked(const CBlock
&, const CValidationState
&) {}
60 * Notifies listeners that a block which builds directly on our current tip
61 * has been received and connected to the headers tree, though not validated yet */
62 virtual void NewPoWValidBlock(const CBlockIndex
*pindex
, const std::shared_ptr
<const CBlock
>& block
) {};
63 friend void ::RegisterValidationInterface(CValidationInterface
*);
64 friend void ::UnregisterValidationInterface(CValidationInterface
*);
65 friend void ::UnregisterAllValidationInterfaces();
68 struct MainSignalsInstance
;
71 std::unique_ptr
<MainSignalsInstance
> m_internals
;
73 friend void ::RegisterValidationInterface(CValidationInterface
*);
74 friend void ::UnregisterValidationInterface(CValidationInterface
*);
75 friend void ::UnregisterAllValidationInterfaces();
78 /** Register a CScheduler to give callbacks which should run in the background (may only be called once) */
79 void RegisterBackgroundSignalScheduler(CScheduler
& scheduler
);
80 /** Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */
81 void UnregisterBackgroundSignalScheduler();
82 /** Call any remaining callbacks on the calling thread */
83 void FlushBackgroundCallbacks();
85 void UpdatedBlockTip(const CBlockIndex
*, const CBlockIndex
*, bool fInitialDownload
);
86 void TransactionAddedToMempool(const CTransactionRef
&);
87 void BlockConnected(const std::shared_ptr
<const CBlock
> &, const CBlockIndex
*pindex
, const std::vector
<CTransactionRef
> &);
88 void BlockDisconnected(const std::shared_ptr
<const CBlock
> &);
89 void SetBestChain(const CBlockLocator
&);
90 void Inventory(const uint256
&);
91 void Broadcast(int64_t nBestBlockTime
, CConnman
* connman
);
92 void BlockChecked(const CBlock
&, const CValidationState
&);
93 void NewPoWValidBlock(const CBlockIndex
*, const std::shared_ptr
<const CBlock
>&);
96 CMainSignals
& GetMainSignals();
98 #endif // BITCOIN_VALIDATIONINTERFACE_H