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: 2025-02-23 09:33:43 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        5744 :     SERIALIZE_METHODS(ProRegPL, obj)
      43             :     {
      44        4896 :         READWRITE(obj.nVersion);
      45        4896 :         READWRITE(obj.nType);
      46        4896 :         READWRITE(obj.nMode);
      47        4896 :         READWRITE(obj.collateralOutpoint);
      48        4896 :         READWRITE(obj.addr);
      49        4895 :         READWRITE(obj.keyIDOwner);
      50        4895 :         READWRITE(obj.pubKeyOperator);
      51        4895 :         READWRITE(obj.keyIDVoting);
      52        4895 :         READWRITE(obj.scriptPayout);
      53        4895 :         READWRITE(obj.nOperatorReward);
      54        4895 :         READWRITE(obj.scriptOperatorPayout);
      55        4895 :         READWRITE(obj.inputsHash);
      56        4895 :         if (!(s.GetType() & SER_GETHASH)) {
      57        4400 :             READWRITE(obj.vchSig);
      58             :         }
      59        4895 :     }
      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         446 :     SERIALIZE_METHODS(ProUpServPL, obj)
      88             :     {
      89         314 :         READWRITE(obj.nVersion, obj.proTxHash, obj.addr, obj.scriptOperatorPayout, obj.inputsHash);
      90         313 :         if (!(s.GetType() & SER_GETHASH)) {
      91         242 :             READWRITE(obj.sig);
      92             :         }
      93         313 :     }
      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         747 :     SERIALIZE_METHODS(ProUpRegPL, obj)
     120             :     {
     121         453 :         READWRITE(obj.nVersion, obj.proTxHash, obj.nMode, obj.pubKeyOperator, obj.keyIDVoting, obj.scriptPayout, obj.inputsHash);
     122         453 :         if (!(s.GetType() & SER_GETHASH)) {
     123         349 :             READWRITE(obj.vchSig);
     124             :         }
     125         453 :     }
     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         302 :     SERIALIZE_METHODS(ProUpRevPL, obj)
     158             :     {
     159         170 :         READWRITE(obj.nVersion, obj.proTxHash, obj.nReason, obj.inputsHash);
     160         170 :         if (!(s.GetType() & SER_GETHASH)) {
     161         127 :             READWRITE(obj.sig);
     162             :         }
     163         170 :     }
     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