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 : #include "budget/budgetvote.h" 7 : 8 : #include "net.h" 9 : #include "streams.h" 10 : 11 29 : CBudgetVote::CBudgetVote() : 12 : CSignedMessage(), 13 : fValid(true), 14 : fSynced(false), 15 : nProposalHash(UINT256_ZERO), 16 : nVote(VOTE_ABSTAIN), 17 : nTime(0), 18 29 : vin() 19 29 : { } 20 : 21 5 : CBudgetVote::CBudgetVote(const CTxIn& vinIn, const uint256& nProposalHashIn, VoteDirection nVoteIn) : 22 : CSignedMessage(), 23 : fValid(true), 24 : fSynced(false), 25 : nProposalHash(nProposalHashIn), 26 : nVote(nVoteIn), 27 5 : vin(vinIn) 28 : { 29 5 : nTime = GetAdjustedTime(); 30 5 : } 31 : 32 17 : void CBudgetVote::Relay() const 33 : { 34 17 : CInv inv(MSG_BUDGET_VOTE, GetHash()); 35 17 : g_connman->RelayInv(inv); 36 17 : } 37 : 38 163 : uint256 CBudgetVote::GetHash() const 39 : { 40 163 : CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); 41 163 : ss << vin; 42 163 : ss << nProposalHash; 43 163 : ss << (int) nVote; 44 163 : ss << nTime; 45 163 : return ss.GetHash(); 46 : } 47 : 48 0 : std::string CBudgetVote::GetStrMessage() const 49 : { 50 0 : return strprintf("%s %s %d %d", vin.prevout.ToStringShort(), nProposalHash.ToString(), (int)nVote, nTime); 51 : } 52 : 53 8 : UniValue CBudgetVote::ToJSON() const 54 : { 55 8 : UniValue bObj(UniValue::VOBJ); 56 16 : bObj.pushKV("mnId", vin.prevout.ToStringShort()); 57 16 : bObj.pushKV("nHash", GetHash().ToString()); 58 16 : bObj.pushKV("Vote", GetVoteString()); 59 8 : bObj.pushKV("nTime", nTime); 60 8 : bObj.pushKV("fValid", fValid); 61 8 : return bObj; 62 : }