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 83 : CBudgetVote::CBudgetVote() : 12 : CSignedMessage(), 13 : fValid(true), 14 : fSynced(false), 15 : nProposalHash(UINT256_ZERO), 16 : nVote(VOTE_ABSTAIN), 17 : nTime(0), 18 83 : vin() 19 83 : { } 20 : 21 7 : 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 7 : vin(vinIn) 28 : { 29 7 : nTime = GetAdjustedTime(); 30 7 : } 31 : 32 41 : void CBudgetVote::Relay() const 33 : { 34 41 : CInv inv(MSG_BUDGET_VOTE, GetHash()); 35 41 : g_connman->RelayInv(inv); 36 41 : } 37 : 38 760 : uint256 CBudgetVote::GetHash() const 39 : { 40 760 : CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); 41 760 : ss << vin; 42 760 : ss << nProposalHash; 43 760 : ss << (int) nVote; 44 760 : ss << nTime; 45 760 : 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 138 : UniValue CBudgetVote::ToJSON() const 54 : { 55 138 : UniValue bObj(UniValue::VOBJ); 56 276 : bObj.pushKV("mnId", vin.prevout.ToStringShort()); 57 276 : bObj.pushKV("nHash", GetHash().ToString()); 58 276 : bObj.pushKV("Vote", GetVoteString()); 59 138 : bObj.pushKV("nTime", nTime); 60 138 : bObj.pushKV("fValid", fValid); 61 138 : return bObj; 62 : }