You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

validationinterface.h 4.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. // Copyright (c) 2009-2010 Satoshi Nakamoto
  2. // Copyright (c) 2009-2016 The Starwels developers
  3. // Distributed under the MIT software license, see the accompanying
  4. // file COPYING or http://www.opensource.org/licenses/mit-license.php.
  5. #ifndef STARWELS_VALIDATIONINTERFACE_H
  6. #define STARWELS_VALIDATIONINTERFACE_H
  7. #include <memory>
  8. #include "primitives/transaction.h" // CTransaction(Ref)
  9. class CBlock;
  10. class CBlockIndex;
  11. struct CBlockLocator;
  12. class CBlockIndex;
  13. class CConnman;
  14. class CReserveScript;
  15. class CValidationInterface;
  16. class CValidationState;
  17. class uint256;
  18. class CScheduler;
  19. // These functions dispatch to one or all registered wallets
  20. /** Register a wallet to receive updates from core */
  21. void RegisterValidationInterface(CValidationInterface* pwalletIn);
  22. /** Unregister a wallet from core */
  23. void UnregisterValidationInterface(CValidationInterface* pwalletIn);
  24. /** Unregister all wallets from core */
  25. void UnregisterAllValidationInterfaces();
  26. class CValidationInterface {
  27. protected:
  28. /** Notifies listeners of updated block chain tip */
  29. virtual void UpdatedBlockTip(const CBlockIndex *pindexNew, const CBlockIndex *pindexFork, bool fInitialDownload) {}
  30. /** Notifies listeners of a transaction having been added to mempool. */
  31. virtual void TransactionAddedToMempool(const CTransactionRef &ptxn) {}
  32. /**
  33. * Notifies listeners of a block being connected.
  34. * Provides a vector of transactions evicted from the mempool as a result.
  35. */
  36. virtual void BlockConnected(const std::shared_ptr<const CBlock> &block, const CBlockIndex *pindex, const std::vector<CTransactionRef> &txnConflicted) {}
  37. /** Notifies listeners of a block being disconnected */
  38. virtual void BlockDisconnected(const std::shared_ptr<const CBlock> &block) {}
  39. /** Notifies listeners of the new active block chain on-disk. */
  40. virtual void SetBestChain(const CBlockLocator &locator) {}
  41. /** Notifies listeners about an inventory item being seen on the network. */
  42. virtual void Inventory(const uint256 &hash) {}
  43. /** Tells listeners to broadcast their data. */
  44. virtual void ResendWalletTransactions(int64_t nBestBlockTime, CConnman* connman) {}
  45. /**
  46. * Notifies listeners of a block validation result.
  47. * If the provided CValidationState IsValid, the provided block
  48. * is guaranteed to be the current best block at the time the
  49. * callback was generated (not necessarily now)
  50. */
  51. virtual void BlockChecked(const CBlock&, const CValidationState&) {}
  52. /**
  53. * Notifies listeners that a block which builds directly on our current tip
  54. * has been received and connected to the headers tree, though not validated yet */
  55. virtual void NewPoWValidBlock(const CBlockIndex *pindex, const std::shared_ptr<const CBlock>& block) {};
  56. friend void ::RegisterValidationInterface(CValidationInterface*);
  57. friend void ::UnregisterValidationInterface(CValidationInterface*);
  58. friend void ::UnregisterAllValidationInterfaces();
  59. };
  60. struct MainSignalsInstance;
  61. class CMainSignals {
  62. private:
  63. std::unique_ptr<MainSignalsInstance> m_internals;
  64. friend void ::RegisterValidationInterface(CValidationInterface*);
  65. friend void ::UnregisterValidationInterface(CValidationInterface*);
  66. friend void ::UnregisterAllValidationInterfaces();
  67. public:
  68. /** Register a CScheduler to give callbacks which should run in the background (may only be called once) */
  69. void RegisterBackgroundSignalScheduler(CScheduler& scheduler);
  70. /** Unregister a CScheduler to give callbacks which should run in the background - these callbacks will now be dropped! */
  71. void UnregisterBackgroundSignalScheduler();
  72. /** Call any remaining callbacks on the calling thread */
  73. void FlushBackgroundCallbacks();
  74. void UpdatedBlockTip(const CBlockIndex *, const CBlockIndex *, bool fInitialDownload);
  75. void TransactionAddedToMempool(const CTransactionRef &);
  76. void BlockConnected(const std::shared_ptr<const CBlock> &, const CBlockIndex *pindex, const std::vector<CTransactionRef> &);
  77. void BlockDisconnected(const std::shared_ptr<const CBlock> &);
  78. void SetBestChain(const CBlockLocator &);
  79. void Inventory(const uint256 &);
  80. void Broadcast(int64_t nBestBlockTime, CConnman* connman);
  81. void BlockChecked(const CBlock&, const CValidationState&);
  82. void NewPoWValidBlock(const CBlockIndex *, const std::shared_ptr<const CBlock>&);
  83. };
  84. CMainSignals& GetMainSignals();
  85. #endif // STARWELS_VALIDATIONINTERFACE_H