PIVX Core  5.6.99
P2P Digital Currency
providertx.h
Go to the documentation of this file.
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
35  uint16_t nOperatorReward{0};
37  uint256 inputsHash; // replay protection
38  std::vector<unsigned char> vchSig;
39 
40 public:
41 
43  {
44  READWRITE(obj.nVersion);
45  READWRITE(obj.nType);
46  READWRITE(obj.nMode);
47  READWRITE(obj.collateralOutpoint);
48  READWRITE(obj.addr);
49  READWRITE(obj.keyIDOwner);
50  READWRITE(obj.pubKeyOperator);
51  READWRITE(obj.keyIDVoting);
52  READWRITE(obj.scriptPayout);
53  READWRITE(obj.nOperatorReward);
54  READWRITE(obj.scriptOperatorPayout);
55  READWRITE(obj.inputsHash);
56  if (!(s.GetType() & SER_GETHASH)) {
57  READWRITE(obj.vchSig);
58  }
59  }
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 
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
83  uint256 inputsHash; // replay protection
85 
86 public:
88  {
89  READWRITE(obj.nVersion, obj.proTxHash, obj.addr, obj.scriptOperatorPayout, obj.inputsHash);
90  if (!(s.GetType() & SER_GETHASH)) {
91  READWRITE(obj.sig);
92  }
93  }
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
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
111  uint16_t nMode{0}; // only 0 supported for now
115  uint256 inputsHash; // replay protection
116  std::vector<unsigned char> vchSig;
117 
118 public:
120  {
121  READWRITE(obj.nVersion, obj.proTxHash, obj.nMode, obj.pubKeyOperator, obj.keyIDVoting, obj.scriptPayout, obj.inputsHash);
122  if (!(s.GetType() & SER_GETHASH)) {
123  READWRITE(obj.vchSig);
124  }
125  }
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
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
147  };
148 
149 public:
150  uint16_t nVersion{CURRENT_VERSION}; // message version
153  uint256 inputsHash; // replay protection
155 
156 public:
158  {
159  READWRITE(obj.nVersion, obj.proTxHash, obj.nReason, obj.inputsHash);
160  if (!(s.GetType() & SER_GETHASH)) {
161  READWRITE(obj.sig);
162  }
163  }
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
A reference to a CKey: the Hash160 of its serialized public key.
Definition: pubkey.h:21
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:72
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:381
A combination of a network address (CNetAddr) and a (TCP) port.
Definition: netaddress.h:484
Capture information about block/transaction validation.
Definition: validation.h:24
static const uint16_t CURRENT_VERSION
Definition: providertx.h:22
std::string ToString() const
Definition: providertx.cpp:26
SERIALIZE_METHODS(ProRegPL, obj)
Definition: providertx.h:42
uint16_t nMode
Definition: providertx.h:28
CScript scriptOperatorPayout
Definition: providertx.h:36
CKeyID keyIDVoting
Definition: providertx.h:33
uint16_t nType
Definition: providertx.h:27
COutPoint collateralOutpoint
Definition: providertx.h:29
uint16_t nVersion
Definition: providertx.h:26
void ToJson(UniValue &obj) const
Definition: providertx.cpp:35
uint16_t nOperatorReward
Definition: providertx.h:35
CScript scriptPayout
Definition: providertx.h:34
static constexpr int16_t SPECIALTX_TYPE
Definition: providertx.h:23
CBLSPublicKey pubKeyOperator
Definition: providertx.h:32
uint256 inputsHash
Definition: providertx.h:37
std::vector< unsigned char > vchSig
Definition: providertx.h:38
std::string MakeSignString() const
Definition: providertx.cpp:11
CKeyID keyIDOwner
Definition: providertx.h:31
bool IsTriviallyValid(CValidationState &state) const
Definition: providertx.cpp:59
CService addr
Definition: providertx.h:30
CKeyID keyIDVoting
Definition: providertx.h:113
CScript scriptPayout
Definition: providertx.h:114
static const uint16_t CURRENT_VERSION
Definition: providertx.h:105
SERIALIZE_METHODS(ProUpRegPL, obj)
Definition: providertx.h:119
static constexpr int16_t SPECIALTX_TYPE
Definition: providertx.h:106
std::string ToString() const
Definition: providertx.cpp:133
uint16_t nVersion
Definition: providertx.h:109
uint256 proTxHash
Definition: providertx.h:110
std::vector< unsigned char > vchSig
Definition: providertx.h:116
bool IsTriviallyValid(CValidationState &state) const
Definition: providertx.cpp:157
uint16_t nMode
Definition: providertx.h:111
CBLSPublicKey pubKeyOperator
Definition: providertx.h:112
uint256 inputsHash
Definition: providertx.h:115
void ToJson(UniValue &obj) const
Definition: providertx.cpp:142
void ToJson(UniValue &obj) const
Definition: providertx.cpp:186
bool IsTriviallyValid(CValidationState &state) const
Definition: providertx.cpp:196
uint16_t nReason
Definition: providertx.h:152
static const uint16_t CURRENT_VERSION
Definition: providertx.h:137
SERIALIZE_METHODS(ProUpRevPL, obj)
Definition: providertx.h:157
uint256 inputsHash
Definition: providertx.h:153
uint256 proTxHash
Definition: providertx.h:151
static constexpr int16_t SPECIALTX_TYPE
Definition: providertx.h:138
CBLSSignature sig
Definition: providertx.h:154
@ REASON_TERMINATION_OF_SERVICE
Definition: providertx.h:143
@ REASON_CHANGE_OF_KEYS
Definition: providertx.h:145
@ REASON_COMPROMISED_KEYS
Definition: providertx.h:144
@ REASON_NOT_SPECIFIED
Definition: providertx.h:142
std::string ToString() const
Definition: providertx.cpp:180
uint16_t nVersion
Definition: providertx.h:150
std::string ToString() const
Definition: providertx.cpp:102
uint256 inputsHash
Definition: providertx.h:83
uint16_t nVersion
Definition: providertx.h:79
CService addr
Definition: providertx.h:81
static const uint16_t CURRENT_VERSION
Definition: providertx.h:75
uint256 proTxHash
Definition: providertx.h:80
CBLSSignature sig
Definition: providertx.h:84
static constexpr int16_t SPECIALTX_TYPE
Definition: providertx.h:76
void ToJson(UniValue &obj) const
Definition: providertx.cpp:111
CScript scriptOperatorPayout
Definition: providertx.h:82
SERIALIZE_METHODS(ProUpServPL, obj)
Definition: providertx.h:87
bool IsTriviallyValid(CValidationState &state) const
Definition: providertx.cpp:125
256-bit opaque blob.
Definition: uint256.h:138
bool GetProRegCollateral(const CTransactionRef &tx, COutPoint &outRet)
Definition: providertx.cpp:210
@ SER_GETHASH
Definition: serialize.h:176
#define READWRITE(...)
Definition: serialize.h:183
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:456
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175