LCOV - code coverage report
Current view: top level - src/llmq - signhash.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 2 2 100.0 %
Date: 2026-06-25 07:23:43 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2025 The Dash 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_LLMQ_SIGNHASH_H
       6             : #define BITCOIN_LLMQ_SIGNHASH_H
       7             : 
       8             : #include <llmq/params.h>
       9             : #include <uint256.h>
      10             : 
      11             : #include <cstring>
      12             : #include <vector>
      13             : 
      14             : #include <saltedhasher.h>
      15             : #include <util/hash_type.h>
      16             : 
      17             : namespace llmq {
      18             : 
      19             : /**
      20             :  * SignHash is a strongly-typed wrapper for the hash used in LLMQ signing operations.
      21             :  * It encapsulates the hash calculation for quorum signatures, replacing the need for
      22             :  * BuildSignHash function and avoiding circular dependencies.
      23             :  */
      24             : class SignHash : public BaseHash<uint256>
      25             : {
      26             : public:
      27      133650 :     SignHash() = default;
      28             :     using BaseHash<uint256>::BaseHash;
      29             : 
      30             :     /**
      31             :      * Constructs a SignHash from the given parameters.
      32             :      * This replaces the previous BuildSignHash function.
      33             :      */
      34             :     SignHash(Consensus::LLMQType llmqType, const uint256& quorumHash, const uint256& id, const uint256& msgHash);
      35             : 
      36             :     /**
      37             :      * Get the underlying uint256 hash value.
      38             :      */
      39      260180 :     const uint256& Get() const { return m_hash; }
      40             : 
      41             :     // Serialization support
      42             :     template <typename Stream>
      43             :     void Serialize(Stream& s) const
      44             :     {
      45             :         s << m_hash;
      46             :     }
      47             : 
      48             :     template <typename Stream>
      49             :     void Unserialize(Stream& s)
      50             :     {
      51             :         s >> m_hash;
      52             :     }
      53             : };
      54             : 
      55             : // Salted hasher for llmq::SignHash that reuses the salted hasher for uint256
      56             : struct SignHashSaltedHasher {
      57             :     std::size_t operator()(const SignHash& signHash) const noexcept { return StaticSaltedHasher{}(signHash.Get()); }
      58             : };
      59             : 
      60             : } // namespace llmq
      61             : 
      62             : // Make SignHash hashable for use in unordered_map
      63             : template <>
      64             : struct std::hash<llmq::SignHash> {
      65             :     std::size_t operator()(const llmq::SignHash& signHash) const noexcept
      66             :     {
      67             :         // Use the first 8 bytes of the hash as the hash value
      68             :         const unsigned char* data = signHash.data();
      69             :         std::size_t result;
      70             :         std::memcpy(&result, data, sizeof(result));
      71             :         return result;
      72             :     }
      73             : };
      74             : 
      75             : 
      76             : #endif // BITCOIN_LLMQ_SIGNHASH_H

Generated by: LCOV version 1.16