Dash Core  0.12.2.1
P2P Digital Currency
governance-classes.h
Go to the documentation of this file.
1 // Copyright (c) 2014-2017 The Dash Core developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 #ifndef GOVERNANCE_CLASSES_H
5 #define GOVERNANCE_CLASSES_H
6 
7 //#define ENABLE_DASH_DEBUG
8 
9 #include "base58.h"
10 #include "governance.h"
11 #include "key.h"
12 #include "script/standard.h"
13 #include "util.h"
14 
15 #include <boost/shared_ptr.hpp>
16 
17 class CSuperblock;
18 class CGovernanceTrigger;
20 class CSuperblockManager;
21 
22 static const int TRIGGER_UNKNOWN = -1;
23 static const int TRIGGER_SUPERBLOCK = 1000;
24 
25 typedef boost::shared_ptr<CSuperblock> CSuperblock_sptr;
26 
27 // DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES
29 
30 // SPLIT A STRING UP - USED FOR SUPERBLOCK PAYMENTS
31 std::vector<std::string> SplitBy(std::string strCommand, std::string strDelimit);
32 
41 {
42  friend class CSuperblockManager;
43  friend class CGovernanceManager;
44 
45 private:
46  typedef std::map<uint256, CSuperblock_sptr> trigger_m_t;
47  typedef trigger_m_t::iterator trigger_m_it;
48  typedef trigger_m_t::const_iterator trigger_m_cit;
49 
51 
52  std::vector<CSuperblock_sptr> GetActiveTriggers();
53  bool AddNewTrigger(uint256 nHash);
54  void CleanAndRemove();
55 
56 public:
58 };
59 
67 {
68 private:
69  static bool GetBestSuperblock(CSuperblock_sptr& pSuperblockRet, int nBlockHeight);
70 
71 public:
72 
73  static bool IsSuperblockTriggered(int nBlockHeight);
74 
75  static void CreateSuperblock(CMutableTransaction& txNewRet, int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet);
76 
77  static std::string GetRequiredPaymentsString(int nBlockHeight);
78  static bool IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
79 };
80 
87 {
88 private:
89  bool fValid;
90 
91 public:
94 
96  :fValid(false),
97  script(),
98  nAmount(0)
99  {}
100 
102  :fValid(false),
103  script(),
104  nAmount(0)
105  {
106  try
107  {
108  CTxDestination dest = addrIn.Get();
110  nAmount = nAmountIn;
111  fValid = true;
112  }
113  catch(std::exception& e)
114  {
115  LogPrintf("CGovernancePayment Payment not valid: addrIn = %s, nAmountIn = %d, what = %s\n",
116  addrIn.ToString(), nAmountIn, e.what());
117  }
118  catch(...)
119  {
120  LogPrintf("CGovernancePayment Payment not valid: addrIn = %s, nAmountIn = %d\n",
121  addrIn.ToString(), nAmountIn);
122  }
123  }
124 
125  bool IsValid() { return fValid; }
126 };
127 
128 
147 {
148 private:
150 
152  int nStatus;
153  std::vector<CGovernancePayment> vecPayments;
154 
155  void ParsePaymentSchedule(std::string& strPaymentAddresses, std::string& strPaymentAmounts);
156 
157 public:
158 
159  CSuperblock();
160  CSuperblock(uint256& nHash);
161 
162  static bool IsValidBlockHeight(int nBlockHeight);
163  static CAmount GetPaymentsLimit(int nBlockHeight);
164 
165  int GetStatus() { return nStatus; }
166  void SetStatus(int nStatusIn) { nStatus = nStatusIn; }
167 
168  // IS THIS TRIGGER ALREADY EXECUTED?
170  // TELL THE ENGINE WE EXECUTED THIS EVENT
172 
174  {
177  return pObj;
178  }
179 
181  {
182  /* // 12.1 TRIGGER EXECUTION */
183  /* // NOTE : Is this over complicated? */
184 
185  /* //int nRet = 0; */
186  /* int nTipEpoch = 0; */
187  /* int nTipBlock = chainActive.Tip()->nHeight+1; */
188 
189  /* // GET TIP EPOCK / BLOCK */
190 
191  /* // typically it should be more than the current time */
192  /* int nDiff = nEpochStart - nTipEpoch; */
193  /* int nBlockDiff = nDiff / (2.6*60); */
194 
195  /* // calculate predicted block height */
196  /* int nMod = (nTipBlock + nBlockDiff) % Params().GetConsensus().nSuperblockCycle; */
197 
198  /* return (nTipBlock + nBlockDiff)-nMod; */
199  return nEpochStart;
200  }
201 
202  int CountPayments() { return (int)vecPayments.size(); }
203  bool GetPayment(int nPaymentIndex, CGovernancePayment& paymentRet);
205 
206  bool IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
207 };
208 
209 #endif
void SetStatus(int nStatusIn)
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
Definition: standard.h:69
static std::string GetRequiredPaymentsString(int nBlockHeight)
CGovernanceObject * FindGovernanceObject(const uint256 &nHash)
Definition: governance.cpp:559
CGovernanceObject * GetGovernanceObject()
std::vector< std::string > SplitBy(std::string strCommand, std::string strDelimit)
static bool IsSuperblockTriggered(int nBlockHeight)
bool IsValid(const CTransaction &txNew, int nBlockHeight, CAmount blockReward)
CAmount GetPaymentsTotalAmount()
std::vector< CSuperblock_sptr > GetActiveTriggers()
bool GetPayment(int nPaymentIndex, CGovernancePayment &paymentRet)
std::string ToString() const
Definition: base58.cpp:193
static bool IsValid(const CTransaction &txNew, int nBlockHeight, CAmount blockReward)
int64_t CAmount
Definition: amount.h:14
#define AssertLockHeld(cs)
Definition: sync.h:96
#define LogPrintf(...)
Definition: util.h:98
static bool GetBestSuperblock(CSuperblock_sptr &pSuperblockRet, int nBlockHeight)
std::map< uint256, CSuperblock_sptr > trigger_m_t
CGovernanceTriggerManager triggerman
CGovernancePayment(CBitcoinAddress addrIn, CAmount nAmountIn)
CScript GetScriptForDestination(const CTxDestination &dest)
Definition: standard.cpp:262
static CAmount GetPaymentsLimit(int nBlockHeight)
static const int SEEN_OBJECT_EXECUTED
void ParsePaymentSchedule(std::string &strPaymentAddresses, std::string &strPaymentAmounts)
trigger_m_t::const_iterator trigger_m_cit
CTxDestination Get() const
Definition: base58.cpp:260
bool AddNewTrigger(uint256 nHash)
static const int TRIGGER_UNKNOWN
static const int TRIGGER_SUPERBLOCK
CGovernanceManager governance
Definition: governance.cpp:17
std::vector< CGovernancePayment > vecPayments
boost::shared_ptr< CSuperblock > CSuperblock_sptr
static bool IsValidBlockHeight(int nBlockHeight)
trigger_m_t::iterator trigger_m_it
CCriticalSection cs
Definition: governance.h:289
static void CreateSuperblock(CMutableTransaction &txNewRet, int nBlockHeight, std::vector< CTxOut > &voutSuperblockRet)