LCOV - code coverage report
Current view: top level - src/rpc - evo_util.h (source / functions) Hit Total Coverage
Test: test_dash_coverage.info Lines: 0 25 0.0 %
Date: 2026-06-25 07:23:51 Functions: 0 11 0.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_RPC_EVO_UTIL_H
       6             : #define BITCOIN_RPC_EVO_UTIL_H
       7             : 
       8             : #include <netaddress.h>
       9             : #include <util/check.h>
      10             : 
      11             : #include <evo/dmn_types.h>
      12             : #include <evo/netinfo.h>
      13             : 
      14             : #include <cstdint>
      15             : #include <type_traits>
      16             : 
      17             : #include <univalue.h>
      18             : 
      19             : class CSimplifiedMNListEntry;
      20             : 
      21             : /** Process setting (legacy) Core network information field based on ProTx version */
      22             : template <typename ProTx>
      23             : void ProcessNetInfoCore(ProTx& ptx, const UniValue& input, const bool optional);
      24             : 
      25             : /** Process setting (legacy) Platform network information fields based on ProTx version */
      26             : template <typename ProTx>
      27             : void ProcessNetInfoPlatform(ProTx& ptx, const UniValue& input_p2p, const UniValue& input_http, const bool optional);
      28             : 
      29             : /** Reads network info reporting and appends data from legacy fields if applicable */
      30             : template <typename Obj>
      31           0 : UniValue GetNetInfoWithLegacyFields(const Obj& obj, const MnType& type)
      32             : {
      33           0 :     UniValue ret{CHECK_NONFATAL(obj.netInfo)->ToJson()};
      34             : 
      35             :     // Nothing to do here if not EvoNode, netInfo is empty or netInfo is capable of natively
      36             :     // storing Platform fields
      37           0 :     if (type != MnType::Evo || obj.netInfo->IsEmpty() || obj.netInfo->CanStorePlatform()) return ret;
      38             : 
      39           0 :     CNetAddr addr{obj.netInfo->GetPrimary()};
      40           0 :     ret.pushKV(PurposeToString(NetInfoPurpose::PLATFORM_HTTPS).data(),
      41           0 :                ArrFromService(CService(addr, obj.platformHTTPPort)));
      42             : 
      43             :     if constexpr (!std::is_same_v<std::decay_t<Obj>, CSimplifiedMNListEntry>) {
      44             :         // CSimplifiedMNListEntry doesn't store platformP2PPort
      45           0 :         ret.pushKV(PurposeToString(NetInfoPurpose::PLATFORM_P2P).data(),
      46           0 :                    ArrFromService(CService(addr, obj.platformP2PPort)));
      47             :     }
      48             : 
      49           0 :     return ret;
      50           0 : }
      51             : 
      52             : /** Returns platform port based on purpose and network info version */
      53             : template <bool is_p2p, typename Obj>
      54           0 : int32_t GetPlatformPort(const Obj& obj)
      55             : {
      56             :     // Currently, there is nothing that prevents PLATFORM_{HTTPS,P2P} to be registered to
      57             :     // an addr *different* from the primary addr for CORE_P2P. This breaks the assumptions
      58             :     // under which platform{HTTP,P2P}Port operate under (i.e. all three are hosted with the
      59             :     // same addr).
      60             :     //
      61             :     // TODO: Introduce restrictions that enforce this assumption *until* we remove legacy
      62             :     //       fields for good.
      63             :     //
      64           0 :     bool is_legacy{!(CHECK_NONFATAL(obj.netInfo)->CanStorePlatform())};
      65             :     if constexpr (is_p2p) {
      66             :         static_assert(!std::is_same_v<std::decay_t<Obj>, CSimplifiedMNListEntry>,
      67             :                       "CSimplifiedMNListEntry doesn't have platformP2PPort");
      68           0 :         if (is_legacy) {
      69           0 :             return obj.platformP2PPort;
      70             :         }
      71           0 :         if (obj.netInfo->IsEmpty()) {
      72           0 :             return -1; // Blank entry, nothing to report
      73             :         }
      74           0 :         CHECK_NONFATAL(obj.netInfo->HasEntries(NetInfoPurpose::PLATFORM_P2P));
      75           0 :         return obj.netInfo->GetEntries(NetInfoPurpose::PLATFORM_P2P)[0].GetPort();
      76             :     } else {
      77           0 :         if (is_legacy) {
      78           0 :             return obj.platformHTTPPort;
      79             :         }
      80           0 :         if (obj.netInfo->IsEmpty()) {
      81           0 :             return -1; // Blank entry, nothing to report
      82             :         }
      83           0 :         CHECK_NONFATAL(obj.netInfo->HasEntries(NetInfoPurpose::PLATFORM_HTTPS));
      84           0 :         return obj.netInfo->GetEntries(NetInfoPurpose::PLATFORM_HTTPS)[0].GetPort();
      85             :     }
      86           0 : }
      87             : 
      88             : #endif // BITCOIN_RPC_EVO_UTIL_H

Generated by: LCOV version 1.16