Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/governance/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,11 @@ std::vector<CGovernanceVote> CGovernanceManager::GetCurrentVotes(const uint256&
return vecResult;
}

std::vector<const CGovernanceObject*> CGovernanceManager::GetAllNewerThan(int64_t nMoreThanTime) const
std::vector<CGovernanceObject> CGovernanceManager::GetAllNewerThan(int64_t nMoreThanTime) const
{
LOCK(cs);

std::vector<const CGovernanceObject*> vGovObjs;
std::vector<CGovernanceObject> vGovObjs;

for (const auto& objPair : mapObjects) {
// IF THIS OBJECT IS OLDER THAN TIME, CONTINUE
Expand All @@ -518,8 +518,7 @@ std::vector<const CGovernanceObject*> CGovernanceManager::GetAllNewerThan(int64_
}

// ADD GOVERNANCE OBJECT TO LIST
const CGovernanceObject* pGovObj = &(objPair.second);
vGovObjs.push_back(pGovObj);
vGovObjs.push_back(objPair.second);
}

return vGovObjs;
Expand Down
2 changes: 1 addition & 1 deletion src/governance/governance.h
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class CGovernanceManager

// These commands are only used in RPC
std::vector<CGovernanceVote> GetCurrentVotes(const uint256& nParentHash, const COutPoint& mnCollateralOutpointFilter) const;
std::vector<const CGovernanceObject*> GetAllNewerThan(int64_t nMoreThanTime) const;
std::vector<CGovernanceObject> GetAllNewerThan(int64_t nMoreThanTime) const;

void AddGovernanceObject(CGovernanceObject& govobj, CConnman& connman, const CNode* pfrom = nullptr);

Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class EVOImpl : public EVO
class GOVImpl : public GOV
{
public:
std::vector<const CGovernanceObject*> getAllNewerThan(int64_t nMoreThanTime) override
std::vector<CGovernanceObject> getAllNewerThan(int64_t nMoreThanTime) override
{
return governance.GetAllNewerThan(nMoreThanTime);
}
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class GOV
{
public:
virtual ~GOV() {}
virtual std::vector<const CGovernanceObject*> getAllNewerThan(int64_t nMoreThanTime) = 0;
virtual std::vector<CGovernanceObject> getAllNewerThan(int64_t nMoreThanTime) = 0;
};

//! Interface for the src/llmq part of a dash node (dashd process).
Expand Down
2 changes: 1 addition & 1 deletion src/qt/clientmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ int64_t ClientModel::getHeaderTipTime() const
return cachedBestHeaderTime;
}

std::vector<const CGovernanceObject*> ClientModel::getAllGovernanceObjects()
std::vector<CGovernanceObject> ClientModel::getAllGovernanceObjects()
{
return m_node.gov().getAllNewerThan(0);
}
Expand Down
2 changes: 1 addition & 1 deletion src/qt/clientmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class ClientModel : public QObject
CDeterministicMNList getMasternodeList() const;
void refreshMasternodeList();

std::vector<const CGovernanceObject*> getAllGovernanceObjects();
std::vector<CGovernanceObject> getAllGovernanceObjects();

//! Returns enum BlockSource of the current importing/syncing state
enum BlockSource getBlockSource() const;
Expand Down
38 changes: 24 additions & 14 deletions src/qt/governancelist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
/// Proposal wrapper
///

Proposal::Proposal(const CGovernanceObject* p, QObject* parent) :
Proposal::Proposal(const CGovernanceObject _govObj, QObject* parent) :
QObject(parent),
pGovObj(p)
govObj(_govObj)
{
UniValue prop_data;
if (prop_data.read(pGovObj->GetDataAsPlainString())) {
if (prop_data.read(govObj.GetDataAsPlainString())) {
if (UniValue titleValue = find_value(prop_data, "name"); titleValue.isStr()) {
m_title = QString::fromStdString(titleValue.get_str());
}
Expand All @@ -52,7 +52,7 @@ Proposal::Proposal(const CGovernanceObject* p, QObject* parent) :

QString Proposal::title() const { return m_title; }

QString Proposal::hash() const { return QString::fromStdString(pGovObj->GetHash().ToString()); }
QString Proposal::hash() const { return QString::fromStdString(govObj.GetHash().ToString()); }

QDateTime Proposal::startDate() const { return m_startDate; }

Expand All @@ -66,18 +66,18 @@ bool Proposal::isActive() const
{
std::string strError;
LOCK(cs_main);
return pGovObj->IsValidLocally(strError, false);
return govObj.IsValidLocally(strError, false);
}

QString Proposal::votingStatus(const int nAbsVoteReq) const
{
// Voting status...
// TODO: determine if voting is in progress vs. funded or not funded for past proposals.
// see CSuperblock::GetNearestSuperblocksHeights(nBlockHeight, nLastSuperblock, nNextSuperblock);
const int absYesCount = pGovObj->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
const int absYesCount = govObj.GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
QString qStatusString;
if (absYesCount >= nAbsVoteReq) {
// Could use pGovObj->IsSetCachedFunding here, but need nAbsVoteReq to display numbers anyway.
// Could use govObj.IsSetCachedFunding here, but need nAbsVoteReq to display numbers anyway.
return tr("Passing +%1").arg(absYesCount - nAbsVoteReq);
} else {
return tr("Needs additional %1 votes").arg(nAbsVoteReq - absYesCount);
Expand All @@ -86,7 +86,7 @@ QString Proposal::votingStatus(const int nAbsVoteReq) const

int Proposal::GetAbsoluteYesCount() const
{
return pGovObj->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
return govObj.GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
}

void Proposal::openUrl() const
Expand All @@ -96,7 +96,7 @@ void Proposal::openUrl() const

QString Proposal::toJson() const
{
const auto json = pGovObj->ToJson();
const auto json = govObj.ToJson();
return QString::fromStdString(json.write(2));
}

Expand Down Expand Up @@ -222,6 +222,7 @@ void ProposalModel::append(const Proposal* proposal)
void ProposalModel::remove(int row)
{
beginRemoveRows({}, row, row);
delete m_data.at(row);
m_data.removeAt(row);
endRemoveRows();
}
Expand All @@ -239,6 +240,15 @@ void ProposalModel::reconcile(const std::vector<const Proposal*>& proposals)
if (m_data.at(i)->hash() == proposal->hash()) {
found = true;
keep_index.at(i) = true;
if (m_data.at(i)->GetAbsoluteYesCount() != proposal->GetAbsoluteYesCount()) {
// replace proposal to update vote count
delete m_data.at(i);
m_data.replace(i, proposal);
Q_EMIT dataChanged(createIndex(i, Column::VOTING_STATUS), createIndex(i, Column::VOTING_STATUS));
} else {
// no changes
delete proposal;
}
break;
}
}
Expand All @@ -260,7 +270,7 @@ void ProposalModel::setVotingParams(int newAbsVoteReq)
this->nAbsVoteReq = newAbsVoteReq;
// Changing either of the voting params may change the voting status
// column. Emit signal to force recalculation.
Q_EMIT dataChanged(createIndex(0, Column::VOTING_STATUS), createIndex(columnCount(), Column::VOTING_STATUS));
Q_EMIT dataChanged(createIndex(0, Column::VOTING_STATUS), createIndex(rowCount(), Column::VOTING_STATUS));
}
}

Expand Down Expand Up @@ -338,14 +348,14 @@ void GovernanceList::updateProposalList()
const int nAbsVoteReq = std::max(Params().GetConsensus().nGovernanceMinQuorum, nMnCount / 10);
proposalModel->setVotingParams(nAbsVoteReq);

const std::vector<const CGovernanceObject*> govObjList = clientModel->getAllGovernanceObjects();
const std::vector<CGovernanceObject> govObjList = clientModel->getAllGovernanceObjects();
std::vector<const Proposal*> newProposals;
for (const auto pGovObj : govObjList) {
if (pGovObj->GetObjectType() != GOVERNANCE_OBJECT_PROPOSAL) {
for (const auto& govObj : govObjList) {
if (govObj.GetObjectType() != GOVERNANCE_OBJECT_PROPOSAL) {
continue; // Skip triggers.
}

newProposals.emplace_back(new Proposal(pGovObj, proposalModel));
newProposals.emplace_back(new Proposal(govObj, proposalModel));
}
proposalModel->reconcile(newProposals);
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/governancelist.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class Proposal : public QObject
private:
Q_OBJECT

const CGovernanceObject* pGovObj;
const CGovernanceObject govObj;
QString m_title;
QDateTime m_startDate;
QDateTime m_endDate;
float m_paymentAmount;
QString m_url;

public:
explicit Proposal(const CGovernanceObject* p, QObject* parent = nullptr);
explicit Proposal(const CGovernanceObject _govObj, QObject* parent = nullptr);
QString title() const;
QString hash() const;
QDateTime startDate() const;
Expand Down
50 changes: 25 additions & 25 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -736,47 +736,47 @@ static UniValue ListObjects(const std::string& strCachedSignal, const std::strin

LOCK2(cs_main, governance.cs);

std::vector<const CGovernanceObject*> objs = governance.GetAllNewerThan(nStartTime);
std::vector<CGovernanceObject> objs = governance.GetAllNewerThan(nStartTime);
governance.UpdateLastDiffTime(GetTime());
// CREATE RESULTS FOR USER

for (const auto& pGovObj : objs) {
if (strCachedSignal == "valid" && !pGovObj->IsSetCachedValid()) continue;
if (strCachedSignal == "funding" && !pGovObj->IsSetCachedFunding()) continue;
if (strCachedSignal == "delete" && !pGovObj->IsSetCachedDelete()) continue;
if (strCachedSignal == "endorsed" && !pGovObj->IsSetCachedEndorsed()) continue;
for (const auto& govObj : objs) {
if (strCachedSignal == "valid" && !govObj.IsSetCachedValid()) continue;
if (strCachedSignal == "funding" && !govObj.IsSetCachedFunding()) continue;
if (strCachedSignal == "delete" && !govObj.IsSetCachedDelete()) continue;
if (strCachedSignal == "endorsed" && !govObj.IsSetCachedEndorsed()) continue;

if (strType == "proposals" && pGovObj->GetObjectType() != GOVERNANCE_OBJECT_PROPOSAL) continue;
if (strType == "triggers" && pGovObj->GetObjectType() != GOVERNANCE_OBJECT_TRIGGER) continue;
if (strType == "proposals" && govObj.GetObjectType() != GOVERNANCE_OBJECT_PROPOSAL) continue;
if (strType == "triggers" && govObj.GetObjectType() != GOVERNANCE_OBJECT_TRIGGER) continue;

UniValue bObj(UniValue::VOBJ);
bObj.pushKV("DataHex", pGovObj->GetDataAsHexString());
bObj.pushKV("DataString", pGovObj->GetDataAsPlainString());
bObj.pushKV("Hash", pGovObj->GetHash().ToString());
bObj.pushKV("CollateralHash", pGovObj->GetCollateralHash().ToString());
bObj.pushKV("ObjectType", pGovObj->GetObjectType());
bObj.pushKV("CreationTime", pGovObj->GetCreationTime());
const COutPoint& masternodeOutpoint = pGovObj->GetMasternodeOutpoint();
bObj.pushKV("DataHex", govObj.GetDataAsHexString());
bObj.pushKV("DataString", govObj.GetDataAsPlainString());
bObj.pushKV("Hash", govObj.GetHash().ToString());
bObj.pushKV("CollateralHash", govObj.GetCollateralHash().ToString());
bObj.pushKV("ObjectType", govObj.GetObjectType());
bObj.pushKV("CreationTime", govObj.GetCreationTime());
const COutPoint& masternodeOutpoint = govObj.GetMasternodeOutpoint();
if (masternodeOutpoint != COutPoint()) {
bObj.pushKV("SigningMasternode", masternodeOutpoint.ToStringShort());
}

// REPORT STATUS FOR FUNDING VOTES SPECIFICALLY
bObj.pushKV("AbsoluteYesCount", pGovObj->GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("YesCount", pGovObj->GetYesCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("NoCount", pGovObj->GetNoCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("AbstainCount", pGovObj->GetAbstainCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("AbsoluteYesCount", govObj.GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("YesCount", govObj.GetYesCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("NoCount", govObj.GetNoCount(VOTE_SIGNAL_FUNDING));
bObj.pushKV("AbstainCount", govObj.GetAbstainCount(VOTE_SIGNAL_FUNDING));

// REPORT VALIDITY AND CACHING FLAGS FOR VARIOUS SETTINGS
std::string strError = "";
bObj.pushKV("fBlockchainValidity", pGovObj->IsValidLocally(strError, false));
bObj.pushKV("fBlockchainValidity", govObj.IsValidLocally(strError, false));
bObj.pushKV("IsValidReason", strError.c_str());
bObj.pushKV("fCachedValid", pGovObj->IsSetCachedValid());
bObj.pushKV("fCachedFunding", pGovObj->IsSetCachedFunding());
bObj.pushKV("fCachedDelete", pGovObj->IsSetCachedDelete());
bObj.pushKV("fCachedEndorsed", pGovObj->IsSetCachedEndorsed());
bObj.pushKV("fCachedValid", govObj.IsSetCachedValid());
bObj.pushKV("fCachedFunding", govObj.IsSetCachedFunding());
bObj.pushKV("fCachedDelete", govObj.IsSetCachedDelete());
bObj.pushKV("fCachedEndorsed", govObj.IsSetCachedEndorsed());

objResult.pushKV(pGovObj->GetHash().ToString(), bObj);
objResult.pushKV(govObj.GetHash().ToString(), bObj);
}

return objResult;
Expand Down