mirror of
https://github.com/dashpay/dash.git
synced 2024-12-26 12:32:48 +01:00
added dynamic registers
This commit is contained in:
parent
31d8a4d16f
commit
59ddc0d71e
@ -8,7 +8,7 @@
|
|||||||
has:
|
has:
|
||||||
vector<CNetworkVariable> vecNetworkVariables;
|
vector<CNetworkVariable> vecNetworkVariables;
|
||||||
vector<CDashProject> vecProjects;
|
vector<CDashProject> vecProjects;
|
||||||
vector<CBudgetProposal> vecProposals;
|
vector<CGovernanceObject> vecProposals;
|
||||||
vector<CBudgetContract> vecContracts;
|
vector<CBudgetContract> vecContracts;
|
||||||
vector<CBudgetUsers> vecUsers;
|
vector<CBudgetUsers> vecUsers;
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ CGovernanceManager governance;
|
|||||||
CCriticalSection cs_budget;
|
CCriticalSection cs_budget;
|
||||||
|
|
||||||
std::map<uint256, int64_t> askedForSourceProposalOrBudget;
|
std::map<uint256, int64_t> askedForSourceProposalOrBudget;
|
||||||
std::vector<CBudgetProposal> vecImmatureBudgetProposals;
|
std::vector<CGovernanceObject> vecImmatureBudgetProposals;
|
||||||
|
|
||||||
int nSubmittedFinalBudget;
|
int nSubmittedFinalBudget;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
|
|||||||
uint256 nBlockHash;
|
uint256 nBlockHash;
|
||||||
if(!GetTransaction(nTxCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){
|
if(!GetTransaction(nTxCollateralHash, txCollateral, Params().GetConsensus(), nBlockHash, true)){
|
||||||
strError = strprintf("Can't find collateral tx %s", txCollateral.ToString());
|
strError = strprintf("Can't find collateral tx %s", txCollateral.ToString());
|
||||||
LogPrintf ("CBudgetProposal::IsCollateralValid - %s\n", strError);
|
LogPrintf ("CGovernanceObject::IsCollateralValid - %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
|
|||||||
BOOST_FOREACH(const CTxOut o, txCollateral.vout){
|
BOOST_FOREACH(const CTxOut o, txCollateral.vout){
|
||||||
if(!o.scriptPubKey.IsNormalPaymentScript() && !o.scriptPubKey.IsUnspendable()){
|
if(!o.scriptPubKey.IsNormalPaymentScript() && !o.scriptPubKey.IsUnspendable()){
|
||||||
strError = strprintf("Invalid Script %s", txCollateral.ToString());
|
strError = strprintf("Invalid Script %s", txCollateral.ToString());
|
||||||
LogPrintf ("CBudgetProposal::IsCollateralValid - %s\n", strError);
|
LogPrintf ("CGovernanceObject::IsCollateralValid - %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(o.scriptPubKey == findScript && o.nValue >= minFee) foundOpReturn = true;
|
if(o.scriptPubKey == findScript && o.nValue >= minFee) foundOpReturn = true;
|
||||||
@ -56,7 +56,7 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
|
|||||||
}
|
}
|
||||||
if(!foundOpReturn){
|
if(!foundOpReturn){
|
||||||
strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral.ToString());
|
strError = strprintf("Couldn't find opReturn %s in %s", nExpectedHash.ToString(), txCollateral.ToString());
|
||||||
LogPrintf ("CBudgetProposal::IsCollateralValid - %s\n", strError);
|
LogPrintf ("CGovernanceObject::IsCollateralValid - %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ bool IsCollateralValid(uint256 nTxCollateralHash, uint256 nExpectedHash, std::st
|
|||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", BUDGET_FEE_CONFIRMATIONS, conf);
|
strError = strprintf("Collateral requires at least %d confirmations - %d confirmations", BUDGET_FEE_CONFIRMATIONS, conf);
|
||||||
LogPrintf ("CBudgetProposal::IsCollateralValid - %s - %d confirmations\n", strError, conf);
|
LogPrintf ("CGovernanceObject::IsCollateralValid - %s - %d confirmations\n", strError, conf);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -101,7 +101,7 @@ void CGovernanceManager::CheckOrphanVotes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CGovernanceManager::AddProposal(CBudgetProposal& budgetProposal)
|
bool CGovernanceManager::AddProposal(CGovernanceObject& budgetProposal)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
@ -126,23 +126,23 @@ void CGovernanceManager::CheckAndRemove()
|
|||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
|
|
||||||
std::map<uint256, CBudgetProposal>::iterator it2 = mapProposals.begin();
|
std::map<uint256, CGovernanceObject>::iterator it2 = mapProposals.begin();
|
||||||
while(it2 != mapProposals.end())
|
while(it2 != mapProposals.end())
|
||||||
{
|
{
|
||||||
CBudgetProposal* pbudgetProposal = &((*it2).second);
|
CGovernanceObject* pbudgetProposal = &((*it2).second);
|
||||||
pbudgetProposal->fValid = pbudgetProposal->IsValid(pCurrentBlockIndex, strError);
|
pbudgetProposal->fValid = pbudgetProposal->IsValid(pCurrentBlockIndex, strError);
|
||||||
++it2;
|
++it2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal *CGovernanceManager::FindProposal(const std::string &strName)
|
CGovernanceObject *CGovernanceManager::FindProposal(const std::string &strName)
|
||||||
{
|
{
|
||||||
//find the prop with the highest yes count
|
//find the prop with the highest yes count
|
||||||
|
|
||||||
int nYesCount = -99999;
|
int nYesCount = -99999;
|
||||||
CBudgetProposal* pbudgetProposal = NULL;
|
CGovernanceObject* pbudgetProposal = NULL;
|
||||||
|
|
||||||
std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin();
|
std::map<uint256, CGovernanceObject>::iterator it = mapProposals.begin();
|
||||||
while(it != mapProposals.end()){
|
while(it != mapProposals.end()){
|
||||||
if((*it).second.strName == strName && (*it).second.GetYesCount() > nYesCount){
|
if((*it).second.strName == strName && (*it).second.GetYesCount() > nYesCount){
|
||||||
pbudgetProposal = &((*it).second);
|
pbudgetProposal = &((*it).second);
|
||||||
@ -156,7 +156,7 @@ CBudgetProposal *CGovernanceManager::FindProposal(const std::string &strName)
|
|||||||
return pbudgetProposal;
|
return pbudgetProposal;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal *CGovernanceManager::FindProposal(uint256 nHash)
|
CGovernanceObject *CGovernanceManager::FindProposal(uint256 nHash)
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
|
||||||
@ -166,18 +166,18 @@ CBudgetProposal *CGovernanceManager::FindProposal(uint256 nHash)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CBudgetProposal*> CGovernanceManager::GetAllProposals()
|
std::vector<CGovernanceObject*> CGovernanceManager::GetAllProposals()
|
||||||
{
|
{
|
||||||
LOCK(cs);
|
LOCK(cs);
|
||||||
|
|
||||||
std::vector<CBudgetProposal*> vBudgetProposalRet;
|
std::vector<CGovernanceObject*> vBudgetProposalRet;
|
||||||
|
|
||||||
std::map<uint256, CBudgetProposal>::iterator it = mapProposals.begin();
|
std::map<uint256, CGovernanceObject>::iterator it = mapProposals.begin();
|
||||||
while(it != mapProposals.end())
|
while(it != mapProposals.end())
|
||||||
{
|
{
|
||||||
(*it).second.CleanAndRemove(false);
|
(*it).second.CleanAndRemove(false);
|
||||||
|
|
||||||
CBudgetProposal* pbudgetProposal = &((*it).second);
|
CGovernanceObject* pbudgetProposal = &((*it).second);
|
||||||
vBudgetProposalRet.push_back(pbudgetProposal);
|
vBudgetProposalRet.push_back(pbudgetProposal);
|
||||||
|
|
||||||
++it;
|
++it;
|
||||||
@ -190,7 +190,7 @@ std::vector<CBudgetProposal*> CGovernanceManager::GetAllProposals()
|
|||||||
// Sort by votes, if there's a tie sort by their feeHash TX
|
// Sort by votes, if there's a tie sort by their feeHash TX
|
||||||
//
|
//
|
||||||
struct sortProposalsByVotes {
|
struct sortProposalsByVotes {
|
||||||
bool operator()(const std::pair<CBudgetProposal*, int> &left, const std::pair<CBudgetProposal*, int> &right) {
|
bool operator()(const std::pair<CGovernanceObject*, int> &left, const std::pair<CGovernanceObject*, int> &right) {
|
||||||
if( left.second != right.second)
|
if( left.second != right.second)
|
||||||
return (left.second > right.second);
|
return (left.second > right.second);
|
||||||
return (UintToArith256(left.first->nFeeTXHash) > UintToArith256(right.first->nFeeTXHash));
|
return (UintToArith256(left.first->nFeeTXHash) > UintToArith256(right.first->nFeeTXHash));
|
||||||
@ -250,13 +250,13 @@ void CGovernanceManager::NewBlock()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::map<uint256, CBudgetProposal>::iterator it2 = mapProposals.begin();
|
std::map<uint256, CGovernanceObject>::iterator it2 = mapProposals.begin();
|
||||||
while(it2 != mapProposals.end()){
|
while(it2 != mapProposals.end()){
|
||||||
(*it2).second.CleanAndRemove(false);
|
(*it2).second.CleanAndRemove(false);
|
||||||
++it2;
|
++it2;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CBudgetProposal>::iterator it4 = vecImmatureBudgetProposals.begin();
|
std::vector<CGovernanceObject>::iterator it4 = vecImmatureBudgetProposals.begin();
|
||||||
while(it4 != vecImmatureBudgetProposals.end())
|
while(it4 != vecImmatureBudgetProposals.end())
|
||||||
{
|
{
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
@ -273,7 +273,7 @@ void CGovernanceManager::NewBlock()
|
|||||||
// continue;
|
// continue;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
// CBudgetProposal budgetProposal((*it4));
|
// CGovernanceObject budgetProposal((*it4));
|
||||||
// if(AddProposal(budgetProposal)) {(*it4).Relay();}
|
// if(AddProposal(budgetProposal)) {(*it4).Relay();}
|
||||||
|
|
||||||
// LogPrintf("mprop (immature) - new budget - %s\n", (*it4).GetHash().ToString());
|
// LogPrintf("mprop (immature) - new budget - %s\n", (*it4).GetHash().ToString());
|
||||||
@ -313,7 +313,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
|||||||
|
|
||||||
// todo - 12.1 - change to MNGOVERNANCEPROPOSAL
|
// todo - 12.1 - change to MNGOVERNANCEPROPOSAL
|
||||||
if (strCommand == NetMsgType::MNBUDGETPROPOSAL) { //Masternode Proposal
|
if (strCommand == NetMsgType::MNBUDGETPROPOSAL) { //Masternode Proposal
|
||||||
CBudgetProposal budgetProposalBroadcast;
|
CGovernanceObject budgetProposalBroadcast;
|
||||||
vRecv >> budgetProposalBroadcast;
|
vRecv >> budgetProposalBroadcast;
|
||||||
|
|
||||||
if(mapSeenMasternodeBudgetProposals.count(budgetProposalBroadcast.GetHash())){
|
if(mapSeenMasternodeBudgetProposals.count(budgetProposalBroadcast.GetHash())){
|
||||||
@ -336,7 +336,7 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal budgetProposal(budgetProposalBroadcast);
|
CGovernanceObject budgetProposal(budgetProposalBroadcast);
|
||||||
if(AddProposal(budgetProposal)) {budgetProposalBroadcast.Relay();}
|
if(AddProposal(budgetProposal)) {budgetProposalBroadcast.Relay();}
|
||||||
masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash());
|
masternodeSync.AddedBudgetItem(budgetProposalBroadcast.GetHash());
|
||||||
|
|
||||||
@ -448,9 +448,9 @@ void CGovernanceManager::Sync(CNode* pfrom, uint256 nProp)
|
|||||||
int nInvCount = 0;
|
int nInvCount = 0;
|
||||||
|
|
||||||
// sync gov objects
|
// sync gov objects
|
||||||
std::map<uint256, CBudgetProposal>::iterator it1 = mapSeenMasternodeBudgetProposals.begin();
|
std::map<uint256, CGovernanceObject>::iterator it1 = mapSeenMasternodeBudgetProposals.begin();
|
||||||
while(it1 != mapSeenMasternodeBudgetProposals.end()){
|
while(it1 != mapSeenMasternodeBudgetProposals.end()){
|
||||||
CBudgetProposal* pbudgetProposal = FindProposal((*it1).first);
|
CGovernanceObject* pbudgetProposal = FindProposal((*it1).first);
|
||||||
if(pbudgetProposal && pbudgetProposal->fValid && ((nProp == uint256() || ((*it1).first == nProp)))){
|
if(pbudgetProposal && pbudgetProposal->fValid && ((nProp == uint256() || ((*it1).first == nProp)))){
|
||||||
// Push the inventory budget proposal message over to the other client
|
// Push the inventory budget proposal message over to the other client
|
||||||
pfrom->PushInventory(CInv(MSG_BUDGET_PROPOSAL, (*it1).second.GetHash()));
|
pfrom->PushInventory(CInv(MSG_BUDGET_PROPOSAL, (*it1).second.GetHash()));
|
||||||
@ -513,12 +513,12 @@ bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strErro
|
|||||||
if(mapVotes[hash2].count(hash)){
|
if(mapVotes[hash2].count(hash)){
|
||||||
if(mapVotes[hash2][hash].nTime > vote.nTime){
|
if(mapVotes[hash2][hash].nTime > vote.nTime){
|
||||||
strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString());
|
strError = strprintf("new vote older than existing vote - %s", vote.GetHash().ToString());
|
||||||
LogPrint("mnbudget", "CBudgetProposal::AddOrUpdateVote - %s\n", strError);
|
LogPrint("mnbudget", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(vote.nTime - mapVotes[hash2][hash].nTime < BUDGET_VOTE_UPDATE_MIN){
|
if(vote.nTime - mapVotes[hash2][hash].nTime < BUDGET_VOTE_UPDATE_MIN){
|
||||||
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash2][hash].nTime);
|
strError = strprintf("time between votes is too soon - %s - %lli", vote.GetHash().ToString(), vote.nTime - mapVotes[hash2][hash].nTime);
|
||||||
LogPrint("mnbudget", "CBudgetProposal::AddOrUpdateVote - %s\n", strError);
|
LogPrint("mnbudget", "CGovernanceObject::AddOrUpdateVote - %s\n", strError);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -527,7 +527,7 @@ bool CGovernanceManager::AddOrUpdateVote(CBudgetVote& vote, std::string& strErro
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal::CBudgetProposal()
|
CGovernanceObject::CGovernanceObject()
|
||||||
{
|
{
|
||||||
strName = "unknown";
|
strName = "unknown";
|
||||||
nStartTime = 0;
|
nStartTime = 0;
|
||||||
@ -537,7 +537,7 @@ CBudgetProposal::CBudgetProposal()
|
|||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal::CBudgetProposal(const CBudgetProposal& other)
|
CGovernanceObject::CGovernanceObject(const CGovernanceObject& other)
|
||||||
{
|
{
|
||||||
strName = other.strName;
|
strName = other.strName;
|
||||||
strURL = other.strURL;
|
strURL = other.strURL;
|
||||||
@ -550,7 +550,7 @@ CBudgetProposal::CBudgetProposal(const CBudgetProposal& other)
|
|||||||
fValid = true;
|
fValid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal::CBudgetProposal(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn)
|
CGovernanceObject::CGovernanceObject(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn)
|
||||||
{
|
{
|
||||||
strName = strNameIn;
|
strName = strNameIn;
|
||||||
strURL = strURLIn;
|
strURL = strURLIn;
|
||||||
@ -561,7 +561,7 @@ CBudgetProposal::CBudgetProposal(std::string strNameIn, std::string strURLIn, in
|
|||||||
nFeeTXHash = nFeeTXHashIn;
|
nFeeTXHash = nFeeTXHashIn;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral)
|
bool CGovernanceObject::IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral)
|
||||||
{
|
{
|
||||||
if(GetNoCount() - GetYesCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){
|
if(GetNoCount() - GetYesCount() > mnodeman.CountEnabled(MIN_BUDGET_PEER_PROTO_VERSION)/10){
|
||||||
strError = "Active removal";
|
strError = "Active removal";
|
||||||
@ -648,7 +648,7 @@ bool CBudgetProposal::IsValid(const CBlockIndex* pindex, std::string& strError,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBudgetProposal::NetworkWillPay()
|
bool CGovernanceObject::NetworkWillPay()
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* vote nVoteType 1 to 10
|
* vote nVoteType 1 to 10
|
||||||
@ -671,7 +671,7 @@ bool CBudgetProposal::NetworkWillPay()
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CBudgetProposal::IsEstablished() {
|
bool CGovernanceObject::IsEstablished() {
|
||||||
//Proposals must be established to make it into a budget
|
//Proposals must be established to make it into a budget
|
||||||
return (nTime < GetTime() - Params().GetConsensus().nBudgetProposalEstablishingTime);
|
return (nTime < GetTime() - Params().GetConsensus().nBudgetProposalEstablishingTime);
|
||||||
}
|
}
|
||||||
@ -702,27 +702,27 @@ void CGovernanceManager::CleanAndRemove(bool fSignatureCheck)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBudgetProposal::GetAbsoluteYesCount()
|
int CGovernanceObject::GetAbsoluteYesCount()
|
||||||
{
|
{
|
||||||
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_YES) - governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_NO);
|
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_YES) - governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBudgetProposal::GetYesCount()
|
int CGovernanceObject::GetYesCount()
|
||||||
{
|
{
|
||||||
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_YES);
|
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_YES);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBudgetProposal::GetNoCount()
|
int CGovernanceObject::GetNoCount()
|
||||||
{
|
{
|
||||||
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_NO);
|
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_NO);
|
||||||
}
|
}
|
||||||
|
|
||||||
int CBudgetProposal::GetAbstainCount()
|
int CGovernanceObject::GetAbstainCount()
|
||||||
{
|
{
|
||||||
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_ABSTAIN);
|
return governance.CountMatchingVotes(VOTE_TYPE_FUND, VOTE_OUTCOME_ABSTAIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CBudgetProposal::Relay()
|
void CGovernanceObject::Relay()
|
||||||
{
|
{
|
||||||
CInv inv(MSG_BUDGET_PROPOSAL, GetHash());
|
CInv inv(MSG_BUDGET_PROPOSAL, GetHash());
|
||||||
RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION);
|
RelayInv(inv, MIN_BUDGET_PEER_PROTO_VERSION);
|
||||||
@ -777,3 +777,9 @@ int CGovernanceManager::CountMatchingVotes(int nVoteTypeIn, int nVoteOutcomeIn)
|
|||||||
|
|
||||||
return nMatching;
|
return nMatching;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// template<typename T>
|
||||||
|
// bool CGovernanceManager::AddRegister(T& newValue)
|
||||||
|
// {
|
||||||
|
|
||||||
|
// }
|
||||||
|
124
src/governance.h
124
src/governance.h
@ -16,6 +16,9 @@
|
|||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
#include "init.h"
|
#include "init.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
extern CCriticalSection cs_budget;
|
extern CCriticalSection cs_budget;
|
||||||
|
|
||||||
@ -28,7 +31,7 @@ static const int64_t CONTRACT_ACTIVATION_TIME = 60*60*24*14;
|
|||||||
|
|
||||||
|
|
||||||
class CGovernanceManager;
|
class CGovernanceManager;
|
||||||
class CBudgetProposal;
|
class CGovernanceObject;
|
||||||
class CBudgetVote;
|
class CBudgetVote;
|
||||||
class CNode;
|
class CNode;
|
||||||
|
|
||||||
@ -37,7 +40,7 @@ static const CAmount GOVERNANCE_FEE_TX = (5*COIN);
|
|||||||
static const int64_t GOVERNANCE_FEE_CONFIRMATIONS = 6;
|
static const int64_t GOVERNANCE_FEE_CONFIRMATIONS = 6;
|
||||||
static const int64_t GOVERNANCE_UPDATE_MIN = 60*60;
|
static const int64_t GOVERNANCE_UPDATE_MIN = 60*60;
|
||||||
|
|
||||||
extern std::vector<CBudgetProposal> vecImmatureBudgetProposals;
|
extern std::vector<CGovernanceObject> vecImmatureBudgetProposals;
|
||||||
extern std::map<uint256, int64_t> askedForSourceProposalOrBudget;
|
extern std::map<uint256, int64_t> askedForSourceProposalOrBudget;
|
||||||
extern CGovernanceManager governance;
|
extern CGovernanceManager governance;
|
||||||
|
|
||||||
@ -62,10 +65,10 @@ public:
|
|||||||
mutable CCriticalSection cs;
|
mutable CCriticalSection cs;
|
||||||
|
|
||||||
// keep track of the scanning errors I've seen
|
// keep track of the scanning errors I've seen
|
||||||
map<uint256, CBudgetProposal> mapProposals;
|
map<uint256, CGovernanceObject> mapProposals;
|
||||||
|
|
||||||
// todo - 12.1 - move to private for better encapsulation
|
// todo - 12.1 - move to private for better encapsulation
|
||||||
std::map<uint256, CBudgetProposal> mapSeenMasternodeBudgetProposals;
|
std::map<uint256, CGovernanceObject> mapSeenMasternodeBudgetProposals;
|
||||||
std::map<uint256, CBudgetVote> mapSeenMasternodeBudgetVotes;
|
std::map<uint256, CBudgetVote> mapSeenMasternodeBudgetVotes;
|
||||||
std::map<uint256, CBudgetVote> mapOrphanMasternodeBudgetVotes;
|
std::map<uint256, CBudgetVote> mapOrphanMasternodeBudgetVotes;
|
||||||
// parent hash vote hash vote
|
// parent hash vote hash vote
|
||||||
@ -97,13 +100,13 @@ public:
|
|||||||
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
void ProcessMessage(CNode* pfrom, std::string& strCommand, CDataStream& vRecv);
|
||||||
void NewBlock();
|
void NewBlock();
|
||||||
|
|
||||||
CBudgetProposal *FindProposal(const std::string &strName);
|
CGovernanceObject *FindProposal(const std::string &strName);
|
||||||
CBudgetProposal *FindProposal(uint256 nHash);
|
CGovernanceObject *FindProposal(uint256 nHash);
|
||||||
|
|
||||||
std::vector<CBudgetProposal*> GetAllProposals();
|
std::vector<CGovernanceObject*> GetAllProposals();
|
||||||
|
|
||||||
bool IsBudgetPaymentBlock(int nBlockHeight);
|
bool IsBudgetPaymentBlock(int nBlockHeight);
|
||||||
bool AddProposal(CBudgetProposal& budgetProposal);
|
bool AddProposal(CGovernanceObject& budgetProposal);
|
||||||
bool UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string& strError);
|
bool UpdateProposal(CBudgetVote& vote, CNode* pfrom, std::string& strError);
|
||||||
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
|
bool AddOrUpdateVote(CBudgetVote& vote, std::string& strError);
|
||||||
bool PropExists(uint256 nHash);
|
bool PropExists(uint256 nHash);
|
||||||
@ -139,47 +142,41 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Governance objects can hold any time of data
|
* Governance objects can hold any type of data
|
||||||
* --------------------------------------------
|
* --------------------------------------------
|
||||||
*
|
*
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// todo - 12.1 - add register obj to CGovernanceObj
|
class CGovernanceObjectRegister
|
||||||
// union GovernanceObjectRegister
|
{
|
||||||
// {
|
private:
|
||||||
// CAmount a;
|
int nType;
|
||||||
// int i;
|
std::string strReg;
|
||||||
// bool b;
|
|
||||||
// double f;
|
public:
|
||||||
// std::string s;
|
CGovernanceObjectRegister(int nTypeIn, char* strRegIn)
|
||||||
// uint256 h;
|
{
|
||||||
// CBitcoinAddress ba;
|
nType = nTypeIn;
|
||||||
// }
|
strReg = strRegIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
ADD_SERIALIZE_METHODS;
|
||||||
|
|
||||||
|
template <typename Stream, typename Operation>
|
||||||
|
inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion) {
|
||||||
|
//for syncing with other clients
|
||||||
|
READWRITE(nType);
|
||||||
|
READWRITE(LIMITED_STRING(strReg, 64));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Governance object payload types
|
* Generic Governance Object
|
||||||
* --------------------------------------------
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// todo - 12.1 - add payload obj to CGovernanceObj
|
class CGovernanceObject
|
||||||
// enum class GovernanceObjectPayloadType {
|
|
||||||
// CAmount,
|
|
||||||
// Int,
|
|
||||||
// Bool,
|
|
||||||
// String,
|
|
||||||
// Double,
|
|
||||||
// Hash256,
|
|
||||||
// BitcoinAddress
|
|
||||||
// };
|
|
||||||
|
|
||||||
//
|
|
||||||
// Budget Proposal : Contains the masternode votes for each budget
|
|
||||||
//
|
|
||||||
|
|
||||||
class CBudgetProposal
|
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
// critical section to protect the inner data structures
|
// critical section to protect the inner data structures
|
||||||
@ -188,22 +185,28 @@ private:
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
bool fValid;
|
bool fValid;
|
||||||
std::string strName;
|
std::string strName; //org name, username, prop name, etc.
|
||||||
std::string strURL;
|
std::string strURL;
|
||||||
int nStartTime;
|
int nStartTime;
|
||||||
int nEndTime;
|
int nEndTime;
|
||||||
CAmount nAmount; // 12.1 - remove
|
CAmount nAmount; // 12.1 - remove
|
||||||
// int nPriority; //budget is sorted by this integer before funding votecount
|
int nPriority; //budget is sorted by this integer before funding votecount
|
||||||
CScript address; //todo rename to addressOwner;
|
CScript address; //todo rename to addressOwner;
|
||||||
int64_t nTime;
|
int64_t nTime;
|
||||||
uint256 nFeeTXHash;
|
uint256 nFeeTXHash;
|
||||||
uint256 nHashParent; // 12.1 - remove
|
uint256 nHashParent; // 12.1 - remove
|
||||||
|
|
||||||
// Registers, these can be used for anything by the masternode network
|
// Registers, these can be used for anything
|
||||||
// vector<GovernanceObjectPayloadType> registerTypes;
|
// -- check governance wiki for correct usage
|
||||||
// vector<GovernanceObjectPayload> registers;
|
std::map<int, CGovernanceObjectRegister> mapRegister;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Example usage:
|
* Example usage:
|
||||||
|
* --------------------------------------------------------
|
||||||
|
*
|
||||||
|
* We don't really care what's in these, as long as the masternode network
|
||||||
|
* believes they're accurate. Otherwise the masternodes will vote them down
|
||||||
|
* and we'll delete them from memory (fee-loss attack).
|
||||||
*
|
*
|
||||||
* - This system is designed to allow virtually any usage
|
* - This system is designed to allow virtually any usage
|
||||||
* - No protocol changes are needed
|
* - No protocol changes are needed
|
||||||
@ -216,14 +219,31 @@ public:
|
|||||||
* Proposal:
|
* Proposal:
|
||||||
* MasternodePaymentsBlock: BlockStart, Masternode1, 2, 3...
|
* MasternodePaymentsBlock: BlockStart, Masternode1, 2, 3...
|
||||||
* Arbitration: UserId1, UserId2, TxHash, ContractHash
|
* Arbitration: UserId1, UserId2, TxHash, ContractHash
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
bool AddRegister(std::string& strError, int nTypeIn, std::string strIn)
|
||||||
|
{
|
||||||
|
if(strIn.size() > 64)
|
||||||
|
{
|
||||||
|
strError = "Too big.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
char regbuff[64];
|
||||||
|
strncpy(regbuff, strIn.c_str(), sizeof(regbuff));
|
||||||
|
|
||||||
|
CGovernanceObjectRegister newRegister(nTypeIn, regbuff);
|
||||||
|
mapRegister.insert(make_pair(1 , newRegister));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//cache object
|
//cache object
|
||||||
|
|
||||||
CBudgetProposal();
|
CGovernanceObject();
|
||||||
CBudgetProposal(const CBudgetProposal& other);
|
CGovernanceObject(const CGovernanceObject& other);
|
||||||
CBudgetProposal(std::string strNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn);
|
CGovernanceObject(std::string strNameIn, std::string strURLIn, int64_t nStartTimeIn, int64_t nEndTimeIn, uint256 nFeeTXHashIn);
|
||||||
|
|
||||||
bool HasMinimumRequiredSupport();
|
bool HasMinimumRequiredSupport();
|
||||||
bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true);
|
bool IsValid(const CBlockIndex* pindex, std::string& strError, bool fCheckCollateral=true);
|
||||||
@ -234,13 +254,11 @@ public:
|
|||||||
std::string GetURL() {return strURL; }
|
std::string GetURL() {return strURL; }
|
||||||
int GetStartTime() {return nStartTime;}
|
int GetStartTime() {return nStartTime;}
|
||||||
int GetEndTime() {return nEndTime;}
|
int GetEndTime() {return nEndTime;}
|
||||||
CScript GetPayee() {return address;}
|
|
||||||
int IsActive(int64_t nTime) {return nTime > nStartTime && nTime < nEndTime;}
|
int IsActive(int64_t nTime) {return nTime > nStartTime && nTime < nEndTime;}
|
||||||
int GetAbsoluteYesCount();
|
int GetAbsoluteYesCount();
|
||||||
int GetYesCount();
|
int GetYesCount();
|
||||||
int GetNoCount();
|
int GetNoCount();
|
||||||
int GetAbstainCount();
|
int GetAbstainCount();
|
||||||
CAmount GetAmount() {return nAmount;}
|
|
||||||
|
|
||||||
void CleanAndRemove(bool fSignatureCheck);
|
void CleanAndRemove(bool fSignatureCheck);
|
||||||
|
|
||||||
@ -250,8 +268,7 @@ public:
|
|||||||
ss << strURL;
|
ss << strURL;
|
||||||
ss << nStartTime;
|
ss << nStartTime;
|
||||||
ss << nEndTime;
|
ss << nEndTime;
|
||||||
ss << nAmount;
|
ss << mapRegister;
|
||||||
ss << *(CScriptBase*)(&address);
|
|
||||||
uint256 h1 = ss.GetHash();
|
uint256 h1 = ss.GetHash();
|
||||||
|
|
||||||
return h1;
|
return h1;
|
||||||
@ -268,10 +285,7 @@ public:
|
|||||||
READWRITE(nTime);
|
READWRITE(nTime);
|
||||||
READWRITE(nStartTime);
|
READWRITE(nStartTime);
|
||||||
READWRITE(nEndTime);
|
READWRITE(nEndTime);
|
||||||
READWRITE(nAmount);
|
READWRITE(mapRegister);
|
||||||
|
|
||||||
READWRITE(*(CScriptBase*)(&address));
|
|
||||||
READWRITE(nTime);
|
|
||||||
READWRITE(nFeeTXHash);
|
READWRITE(nFeeTXHash);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -35,7 +35,7 @@ struct sortFinalizedBudgetsByVotes {
|
|||||||
// Sort by votes, if there's a tie sort by their feeHash TX
|
// Sort by votes, if there's a tie sort by their feeHash TX
|
||||||
//
|
//
|
||||||
struct sortProposalsByVotes {
|
struct sortProposalsByVotes {
|
||||||
bool operator()(const std::pair<CBudgetProposal*, int> &left, const std::pair<CBudgetProposal*, int> &right) {
|
bool operator()(const std::pair<CGovernanceObject*, int> &left, const std::pair<CGovernanceObject*, int> &right) {
|
||||||
if( left.second != right.second)
|
if( left.second != right.second)
|
||||||
return (left.second > right.second);
|
return (left.second > right.second);
|
||||||
return (UintToArith256(left.first->nFeeTXHash) > UintToArith256(right.first->nFeeTXHash));
|
return (UintToArith256(left.first->nFeeTXHash) > UintToArith256(right.first->nFeeTXHash));
|
||||||
@ -700,7 +700,7 @@ void CFinalizedBudget::AutoCheck()
|
|||||||
|
|
||||||
if(strBudgetMode == "auto") //only vote for exact matches
|
if(strBudgetMode == "auto") //only vote for exact matches
|
||||||
{
|
{
|
||||||
std::vector<CBudgetProposal*> vBudgetProposals = budget.GetBudget();
|
std::vector<CGovernanceObject*> vBudgetProposals = budget.GetBudget();
|
||||||
|
|
||||||
|
|
||||||
for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){
|
for(unsigned int i = 0; i < vecBudgetPayments.size(); i++){
|
||||||
@ -783,7 +783,7 @@ std::string CFinalizedBudget::GetProposals()
|
|||||||
std::string ret = "";
|
std::string ret = "";
|
||||||
|
|
||||||
BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){
|
BOOST_FOREACH(CTxBudgetPayment& budgetPayment, vecBudgetPayments){
|
||||||
CBudgetProposal* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash);
|
CGovernanceObject* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash);
|
||||||
|
|
||||||
std::string token = budgetPayment.nProposalHash.ToString();
|
std::string token = budgetPayment.nProposalHash.ToString();
|
||||||
|
|
||||||
@ -807,7 +807,7 @@ std::string CFinalizedBudget::GetStatus()
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
CBudgetProposal* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash);
|
CGovernanceObject* pbudgetProposal = governance.FindProposal(budgetPayment.nProposalHash);
|
||||||
if(!pbudgetProposal){
|
if(!pbudgetProposal){
|
||||||
if(retBadHashes == ""){
|
if(retBadHashes == ""){
|
||||||
retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString();
|
retBadHashes = "Unknown proposal hash! Check this proposal before voting" + budgetPayment.nProposalHash.ToString();
|
||||||
|
@ -95,7 +95,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp)
|
|||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
|
||||||
// create transaction 15 minutes into the future, to allow for confirmation time
|
// create transaction 15 minutes into the future, to allow for confirmation time
|
||||||
CBudgetProposal budgetProposalBroadcast(strName, strURL, nPaymentCount, scriptPubKey, nAmount, GetTime(), 253370764800, uint256());
|
CGovernanceObject budgetProposalBroadcast(strName, strURL, nPaymentCount, scriptPubKey, nAmount, GetTime(), 253370764800, uint256());
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
if(!budgetProposalBroadcast.IsValid(pindex, strError, false))
|
if(!budgetProposalBroadcast.IsValid(pindex, strError, false))
|
||||||
@ -158,7 +158,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp)
|
|||||||
uint256 hash = ParseHashV(params[7], "Proposal hash");
|
uint256 hash = ParseHashV(params[7], "Proposal hash");
|
||||||
|
|
||||||
//create the proposal incase we're the first to make it
|
//create the proposal incase we're the first to make it
|
||||||
CBudgetProposal budgetProposalBroadcast(strName, strURL, nPaymentCount, scriptPubKey, nAmount, GetTime(), 253370764800, hash);
|
CGovernanceObject budgetProposalBroadcast(strName, strURL, nPaymentCount, scriptPubKey, nAmount, GetTime(), 253370764800, hash);
|
||||||
|
|
||||||
std::string strError = "";
|
std::string strError = "";
|
||||||
|
|
||||||
@ -416,8 +416,8 @@ UniValue mnbudget(const UniValue& params, bool fHelp)
|
|||||||
pindex = chainActive.Tip();
|
pindex = chainActive.Tip();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<CBudgetProposal*> winningProps = governance.GetAllProposals();
|
std::vector<CGovernanceObject*> winningProps = governance.GetAllProposals();
|
||||||
BOOST_FOREACH(CBudgetProposal* pbudgetProposal, winningProps)
|
BOOST_FOREACH(CGovernanceObject* pbudgetProposal, winningProps)
|
||||||
{
|
{
|
||||||
if(strShow == "valid" && !pbudgetProposal->fValid) continue;
|
if(strShow == "valid" && !pbudgetProposal->fValid) continue;
|
||||||
|
|
||||||
@ -458,15 +458,15 @@ UniValue mnbudget(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
std::string strName = SanitizeString(params[1].get_str());
|
std::string strName = SanitizeString(params[1].get_str());
|
||||||
|
|
||||||
CBudgetProposal* pbudgetProposal = governance.FindProposal(strName);
|
CGovernanceObject* pbudgetProposal = governance.FindProposal(strName);
|
||||||
|
|
||||||
if(pbudgetProposal == NULL)
|
if(pbudgetProposal == NULL)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal");
|
||||||
|
|
||||||
UniValue resultObj(UniValue::VOBJ);
|
UniValue resultObj(UniValue::VOBJ);
|
||||||
|
|
||||||
std::vector<CBudgetProposal*> winningProps = governance.GetAllProposals();
|
std::vector<CGovernanceObject*> winningProps = governance.GetAllProposals();
|
||||||
BOOST_FOREACH(CBudgetProposal* pbudgetProposal, winningProps)
|
BOOST_FOREACH(CGovernanceObject* pbudgetProposal, winningProps)
|
||||||
{
|
{
|
||||||
if(pbudgetProposal->GetName() != strName) continue;
|
if(pbudgetProposal->GetName() != strName) continue;
|
||||||
if(!pbudgetProposal->fValid) continue;
|
if(!pbudgetProposal->fValid) continue;
|
||||||
@ -490,7 +490,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
uint256 hash = ParseHashV(params[1], "Proposal hash");
|
uint256 hash = ParseHashV(params[1], "Proposal hash");
|
||||||
|
|
||||||
CBudgetProposal* pbudgetProposal = governance.FindProposal(hash);
|
CGovernanceObject* pbudgetProposal = governance.FindProposal(hash);
|
||||||
|
|
||||||
if(pbudgetProposal == NULL)
|
if(pbudgetProposal == NULL)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal");
|
||||||
@ -538,7 +538,7 @@ UniValue mnbudget(const UniValue& params, bool fHelp)
|
|||||||
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
|
|
||||||
CBudgetProposal* pbudgetProposal = governance.FindProposal(hash);
|
CGovernanceObject* pbudgetProposal = governance.FindProposal(hash);
|
||||||
|
|
||||||
if(pbudgetProposal == NULL)
|
if(pbudgetProposal == NULL)
|
||||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal");
|
throw JSONRPCError(RPC_INVALID_PARAMETER, "Unknown proposal");
|
||||||
|
Loading…
Reference in New Issue
Block a user