Skip to content

Commit aba57ce

Browse files
kwvgPastaPastaPasta
authored andcommitted
qt: add interface for CGovernanceObject querying
The GetAbsoluteYesCount -> Get{Yes,No}Count -> CountMatchingVotes call chain eventually results in needing to call GetListAtChainTip from the CDeterministicMNManager instance. Currently it's being accessed as a global but future deglobalization will move fetching the CDeterministicMNList outside CGovernanceObject, requiring an instance of CDeterministicMNManager. In preparation of that, these changes are being made in advance.
1 parent 8d73cec commit aba57ce

File tree

5 files changed

+38
-11
lines changed

5 files changed

+38
-11
lines changed

src/governance/vote.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class CKey;
1616
class CKeyID;
1717

1818
// INTENTION OF MASTERNODES REGARDING ITEM
19-
enum vote_outcome_enum_t {
19+
enum vote_outcome_enum_t : uint8_t {
2020
VOTE_OUTCOME_NONE = 0,
2121
VOTE_OUTCOME_YES = 1,
2222
VOTE_OUTCOME_NO = 2,
@@ -25,7 +25,7 @@ enum vote_outcome_enum_t {
2525

2626

2727
// SIGNAL VARIOUS THINGS TO HAPPEN:
28-
enum vote_signal_enum_t {
28+
enum vote_signal_enum_t : uint8_t {
2929
VOTE_SIGNAL_NONE = 0,
3030
VOTE_SIGNAL_FUNDING = 1, // -- fund this object for it's stated amount
3131
VOTE_SIGNAL_VALID = 2, // -- this object checks out in sentinel engine

src/interfaces/node.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ enum class SynchronizationState;
3737
struct CNodeStateStats;
3838
struct NodeContext;
3939

40+
enum vote_signal_enum_t : uint8_t;
41+
4042
namespace interfaces {
4143
class Handler;
4244
class WalletLoader;
@@ -59,6 +61,8 @@ class GOV
5961
public:
6062
virtual ~GOV() {}
6163
virtual void getAllNewerThan(std::vector<CGovernanceObject> &objs, int64_t nMoreThanTime) = 0;
64+
virtual int32_t getObjAbsYesCount(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) = 0;
65+
virtual bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_collateral) = 0;
6266
};
6367

6468
//! Interface for the src/llmq part of a dash node (dashd process).

src/node/interfaces.cpp

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,29 @@ class GOVImpl : public GOV
100100
public:
101101
void getAllNewerThan(std::vector<CGovernanceObject> &objs, int64_t nMoreThanTime) override
102102
{
103-
if (governance == nullptr) return;
104-
governance->GetAllNewerThan(objs, nMoreThanTime);
103+
if (::governance != nullptr) {
104+
return ::governance->GetAllNewerThan(objs, nMoreThanTime);
105+
}
106+
return;
107+
}
108+
int32_t getObjAbsYesCount(const CGovernanceObject& obj, vote_signal_enum_t vote_signal) override
109+
{
110+
// TODO: Move GetListAtChainTip query outside CGovernanceObject, query requires
111+
// active CDeterministicMNManager instance
112+
if (::governance != nullptr && ::deterministicMNManager != nullptr) {
113+
return obj.GetAbsoluteYesCount(vote_signal);
114+
}
115+
return 0;
116+
}
117+
bool getObjLocalValidity(const CGovernanceObject& obj, std::string& error, bool check_collateral) override
118+
{
119+
// TODO: Move GetListAtChainTip query outside CGovernanceObject, query requires
120+
// active CDeterministicMNManager instance
121+
if (::governance != nullptr && ::deterministicMNManager != nullptr) {
122+
LOCK(cs_main);
123+
return obj.IsValidLocally(error, check_collateral);
124+
}
125+
return false;
105126
}
106127
};
107128

src/qt/governancelist.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@
2626
/// Proposal wrapper
2727
///
2828

29-
Proposal::Proposal(const CGovernanceObject& _govObj, QObject* parent) :
29+
Proposal::Proposal(ClientModel* _clientModel, const CGovernanceObject& _govObj, QObject* parent) :
3030
QObject(parent),
31+
clientModel(_clientModel),
3132
govObj(_govObj)
3233
{
3334
UniValue prop_data;
@@ -68,17 +69,16 @@ QString Proposal::url() const { return m_url; }
6869

6970
bool Proposal::isActive() const
7071
{
71-
LOCK(cs_main);
7272
std::string strError;
73-
return govObj.IsValidLocally(strError, false);
73+
return clientModel->node().gov().getObjLocalValidity(govObj, strError, false);
7474
}
7575

7676
QString Proposal::votingStatus(const int nAbsVoteReq) const
7777
{
7878
// Voting status...
7979
// TODO: determine if voting is in progress vs. funded or not funded for past proposals.
8080
// see CSuperblock::GetNearestSuperblocksHeights(nBlockHeight, nLastSuperblock, nNextSuperblock);
81-
const int absYesCount = govObj.GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
81+
const int absYesCount = clientModel->node().gov().getObjAbsYesCount(govObj, VOTE_SIGNAL_FUNDING);
8282
QString qStatusString;
8383
if (absYesCount >= nAbsVoteReq) {
8484
// Could use govObj.IsSetCachedFunding here, but need nAbsVoteReq to display numbers anyway.
@@ -90,7 +90,7 @@ QString Proposal::votingStatus(const int nAbsVoteReq) const
9090

9191
int Proposal::GetAbsoluteYesCount() const
9292
{
93-
return govObj.GetAbsoluteYesCount(VOTE_SIGNAL_FUNDING);
93+
return clientModel->node().gov().getObjAbsYesCount(govObj, VOTE_SIGNAL_FUNDING);
9494
}
9595

9696
void Proposal::openUrl() const
@@ -360,7 +360,7 @@ void GovernanceList::updateProposalList()
360360
continue; // Skip triggers.
361361
}
362362

363-
newProposals.emplace_back(new Proposal(govObj, proposalModel));
363+
newProposals.emplace_back(new Proposal(this->clientModel, govObj, proposalModel));
364364
}
365365
proposalModel->reconcile(newProposals);
366366
}

src/qt/governancelist.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,17 @@ class Proposal : public QObject
5959
private:
6060
Q_OBJECT
6161

62+
ClientModel* clientModel;
6263
const CGovernanceObject govObj;
64+
6365
QString m_title;
6466
QDateTime m_startDate;
6567
QDateTime m_endDate;
6668
float m_paymentAmount;
6769
QString m_url;
6870

6971
public:
70-
explicit Proposal(const CGovernanceObject& _govObj, QObject* parent = nullptr);
72+
explicit Proposal(ClientModel* _clientModel, const CGovernanceObject& _govObj, QObject* parent = nullptr);
7173
QString title() const;
7274
QString hash() const;
7375
QDateTime startDate() const;

0 commit comments

Comments
 (0)