Line data Source code
1 : // Copyright (c) 2014-2025 The Dash Core developers 2 : // Distributed under the MIT/X11 software license, see the accompanying 3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 4 : 5 : #ifndef BITCOIN_GOVERNANCE_COMMON_H 6 : #define BITCOIN_GOVERNANCE_COMMON_H 7 : 8 : #include <primitives/transaction.h> 9 : #include <uint256.h> 10 : 11 : #include <serialize.h> 12 : 13 : #include <string> 14 : #include <vector> 15 : 16 : struct RPCResult; 17 : 18 : class UniValue; 19 : 20 : /** 21 : * This module is a public interface of governance module that can be used 22 : * in other components such as wallet 23 : */ 24 : 25 : enum class GovernanceObject : int { 26 : UNKNOWN = 0, 27 : PROPOSAL, 28 : TRIGGER 29 : }; 30 : template<> struct is_serializable_enum<GovernanceObject> : std::true_type {}; 31 : 32 : namespace Governance { 33 62876 : class Object 34 : { 35 : public: 36 2620 : Object() = default; 37 : 38 : Object(const uint256& nHashParent, int nRevision, int64_t nTime, const uint256& nCollateralHash, const std::string& strDataHex); 39 : 40 : [[nodiscard]] static RPCResult GetJsonHelp(const std::string& key, bool optional); 41 : [[nodiscard]] UniValue ToJson() const; 42 : 43 : uint256 GetHash() const; 44 : 45 : std::string GetDataAsHexString() const; 46 : std::string GetDataAsPlainString() const; 47 : 48 : /// Object typecode 49 655 : GovernanceObject type{GovernanceObject::UNKNOWN}; 50 : 51 : /// parent object, 0 is root 52 655 : uint256 hashParent{}; 53 : 54 : /// object revision in the system 55 655 : int revision{0}; 56 : 57 : /// time this object was created 58 655 : int64_t time{0}; 59 : 60 : /// fee-tx 61 655 : uint256 collateralHash{}; 62 : 63 : /// Masternode info for signed objects 64 : COutPoint masternodeOutpoint; 65 655 : std::vector<unsigned char> vchSig{}; 66 : 67 : /// Data field - can be used for anything 68 : std::vector<unsigned char> vchData; 69 : 70 3600 : SERIALIZE_METHODS(Object, obj) 71 : { 72 1200 : READWRITE( 73 : obj.hashParent, 74 : obj.revision, 75 : obj.time, 76 : obj.collateralHash, 77 : obj.vchData, 78 : obj.type, 79 : obj.masternodeOutpoint 80 : ); 81 1200 : if (!(s.GetType() & SER_GETHASH)) { 82 792 : READWRITE(obj.vchSig); 83 792 : } 84 1200 : } 85 : }; 86 : } // namespace Governance 87 : 88 : #endif // BITCOIN_GOVERNANCE_COMMON_H