2018-09-28 09:56:17 +02:00
|
|
|
// Copyright (c) 2014-2018 The Dash Core developers
|
2016-08-17 09:08:25 +02:00
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2016-11-13 18:52:34 +01:00
|
|
|
#ifndef GOVERNANCE_CLASSES_H
|
|
|
|
#define GOVERNANCE_CLASSES_H
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
#include "base58.h"
|
|
|
|
#include "governance.h"
|
2016-12-20 14:27:59 +01:00
|
|
|
#include "key.h"
|
|
|
|
#include "script/standard.h"
|
|
|
|
#include "util.h"
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
class CSuperblock;
|
|
|
|
class CGovernanceTriggerManager;
|
|
|
|
class CSuperblockManager;
|
|
|
|
|
2018-07-12 11:02:20 +02:00
|
|
|
typedef std::shared_ptr<CSuperblock> CSuperblock_sptr;
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
// DECLARE GLOBAL VARIABLES FOR GOVERNANCE CLASSES
|
|
|
|
extern CGovernanceTriggerManager triggerman;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger Mananger
|
|
|
|
*
|
|
|
|
* - Track governance objects which are triggers
|
|
|
|
* - After triggers are activated and executed, they can be removed
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CGovernanceTriggerManager
|
|
|
|
{
|
|
|
|
friend class CSuperblockManager;
|
|
|
|
friend class CGovernanceManager;
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
private:
|
2016-08-17 09:08:25 +02:00
|
|
|
typedef std::map<uint256, CSuperblock_sptr> trigger_m_t;
|
|
|
|
typedef trigger_m_t::iterator trigger_m_it;
|
|
|
|
|
|
|
|
trigger_m_t mapTrigger;
|
|
|
|
|
|
|
|
std::vector<CSuperblock_sptr> GetActiveTriggers();
|
|
|
|
bool AddNewTrigger(uint256 nHash);
|
|
|
|
void CleanAndRemove();
|
|
|
|
|
2016-09-12 09:40:00 +02:00
|
|
|
public:
|
2018-09-28 09:56:17 +02:00
|
|
|
CGovernanceTriggerManager() :
|
|
|
|
mapTrigger() {}
|
2016-08-17 09:08:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Superblock Manager
|
|
|
|
*
|
|
|
|
* Class for querying superblock information
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CSuperblockManager
|
|
|
|
{
|
2016-08-22 03:41:40 +02:00
|
|
|
private:
|
2016-09-12 09:40:00 +02:00
|
|
|
static bool GetBestSuperblock(CSuperblock_sptr& pSuperblockRet, int nBlockHeight);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
public:
|
2016-08-17 09:08:25 +02:00
|
|
|
static bool IsSuperblockTriggered(int nBlockHeight);
|
|
|
|
|
2018-08-12 17:27:09 +02:00
|
|
|
static bool GetSuperblockPayments(int nBlockHeight, std::vector<CTxOut>& voutSuperblockRet);
|
2018-02-12 19:35:10 +01:00
|
|
|
static void ExecuteBestSuperblock(int nBlockHeight);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
|
|
|
static std::string GetRequiredPaymentsString(int nBlockHeight);
|
2016-08-22 03:41:40 +02:00
|
|
|
static bool IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
2016-08-17 09:08:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Governance Object Payment
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CGovernancePayment
|
|
|
|
{
|
2016-09-12 09:40:00 +02:00
|
|
|
private:
|
|
|
|
bool fValid;
|
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
public:
|
|
|
|
CScript script;
|
|
|
|
CAmount nAmount;
|
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
CGovernancePayment() :
|
|
|
|
fValid(false),
|
|
|
|
script(),
|
|
|
|
nAmount(0)
|
|
|
|
{
|
|
|
|
}
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2018-09-28 09:56:17 +02:00
|
|
|
CGovernancePayment(CBitcoinAddress addrIn, CAmount nAmountIn) :
|
|
|
|
fValid(false),
|
|
|
|
script(),
|
|
|
|
nAmount(0)
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2018-09-28 09:56:17 +02:00
|
|
|
try {
|
2016-08-17 09:08:25 +02:00
|
|
|
CTxDestination dest = addrIn.Get();
|
|
|
|
script = GetScriptForDestination(dest);
|
|
|
|
nAmount = nAmountIn;
|
2016-10-17 20:54:28 +02:00
|
|
|
fValid = true;
|
2018-09-28 09:56:17 +02:00
|
|
|
} catch (std::exception& e) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrintf("CGovernancePayment Payment not valid: addrIn = %s, nAmountIn = %d, what = %s\n",
|
2018-09-28 09:56:17 +02:00
|
|
|
addrIn.ToString(), nAmountIn, e.what());
|
|
|
|
} catch (...) {
|
2016-10-17 20:54:28 +02:00
|
|
|
LogPrintf("CGovernancePayment Payment not valid: addrIn = %s, nAmountIn = %d\n",
|
2018-09-28 09:56:17 +02:00
|
|
|
addrIn.ToString(), nAmountIn);
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
2016-09-12 09:40:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
bool IsValid() { return fValid; }
|
2016-08-17 09:08:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Trigger : Superblock
|
|
|
|
*
|
|
|
|
* - Create payments on the network
|
2016-09-12 09:40:00 +02:00
|
|
|
*
|
|
|
|
* object structure:
|
|
|
|
* {
|
|
|
|
* "governance_object_id" : last_id,
|
|
|
|
* "type" : govtypes.trigger,
|
|
|
|
* "subtype" : "superblock",
|
|
|
|
* "superblock_name" : superblock_name,
|
|
|
|
* "start_epoch" : start_epoch,
|
|
|
|
* "payment_addresses" : "addr1|addr2|addr3",
|
|
|
|
* "payment_amounts" : "amount1|amount2|amount3"
|
|
|
|
* }
|
2016-08-17 09:08:25 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
class CSuperblock : public CGovernanceObject
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
uint256 nGovObjHash;
|
|
|
|
|
2018-02-12 13:46:01 +01:00
|
|
|
int nBlockHeight;
|
2016-08-17 09:08:25 +02:00
|
|
|
int nStatus;
|
|
|
|
std::vector<CGovernancePayment> vecPayments;
|
|
|
|
|
2018-02-12 13:49:00 +01:00
|
|
|
void ParsePaymentSchedule(const std::string& strPaymentAddresses, const std::string& strPaymentAmounts);
|
2016-08-22 03:41:40 +02:00
|
|
|
|
2016-08-17 09:08:25 +02:00
|
|
|
public:
|
|
|
|
CSuperblock();
|
|
|
|
CSuperblock(uint256& nHash);
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
static bool IsValidBlockHeight(int nBlockHeight);
|
2018-02-12 13:46:55 +01:00
|
|
|
static void GetNearestSuperblocksHeights(int nBlockHeight, int& nLastSuperblockRet, int& nNextSuperblockRet);
|
2016-08-22 03:41:40 +02:00
|
|
|
static CAmount GetPaymentsLimit(int nBlockHeight);
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
int GetStatus() { return nStatus; }
|
|
|
|
void SetStatus(int nStatusIn) { nStatus = nStatusIn; }
|
|
|
|
|
|
|
|
// IS THIS TRIGGER ALREADY EXECUTED?
|
|
|
|
bool IsExecuted() { return nStatus == SEEN_OBJECT_EXECUTED; }
|
|
|
|
// TELL THE ENGINE WE EXECUTED THIS EVENT
|
|
|
|
void SetExecuted() { nStatus = SEEN_OBJECT_EXECUTED; }
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
CGovernanceObject* GetGovernanceObject()
|
|
|
|
{
|
2016-08-17 09:08:25 +02:00
|
|
|
AssertLockHeld(governance.cs);
|
|
|
|
CGovernanceObject* pObj = governance.FindGovernanceObject(nGovObjHash);
|
|
|
|
return pObj;
|
|
|
|
}
|
|
|
|
|
2018-02-12 13:46:01 +01:00
|
|
|
int GetBlockHeight()
|
2016-08-17 09:08:25 +02:00
|
|
|
{
|
2018-02-12 13:46:01 +01:00
|
|
|
return nBlockHeight;
|
2016-08-17 09:08:25 +02:00
|
|
|
}
|
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
int CountPayments() { return (int)vecPayments.size(); }
|
|
|
|
bool GetPayment(int nPaymentIndex, CGovernancePayment& paymentRet);
|
|
|
|
CAmount GetPaymentsTotalAmount();
|
2016-08-17 09:08:25 +02:00
|
|
|
|
2016-08-22 03:41:40 +02:00
|
|
|
bool IsValid(const CTransaction& txNew, int nBlockHeight, CAmount blockReward);
|
2018-02-12 19:35:10 +01:00
|
|
|
bool IsExpired();
|
2016-08-17 09:08:25 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|