LCOV - code coverage report
Current view: top level - src/evo - dmnstate.cpp (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 87 117 74.4 %
Date: 2026-06-25 07:23:43 Functions: 3 3 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2018-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             : #include <evo/dmnstate.h>
       6             : 
       7             : #include <evo/netinfo.h>
       8             : #include <script/standard.h>
       9             : #include <univalue.h>
      10             : 
      11         898 : std::string CDeterministicMNState::ToString() const
      12             : {
      13         898 :     CTxDestination dest;
      14         898 :     std::string payoutAddress = "unknown";
      15         898 :     std::string operatorPayoutAddress = "none";
      16         898 :     if (ExtractDestination(scriptPayout, dest)) {
      17         898 :         payoutAddress = EncodeDestination(dest);
      18         898 :     }
      19         898 :     if (ExtractDestination(scriptOperatorPayout, dest)) {
      20         345 :         operatorPayoutAddress = EncodeDestination(dest);
      21         345 :     }
      22             : 
      23         898 :     return strprintf("CDeterministicMNState(nVersion=%d, nRegisteredHeight=%d, nLastPaidHeight=%d, nPoSePenalty=%d, "
      24             :                      "nPoSeRevivedHeight=%d, nPoSeBanHeight=%d, nRevocationReason=%d, "
      25             :                      "ownerAddress=%s, pubKeyOperator=%s, votingAddress=%s, netInfo=%s, payoutAddress=%s, "
      26             :                      "operatorPayoutAddress=%s)\n",
      27         898 :                      nVersion, nRegisteredHeight, nLastPaidHeight, nPoSePenalty, nPoSeRevivedHeight, nPoSeBanHeight,
      28         898 :                      nRevocationReason, EncodeDestination(PKHash(keyIDOwner)), pubKeyOperator.ToString(),
      29         898 :                      EncodeDestination(PKHash(keyIDVoting)), netInfo->ToString(), payoutAddress, operatorPayoutAddress);
      30         898 : }
      31             : 
      32           8 : UniValue CDeterministicMNStateDiff::ToJson(MnType nType) const
      33             : {
      34           8 :     UniValue obj(UniValue::VOBJ);
      35           8 :     if (fields & Field_nVersion) {
      36           6 :         obj.pushKV("version", state.nVersion);
      37           6 :     }
      38           8 :     if (fields & Field_netInfo) {
      39           6 :         if (IsServiceDeprecatedRPCEnabled()) {
      40           4 :             obj.pushKV("service", state.netInfo->GetPrimary().ToStringAddrPort());
      41           4 :         }
      42           6 :     }
      43           8 :     if (fields & Field_nRegisteredHeight) {
      44           0 :         obj.pushKV("registeredHeight", state.nRegisteredHeight);
      45           0 :     }
      46           8 :     if (fields & Field_nLastPaidHeight) {
      47           8 :         obj.pushKV("lastPaidHeight", state.nLastPaidHeight);
      48           8 :     }
      49           8 :     if (fields & Field_nConsecutivePayments) {
      50           8 :         obj.pushKV("consecutivePayments", state.nConsecutivePayments);
      51           8 :     }
      52           8 :     if (fields & Field_nPoSePenalty) {
      53           0 :         obj.pushKV("PoSePenalty", state.nPoSePenalty);
      54           0 :     }
      55           8 :     if (fields & Field_nPoSeRevivedHeight) {
      56           0 :         obj.pushKV("PoSeRevivedHeight", state.nPoSeRevivedHeight);
      57           0 :     }
      58           8 :     if (fields & Field_nPoSeBanHeight) {
      59           0 :         obj.pushKV("PoSeBanHeight", state.nPoSeBanHeight);
      60           0 :     }
      61           8 :     if (fields & Field_nRevocationReason) {
      62           0 :         obj.pushKV("revocationReason", state.nRevocationReason);
      63           0 :     }
      64           8 :     if (fields & Field_keyIDOwner) {
      65           0 :         obj.pushKV("ownerAddress", EncodeDestination(PKHash(state.keyIDOwner)));
      66           0 :     }
      67           8 :     if (fields & Field_keyIDVoting) {
      68           0 :         obj.pushKV("votingAddress", EncodeDestination(PKHash(state.keyIDVoting)));
      69           0 :     }
      70           8 :     if (fields & Field_scriptPayout) {
      71           0 :         CTxDestination dest;
      72           0 :         if (ExtractDestination(state.scriptPayout, dest)) {
      73           0 :             obj.pushKV("payoutAddress", EncodeDestination(dest));
      74           0 :         }
      75           0 :     }
      76           8 :     if (fields & Field_scriptOperatorPayout) {
      77           0 :         CTxDestination dest;
      78           0 :         if (ExtractDestination(state.scriptOperatorPayout, dest)) {
      79           0 :             obj.pushKV("operatorPayoutAddress", EncodeDestination(dest));
      80           0 :         }
      81           0 :     }
      82           8 :     if (fields & Field_pubKeyOperator) {
      83           0 :         obj.pushKV("pubKeyOperator", state.pubKeyOperator.ToString());
      84           0 :     }
      85           8 :     if (nType == MnType::Evo) {
      86           8 :         if (fields & Field_platformNodeID) {
      87           0 :             obj.pushKV("platformNodeID", state.platformNodeID.ToString());
      88           0 :         }
      89           8 :         if (IsServiceDeprecatedRPCEnabled()) {
      90             :             // platformP2PPort/platformHTTPPort are deprecated scalar duplicates of netInfo's
      91             :             // Platform entries. From ExtAddr onwards the scalar fields are unused (always 0), so
      92             :             // when the diff carries an ExtAddr netInfo report the live port from it to stay
      93             :             // consistent with the "addresses" output below.
      94           8 :             const bool has_ext_netinfo = (fields & Field_netInfo) && state.netInfo->CanStorePlatform();
      95           4 :             if (fields & Field_platformP2PPort) {
      96           4 :                 obj.pushKV("platformP2PPort",
      97           2 :                            has_ext_netinfo && state.netInfo->HasEntries(NetInfoPurpose::PLATFORM_P2P)
      98           0 :                                ? state.netInfo->GetEntries(NetInfoPurpose::PLATFORM_P2P)[0].GetPort()
      99           2 :                                : state.platformP2PPort);
     100           2 :             }
     101           4 :             if (fields & Field_platformHTTPPort) {
     102           4 :                 obj.pushKV("platformHTTPPort",
     103           2 :                            has_ext_netinfo && state.netInfo->HasEntries(NetInfoPurpose::PLATFORM_HTTPS)
     104           0 :                                ? state.netInfo->GetEntries(NetInfoPurpose::PLATFORM_HTTPS)[0].GetPort()
     105           2 :                                : state.platformHTTPPort);
     106           2 :             }
     107           4 :         }
     108           8 :     }
     109             :     {
     110           8 :         const bool has_netinfo = (fields & Field_netInfo);
     111             : 
     112           8 :         UniValue netInfoObj(UniValue::VOBJ);
     113           8 :         if (has_netinfo) {
     114           6 :             netInfoObj = state.netInfo->ToJson();
     115           6 :         }
     116           8 :         if (nType == MnType::Evo && (!has_netinfo || !state.netInfo->CanStorePlatform())) {
     117          10 :             auto unknownAddr = [](uint16_t port) -> UniValue {
     118           4 :                 UniValue obj(UniValue::VARR);
     119             :                 // We don't know what the address is because it wasn't changed in the
     120             :                 // diff but we still need to report the port number in addr:port format
     121           4 :                 obj.push_back(strprintf("255.255.255.255:%d", port));
     122           4 :                 return obj;
     123           4 :             };
     124           6 :             if (fields & Field_platformP2PPort) {
     125          12 :                 netInfoObj.pushKV(PurposeToString(NetInfoPurpose::PLATFORM_P2P).data(),
     126          12 :                                   (has_netinfo)
     127           4 :                                       ? ArrFromService(CService(state.netInfo->GetPrimary(), state.platformP2PPort))
     128           2 :                                       : unknownAddr(state.platformP2PPort));
     129           6 :             }
     130           6 :             if (fields & Field_platformHTTPPort) {
     131          12 :                 netInfoObj.pushKV(PurposeToString(NetInfoPurpose::PLATFORM_HTTPS).data(),
     132          12 :                                   (has_netinfo)
     133           4 :                                       ? ArrFromService(CService(state.netInfo->GetPrimary(), state.platformHTTPPort))
     134           2 :                                       : unknownAddr(state.platformHTTPPort));
     135           6 :             }
     136           6 :         }
     137           8 :         if (!netInfoObj.empty()) {
     138           8 :             obj.pushKV("addresses", netInfoObj);
     139           8 :         }
     140           8 :     }
     141           8 :     return obj;
     142           8 : }

Generated by: LCOV version 1.16