PIVX Core  5.6.99
P2P Digital Currency
budgetvote.h
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 #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 
19 {
20 public:
21  enum VoteDirection : uint32_t {
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
32  int64_t nTime;
34 
35 public:
36  CBudgetVote();
37  CBudgetVote(const CTxIn& vin, const uint256& nProposalHash, VoteDirection nVoteIn);
38 
39  void Relay() const;
40 
41  std::string GetVoteString() const
42  {
43  std::string ret = "ABSTAIN";
44  if (nVote == VOTE_YES) ret = "YES";
45  if (nVote == VOTE_NO) ret = "NO";
46  return ret;
47  }
48 
49  uint256 GetHash() const;
50 
51  // override CSignedMessage functions
52  uint256 GetSignatureHash() const override { return GetHash(); }
53  std::string GetStrMessage() const override;
54  CTxIn GetVin() const { return vin; };
55 
56  UniValue ToJSON() const;
57 
58  VoteDirection GetDirection() const { return nVote; }
60  int64_t GetTime() const { return nTime; }
61  bool IsSynced() const { return fSynced; }
62  bool IsValid() const { return fValid; }
63 
64  void SetSynced(bool _fSynced) { fSynced = _fSynced; }
65  void SetTime(const int64_t& _nTime) { nTime = _nTime; }
66  void SetValid(bool _fValid) { fValid = _fValid; }
67 
68  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
bool fValid
Definition: budgetvote.h:28
CTxIn GetVin() const
Definition: budgetvote.h:54
uint256 nProposalHash
Definition: budgetvote.h:30
std::string GetStrMessage() const override
Definition: budgetvote.cpp:48
CTxIn vin
Definition: budgetvote.h:33
uint256 GetProposalHash() const
Definition: budgetvote.h:59
bool IsValid() const
Definition: budgetvote.h:62
SERIALIZE_METHODS(CBudgetVote, obj)
Definition: budgetvote.h:68
UniValue ToJSON() const
Definition: budgetvote.cpp:53
int64_t nTime
Definition: budgetvote.h:32
bool IsSynced() const
Definition: budgetvote.h:61
int64_t GetTime() const
Definition: budgetvote.h:60
void Relay() const
Definition: budgetvote.cpp:32
VoteDirection nVote
Definition: budgetvote.h:31
uint256 GetSignatureHash() const override
Definition: budgetvote.h:52
uint256 GetHash() const
Definition: budgetvote.cpp:38
std::string GetVoteString() const
Definition: budgetvote.h:41
bool fSynced
Definition: budgetvote.h:29
void SetSynced(bool _fSynced)
Definition: budgetvote.h:64
void SetTime(const int64_t &_nTime)
Definition: budgetvote.h:65
void SetValid(bool _fValid)
Definition: budgetvote.h:66
VoteDirection GetDirection() const
Definition: budgetvote.h:58
Base Class for all signed messages on the network.
Definition: messagesigner.h:63
An input of a transaction.
Definition: transaction.h:94
256-bit opaque blob.
Definition: uint256.h:138
#define READWRITE(...)
Definition: serialize.h:183
Serialization wrapper class for custom integers and enums.
Definition: serialize.h:670