PIVX Core  5.6.99
P2P Digital Currency
budgetvote.cpp
Go to the documentation of this file.
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 
13  fValid(true),
14  fSynced(false),
15  nProposalHash(UINT256_ZERO),
16  nVote(VOTE_ABSTAIN),
17  nTime(0),
18  vin()
19 { }
20 
21 CBudgetVote::CBudgetVote(const CTxIn& vinIn, const uint256& nProposalHashIn, VoteDirection nVoteIn) :
23  fValid(true),
24  fSynced(false),
25  nProposalHash(nProposalHashIn),
26  nVote(nVoteIn),
27  vin(vinIn)
28 {
30 }
31 
32 void CBudgetVote::Relay() const
33 {
35  g_connman->RelayInv(inv);
36 }
37 
39 {
40  CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
41  ss << vin;
42  ss << nProposalHash;
43  ss << (int) nVote;
44  ss << nTime;
45  return ss.GetHash();
46 }
47 
48 std::string CBudgetVote::GetStrMessage() const
49 {
50  return strprintf("%s %s %d %d", vin.prevout.ToStringShort(), nProposalHash.ToString(), (int)nVote, nTime);
51 }
52 
54 {
56  bObj.pushKV("mnId", vin.prevout.ToStringShort());
57  bObj.pushKV("nHash", GetHash().ToString());
58  bObj.pushKV("Vote", GetVoteString());
59  bObj.pushKV("nTime", nTime);
60  bObj.pushKV("fValid", fValid);
61  return bObj;
62 }
true
Definition: bls_dkg.cpp:153
false
Definition: bls_dkg.cpp:151
std::string ToStringShort() const
Definition: transaction.cpp:13
bool fValid
Definition: budgetvote.h:28
uint256 nProposalHash
Definition: budgetvote.h:30
std::string GetStrMessage() const override
Definition: budgetvote.cpp:48
CTxIn vin
Definition: budgetvote.h:33
UniValue ToJSON() const
Definition: budgetvote.cpp:53
int64_t nTime
Definition: budgetvote.h:32
void Relay() const
Definition: budgetvote.cpp:32
VoteDirection nVote
Definition: budgetvote.h:31
uint256 GetHash() const
Definition: budgetvote.cpp:38
std::string GetVoteString() const
Definition: budgetvote.h:41
A writer stream (for serialization) that computes a 256-bit hash.
Definition: hash.h:216
uint256 GetHash()
Definition: hash.h:236
inv message data
Definition: protocol.h:466
Base Class for all signed messages on the network.
Definition: messagesigner.h:63
An input of a transaction.
Definition: transaction.h:94
COutPoint prevout
Definition: transaction.h:96
@ VOBJ
Definition: univalue.h:21
bool pushKV(const std::string &key, const UniValue &val)
Definition: univalue.cpp:133
std::string ToString() const
Definition: uint256.cpp:65
256-bit opaque blob.
Definition: uint256.h:138
std::unique_ptr< CConnman > g_connman
Definition: init.cpp:90
@ MSG_BUDGET_VOTE
Definition: protocol.h:446
@ SER_GETHASH
Definition: serialize.h:176
int64_t GetAdjustedTime()
Definition: timedata.cpp:36
#define strprintf
Definition: tinyformat.h:1056
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:175