LCOV - code coverage report
Current view: top level - src/evo - simplifiedmns.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 38 39 97.4 %
Date: 2026-06-25 07:23:43 Functions: 20 27 74.1 %

          Line data    Source code
       1             : // Copyright (c) 2017-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_EVO_SIMPLIFIEDMNS_H
       6             : #define BITCOIN_EVO_SIMPLIFIEDMNS_H
       7             : 
       8             : #include <bls/bls.h>
       9             : #include <evo/dmn_types.h>
      10             : #include <evo/netinfo.h>
      11             : #include <evo/providertx.h>
      12             : #include <util/helpers.h>
      13             : 
      14             : #include <merkleblock.h>
      15             : #include <netaddress.h>
      16             : #include <pubkey.h>
      17             : 
      18             : #include <gsl/pointers.h>
      19             : 
      20             : #include <memory>
      21             : #include <vector>
      22             : 
      23             : struct RPCResult;
      24             : 
      25             : class UniValue;
      26             : 
      27       51640 : class CSimplifiedMNListEntry
      28             : {
      29             : public:
      30             :     uint256 proRegTxHash;
      31             :     uint256 confirmedHash;
      32          15 :     std::shared_ptr<NetInfoInterface> netInfo{nullptr};
      33             :     CBLSLazyPublicKey pubKeyOperator;
      34             :     CKeyID keyIDVoting;
      35          15 :     bool isValid{false};
      36          15 :     uint16_t platformHTTPPort{0};
      37          15 :     uint160 platformNodeID{};
      38             :     CScript scriptPayout; // mem-only
      39             :     CScript scriptOperatorPayout; // mem-only
      40          15 :     uint16_t nVersion{ProTxVersion::LegacyBLS};
      41          15 :     MnType nType{MnType::Regular};
      42             : 
      43          60 :     CSimplifiedMNListEntry() = default;
      44             :     CSimplifiedMNListEntry(const uint256& proreg_tx_hash, const uint256& confirmed_hash,
      45             :                            const std::shared_ptr<NetInfoInterface>& net_info, const CBLSLazyPublicKey& pubkey_operator,
      46             :                            const CKeyID& keyid_voting, bool is_valid, uint16_t platform_http_port,
      47             :                            const uint160& platform_node_id, const CScript& script_payout,
      48             :                            const CScript& script_operator_payout, uint16_t version, MnType type);
      49             : 
      50      548069 :     bool operator==(const CSimplifiedMNListEntry& rhs) const
      51             :     {
      52     1095942 :         return proRegTxHash == rhs.proRegTxHash &&
      53      547873 :                confirmedHash == rhs.confirmedHash &&
      54      543749 :                util::shared_ptr_equal(netInfo, rhs.netInfo) &&
      55      540743 :                pubKeyOperator == rhs.pubKeyOperator &&
      56      540735 :                keyIDVoting == rhs.keyIDVoting &&
      57      540699 :                isValid == rhs.isValid &&
      58      540092 :                nVersion == rhs.nVersion &&
      59      540092 :                nType == rhs.nType &&
      60      540092 :                platformHTTPPort == rhs.platformHTTPPort &&
      61      539806 :                platformNodeID == rhs.platformNodeID;
      62             :     }
      63             : 
      64      295784 :     bool operator!=(const CSimplifiedMNListEntry& rhs) const
      65             :     {
      66      295784 :         return !(rhs == *this);
      67             :     }
      68             : 
      69      123663 :     SERIALIZE_METHODS(CSimplifiedMNListEntry, obj)
      70             :     {
      71       41221 :         if ((s.GetType() & SER_NETWORK) && s.GetVersion() >= SMNLE_VERSIONED_PROTO_VERSION) {
      72          80 :             READWRITE(
      73             :                 obj.nVersion);
      74          80 :         }
      75       41221 :         READWRITE(
      76             :                 obj.proRegTxHash,
      77             :                 obj.confirmedHash,
      78             :                 NetInfoSerWrapper(const_cast<std::shared_ptr<NetInfoInterface>&>(obj.netInfo),
      79             :                                   obj.nVersion >= ProTxVersion::ExtAddr),
      80             :                 CBLSLazyPublicKeyVersionWrapper(const_cast<CBLSLazyPublicKey&>(obj.pubKeyOperator), (obj.nVersion == ProTxVersion::LegacyBLS)),
      81             :                 obj.keyIDVoting,
      82             :                 obj.isValid);
      83       41221 :         if ((s.GetType() & SER_NETWORK) && s.GetVersion() < DMN_TYPE_PROTO_VERSION) {
      84           0 :             return;
      85             :         }
      86       41221 :         if (obj.nVersion >= ProTxVersion::BasicBLS) {
      87       37472 :             READWRITE(
      88             :                 obj.nType);
      89       37472 :             if (obj.nType == MnType::Evo) {
      90        1332 :                 if (obj.nVersion < ProTxVersion::ExtAddr) {
      91        1254 :                 READWRITE(
      92             :                 obj.platformHTTPPort);
      93        1254 :                 }
      94        1332 :                 READWRITE(
      95             :                 obj.platformNodeID);
      96        1332 :             }
      97       37472 :         }
      98       41221 :     }
      99             : 
     100             :     uint256 CalcHash() const;
     101             : 
     102             :     [[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional);
     103             :     std::string ToString() const;
     104             :     [[nodiscard]] UniValue ToJson(bool extended = false) const;
     105             : };
     106             : 
     107             : class CSimplifiedMNList
     108             : {
     109             : public:
     110             :     std::vector<std::unique_ptr<CSimplifiedMNListEntry>> mnList;
     111             : 
     112        1788 :     CSimplifiedMNList() = default;
     113             : 
     114             :     // This constructor from std::vector is used in unit-tests
     115             :     explicit CSimplifiedMNList(std::vector<std::unique_ptr<CSimplifiedMNListEntry>>&& smlEntries);
     116             : 
     117             :     uint256 CalcMerkleRoot(bool* pmutated = nullptr) const;
     118             :     bool operator==(const CSimplifiedMNList& rhs) const;
     119             : };
     120             : 
     121             : bool CalcCbTxMerkleRootMNList(uint256& merkleRootRet, gsl::not_null<std::shared_ptr<const CSimplifiedMNList>> sml,
     122             :                               BlockValidationState& state);
     123             : 
     124             : #endif // BITCOIN_EVO_SIMPLIFIEDMNS_H

Generated by: LCOV version 1.16