LCOV - code coverage report
Current view: top level - src/evo - providertx.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 31 31 100.0 %
Date: 2026-08-09 10:51:41 Functions: 12 12 100.0 %

          Line data    Source code
       1             : // Copyright (c) 2018-2021 The Dash Core developers
       2             : // Copyright (c) 2021 The PIVX Core developers
       3             : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
       4             : 
       5             : #ifndef PIVX_EVO_PROVIDERTX_H
       6             : #define PIVX_EVO_PROVIDERTX_H
       7             : 
       8             : #include "bls/bls_wrapper.h"
       9             : #include "netaddress.h"
      10             : #include "primitives/transaction.h"
      11             : #include <consensus/validation.h>
      12             : 
      13             : #include <univalue.h>
      14             : 
      15             : class CValidationState;
      16             : 
      17             : // Provider-Register tx payload
      18             : 
      19             : class ProRegPL
      20             : {
      21             : public:
      22             :     static const uint16_t CURRENT_VERSION = 1;
      23             :     static constexpr int16_t SPECIALTX_TYPE = CTransaction::TxType::PROREG;
      24             : 
      25             : public:
      26             :     uint16_t nVersion{CURRENT_VERSION};                         // message version
      27             :     uint16_t nType{0};                                          // only 0 supported for now
      28             :     uint16_t nMode{0};                                          // only 0 supported for now
      29             :     COutPoint collateralOutpoint{UINT256_ZERO, (uint32_t)-1};   // if hash is null, we refer to a ProRegTx output
      30             :     CService addr;
      31             :     CKeyID keyIDOwner;
      32             :     CBLSPublicKey pubKeyOperator;
      33             :     CKeyID keyIDVoting;
      34             :     CScript scriptPayout;
      35             :     uint16_t nOperatorReward{0};
      36             :     CScript scriptOperatorPayout;
      37             :     uint256 inputsHash; // replay protection
      38             :     std::vector<unsigned char> vchSig;
      39             : 
      40             : public:
      41             : 
      42        1818 :     SERIALIZE_METHODS(ProRegPL, obj)
      43             :     {
      44        1474 :         READWRITE(obj.nVersion);
      45        1474 :         READWRITE(obj.nType);
      46        1474 :         READWRITE(obj.nMode);
      47        1474 :         READWRITE(obj.collateralOutpoint);
      48        1474 :         READWRITE(obj.addr);
      49        1473 :         READWRITE(obj.keyIDOwner);
      50        1473 :         READWRITE(obj.pubKeyOperator);
      51        1473 :         READWRITE(obj.keyIDVoting);
      52        1473 :         READWRITE(obj.scriptPayout);
      53        1473 :         READWRITE(obj.nOperatorReward);
      54        1473 :         READWRITE(obj.scriptOperatorPayout);
      55        1473 :         READWRITE(obj.inputsHash);
      56        1473 :         if (!(s.GetType() & SER_GETHASH)) {
      57        1390 :             READWRITE(obj.vchSig);
      58             :         }
      59        1473 :     }
      60             : 
      61             :     // When signing with the collateral key, we don't sign the hash but a generated message instead
      62             :     // This is needed for HW wallet support which can only sign text messages as of now
      63             :     std::string MakeSignString() const;
      64             : 
      65             :     std::string ToString() const;
      66             :     void ToJson(UniValue& obj) const;
      67             :     bool IsTriviallyValid(CValidationState& state) const;
      68             : };
      69             : 
      70             : // Provider-Update-Service tx payload
      71             : 
      72             : class ProUpServPL
      73             : {
      74             : public:
      75             :     static const uint16_t CURRENT_VERSION = 1;
      76             :     static constexpr int16_t SPECIALTX_TYPE = CTransaction::TxType::PROUPSERV;
      77             : 
      78             : public:
      79             :     uint16_t nVersion{CURRENT_VERSION}; // message version
      80             :     uint256 proTxHash{UINT256_ZERO};
      81             :     CService addr;
      82             :     CScript scriptOperatorPayout;
      83             :     uint256 inputsHash; // replay protection
      84             :     CBLSSignature sig;
      85             : 
      86             : public:
      87         196 :     SERIALIZE_METHODS(ProUpServPL, obj)
      88             :     {
      89         115 :         READWRITE(obj.nVersion, obj.proTxHash, obj.addr, obj.scriptOperatorPayout, obj.inputsHash);
      90         114 :         if (!(s.GetType() & SER_GETHASH)) {
      91          86 :             READWRITE(obj.sig);
      92             :         }
      93         114 :     }
      94             : 
      95             : public:
      96             :     std::string ToString() const;
      97             :     void ToJson(UniValue& obj) const;
      98             :     bool IsTriviallyValid(CValidationState& state) const;
      99             : };
     100             : 
     101             : // Provider-Update-Registrar tx payload
     102             : class ProUpRegPL
     103             : {
     104             : public:
     105             :     static const uint16_t CURRENT_VERSION = 1;
     106             :     static constexpr int16_t SPECIALTX_TYPE = CTransaction::TxType::PROUPREG;
     107             : 
     108             : public:
     109             :     uint16_t nVersion{CURRENT_VERSION}; // message version
     110             :     uint256 proTxHash;
     111             :     uint16_t nMode{0}; // only 0 supported for now
     112             :     CBLSPublicKey pubKeyOperator;
     113             :     CKeyID keyIDVoting;
     114             :     CScript scriptPayout;
     115             :     uint256 inputsHash; // replay protection
     116             :     std::vector<unsigned char> vchSig;
     117             : 
     118             : public:
     119         205 :     SERIALIZE_METHODS(ProUpRegPL, obj)
     120             :     {
     121         114 :         READWRITE(obj.nVersion, obj.proTxHash, obj.nMode, obj.pubKeyOperator, obj.keyIDVoting, obj.scriptPayout, obj.inputsHash);
     122         114 :         if (!(s.GetType() & SER_GETHASH)) {
     123          83 :             READWRITE(obj.vchSig);
     124             :         }
     125         114 :     }
     126             : 
     127             : public:
     128             :     std::string ToString() const;
     129             :     void ToJson(UniValue& obj) const;
     130             :     bool IsTriviallyValid(CValidationState& state) const;
     131             : };
     132             : 
     133             : // Provider-Update-Revoke tx payload
     134             : class ProUpRevPL
     135             : {
     136             : public:
     137             :     static const uint16_t CURRENT_VERSION = 1;
     138             :     static constexpr int16_t SPECIALTX_TYPE = CTransaction::TxType::PROUPREV;
     139             : 
     140             :     // these are just informational and do not have any effect on the revocation
     141             :     enum RevocationReason {
     142             :         REASON_NOT_SPECIFIED = 0,
     143             :         REASON_TERMINATION_OF_SERVICE = 1,
     144             :         REASON_COMPROMISED_KEYS = 2,
     145             :         REASON_CHANGE_OF_KEYS = 3,
     146             :         REASON_LAST = REASON_CHANGE_OF_KEYS
     147             :     };
     148             : 
     149             : public:
     150             :     uint16_t nVersion{CURRENT_VERSION}; // message version
     151             :     uint256 proTxHash;
     152             :     uint16_t nReason{REASON_NOT_SPECIFIED};
     153             :     uint256 inputsHash; // replay protection
     154             :     CBLSSignature sig;
     155             : 
     156             : public:
     157         116 :     SERIALIZE_METHODS(ProUpRevPL, obj)
     158             :     {
     159          62 :         READWRITE(obj.nVersion, obj.proTxHash, obj.nReason, obj.inputsHash);
     160          62 :         if (!(s.GetType() & SER_GETHASH)) {
     161          47 :             READWRITE(obj.sig);
     162             :         }
     163          62 :     }
     164             : 
     165             : public:
     166             :     std::string ToString() const;
     167             :     void ToJson(UniValue& obj) const;
     168             :     bool IsTriviallyValid(CValidationState& state) const;
     169             : };
     170             : 
     171             : 
     172             : // If tx is a ProRegTx, return the collateral outpoint in outRet.
     173             : bool GetProRegCollateral(const CTransactionRef& tx, COutPoint& outRet);
     174             : 
     175             : #endif // PIVX_EVO_PROVIDERTX_H

Generated by: LCOV version 1.14