PIVX Core  5.6.99
P2P Digital Currency
blockstatecatcher.h
Go to the documentation of this file.
1 // Copyright (c) 2021 The PIVX Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or https://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef PIVX_UTIL_BLOCKSTATECATCHER_H
6 #define PIVX_UTIL_BLOCKSTATECATCHER_H
7 
8 #include "consensus/validation.h"
9 #include "validationinterface.h"
10 
15 {
16 public:
18  bool found;
20  explicit BlockStateCatcher(const uint256& hashIn) : hash(hashIn), found(false), state(){};
21  void setBlockHash(const uint256& _hash) { clear(); hash = _hash; }
22  void clear() { hash.SetNull(); found = false; state = CValidationState(); }
23  bool stateErrorFound() { return found && state.IsError(); }
24 
25 protected:
26  virtual void BlockChecked(const CBlock& block, const CValidationState& stateIn) {
27  if (block.GetHash() != hash) return;
28  found = true;
29  state = stateIn;
30  };
31 };
32 
34 {
35 private:
36  std::shared_ptr<BlockStateCatcher> stateCatcher = nullptr;
37  bool isRegistered = false;
38 
39 public:
40  explicit BlockStateCatcherWrapper(const uint256& hashIn)
41  {
42  stateCatcher = std::make_shared<BlockStateCatcher>(hashIn);
43  }
45  {
47  }
49  {
51  isRegistered = true;
52  }
54  {
55  return *stateCatcher;
56  }
57 };
58 
59 #endif // PIVX_UTIL_BLOCKSTATECATCHER_H
false
Definition: bls_dkg.cpp:151
Validation interface listener used to get feedback from ProcessNewBlock result.
void setBlockHash(const uint256 &_hash)
CValidationState state
virtual void BlockChecked(const CBlock &block, const CValidationState &stateIn)
BlockStateCatcher(const uint256 &hashIn)
BlockStateCatcherWrapper(const uint256 &hashIn)
BlockStateCatcher & get() const
std::shared_ptr< BlockStateCatcher > stateCatcher
uint256 GetHash() const
Definition: block.cpp:15
Definition: block.h:80
Implement this to subscribe to events generated in validation.
Capture information about block/transaction validation.
Definition: validation.h:24
bool IsError() const
Definition: validation.h:77
void SetNull()
Definition: uint256.h:44
256-bit opaque blob.
Definition: uint256.h:138
void RegisterSharedValidationInterface(std::shared_ptr< CValidationInterface > pwalletIn)
void UnregisterSharedValidationInterface(std::shared_ptr< CValidationInterface > pwalletIn)