Line data Source code
1 : // Copyright (c) 2014-2015 The Dash developers 2 : // Copyright (c) 2015-2021 The PIVX Core developers 3 : // Distributed under the MIT/X11 software license, see the accompanying 4 : // file COPYING or http://www.opensource.org/licenses/mit-license.php. 5 : 6 : #ifndef PIVX_BUDGET_BUDGETVOTE_H 7 : #define PIVX_BUDGET_BUDGETVOTE_H 8 : 9 : #include "messagesigner.h" 10 : #include "primitives/transaction.h" 11 : 12 : #include <univalue.h> 13 : 14 : // 15 : // CBudgetVote - Allow a masternode node to vote and broadcast throughout the network 16 : // 17 : 18 : class CBudgetVote : public CSignedMessage 19 : { 20 : public: 21 : enum VoteDirection : uint32_t { 22 : VOTE_ABSTAIN = 0, 23 : VOTE_YES = 1, 24 : VOTE_NO = 2 25 : }; 26 : 27 : private: 28 : bool fValid; //if the vote is currently valid / counted 29 : bool fSynced; //if we've sent this to our peers 30 : uint256 nProposalHash; 31 : VoteDirection nVote; 32 : int64_t nTime; 33 : CTxIn vin; 34 : 35 : public: 36 : CBudgetVote(); 37 : CBudgetVote(const CTxIn& vin, const uint256& nProposalHash, VoteDirection nVoteIn); 38 : 39 : void Relay() const; 40 : 41 138 : std::string GetVoteString() const 42 : { 43 138 : std::string ret = "ABSTAIN"; 44 138 : if (nVote == VOTE_YES) ret = "YES"; 45 138 : if (nVote == VOTE_NO) ret = "NO"; 46 138 : return ret; 47 : } 48 : 49 : uint256 GetHash() const; 50 : 51 : // override CSignedMessage functions 52 52 : uint256 GetSignatureHash() const override { return GetHash(); } 53 : std::string GetStrMessage() const override; 54 90 : CTxIn GetVin() const { return vin; }; 55 : 56 : UniValue ToJSON() const; 57 : 58 7370 : VoteDirection GetDirection() const { return nVote; } 59 89 : uint256 GetProposalHash() const { return nProposalHash; } 60 90 : int64_t GetTime() const { return nTime; } 61 591 : bool IsSynced() const { return fSynced; } 62 4915 : bool IsValid() const { return fValid; } 63 : 64 322 : void SetSynced(bool _fSynced) { fSynced = _fSynced; } 65 0 : void SetTime(const int64_t& _nTime) { nTime = _nTime; } 66 500 : void SetValid(bool _fValid) { fValid = _fValid; } 67 : 68 292 : SERIALIZE_METHODS(CBudgetVote, obj) { READWRITE(obj.vin, obj.nProposalHash, Using<CustomUintFormatter<4>>(obj.nVote), obj.nTime, obj.vchSig, obj.nMessVersion); } 69 : }; 70 : 71 : #endif // PIVX_BUDGET_BUDGETVOTE_H