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 826 : 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 22215 : bool operator==(const CSimplifiedMNListEntry& rhs) const 51 : { 52 44430 : return proRegTxHash == rhs.proRegTxHash && 53 22215 : confirmedHash == rhs.confirmedHash && 54 22113 : util::shared_ptr_equal(netInfo, rhs.netInfo) && 55 22096 : pubKeyOperator == rhs.pubKeyOperator && 56 22088 : keyIDVoting == rhs.keyIDVoting && 57 22088 : isValid == rhs.isValid && 58 22088 : nVersion == rhs.nVersion && 59 22088 : nType == rhs.nType && 60 22088 : platformHTTPPort == rhs.platformHTTPPort && 61 22088 : platformNodeID == rhs.platformNodeID; 62 : } 63 : 64 8174 : bool operator!=(const CSimplifiedMNListEntry& rhs) const 65 : { 66 8174 : return !(rhs == *this); 67 : } 68 : 69 1224 : SERIALIZE_METHODS(CSimplifiedMNListEntry, obj) 70 : { 71 408 : if ((s.GetType() & SER_NETWORK) && s.GetVersion() >= SMNLE_VERSIONED_PROTO_VERSION) { 72 0 : READWRITE( 73 : obj.nVersion); 74 0 : } 75 408 : 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 408 : if ((s.GetType() & SER_NETWORK) && s.GetVersion() < DMN_TYPE_PROTO_VERSION) { 84 0 : return; 85 : } 86 408 : if (obj.nVersion >= ProTxVersion::BasicBLS) { 87 373 : READWRITE( 88 : obj.nType); 89 373 : if (obj.nType == MnType::Evo) { 90 0 : if (obj.nVersion < ProTxVersion::ExtAddr) { 91 0 : READWRITE( 92 : obj.platformHTTPPort); 93 0 : } 94 0 : READWRITE( 95 : obj.platformNodeID); 96 0 : } 97 373 : } 98 408 : } 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 6 : 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