/tmp/bitcoin/src/node/block_validation_state_catcher.h
Line | Count | Source |
1 | | // Copyright (c) 2021-present The Bitcoin Core developers |
2 | | // Distributed under the MIT software license, see the accompanying |
3 | | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | | |
5 | | #ifndef BITCOIN_NODE_BLOCK_VALIDATION_STATE_CATCHER_H |
6 | | #define BITCOIN_NODE_BLOCK_VALIDATION_STATE_CATCHER_H |
7 | | |
8 | | #include <consensus/validation.h> |
9 | | #include <validationinterface.h> |
10 | | |
11 | | #include <memory> |
12 | | #include <optional> |
13 | | |
14 | | namespace node { |
15 | | |
16 | | /** Captures the validation state reported for a specific block. |
17 | | * Callers manage registration and unregistration with ValidationSignals. |
18 | | */ |
19 | | class BlockValidationStateCatcher final : public CValidationInterface |
20 | | { |
21 | | private: |
22 | | uint256 m_hash; |
23 | | |
24 | | public: |
25 | | std::optional<BlockValidationState> m_state; |
26 | 7.41k | explicit BlockValidationStateCatcher(const uint256& hash) : m_hash(hash) {}; |
27 | | |
28 | | protected: |
29 | | void BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state) override |
30 | 7.20k | { |
31 | 7.20k | if (block->GetHash() == m_hash) m_state = state; |
32 | 7.20k | } |
33 | | }; |
34 | | |
35 | | } // namespace node |
36 | | |
37 | | #endif // BITCOIN_NODE_BLOCK_VALIDATION_STATE_CATCHER_H |