Branch data Line data Source code
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 [ + - ]: 477231 : explicit BlockValidationStateCatcher(const uint256& hash) : m_hash(hash) {};
27 : :
28 : : protected:
29 : 477231 : void BlockChecked(const std::shared_ptr<const CBlock>& block, const BlockValidationState& state) override
30 : : {
31 [ + - ]: 477231 : if (block->GetHash() == m_hash) m_state = state;
32 : 477231 : }
33 : : };
34 : :
35 : : } // namespace node
36 : :
37 : : #endif // BITCOIN_NODE_BLOCK_VALIDATION_STATE_CATCHER_H
|