Skip to content

Commit 5c88045

Browse files
committed
[Refactor] Initialize Gov Objects from serialized messages
1 parent d0f0705 commit 5c88045

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/masternode-budget.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,25 +1032,25 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
10321032
LogPrint(BCLog::MNBUDGET, "mnvs - Sent Masternode votes to peer %i\n", pfrom->GetId());
10331033
}
10341034

1035-
if (strCommand == NetMsgType::BUDGETPROPOSAL) { //Masternode Proposal
1036-
CBudgetProposalBroadcast budgetProposalBroadcast;
1037-
vRecv >> budgetProposalBroadcast;
1038-
1039-
const uint256& nHash = budgetProposalBroadcast.GetHash();
1035+
if (strCommand == NetMsgType::BUDGETPROPOSAL) {
1036+
// Masternode Proposal
1037+
CBudgetProposal proposal;
1038+
if (!proposal.ParseBroadcast(vRecv)) {
1039+
// !TODO: we should probably call misbehaving here
1040+
return;
1041+
}
1042+
const uint256& nHash = proposal.GetHash();
10401043
if (HaveProposal(nHash)) {
10411044
masternodeSync.AddedBudgetItem(nHash);
10421045
return;
10431046
}
1044-
1045-
CBudgetProposal budgetProposal(budgetProposalBroadcast);
1046-
if (!AddProposal(budgetProposal)) {
1047+
if (!AddProposal(proposal)) {
10471048
return;
10481049
}
1049-
budgetProposalBroadcast.Relay();
1050+
proposal.Relay();
10501051
masternodeSync.AddedBudgetItem(nHash);
10511052

10521053
LogPrint(BCLog::MNBUDGET,"mprop (new) %s\n", nHash.ToString());
1053-
10541054
//We might have active votes for this proposal that are valid now
10551055
CheckOrphanVotes();
10561056
}
@@ -1095,25 +1095,25 @@ void CBudgetManager::ProcessMessage(CNode* pfrom, std::string& strCommand, CData
10951095
LogPrint(BCLog::MNBUDGET,"mvote - new budget vote for budget %s - %s\n", vote.GetProposalHash().ToString(), vote.GetHash().ToString());
10961096
}
10971097

1098-
if (strCommand == NetMsgType::FINALBUDGET) { //Finalized Budget Suggestion
1099-
CFinalizedBudgetBroadcast finalizedBudgetBroadcast;
1100-
vRecv >> finalizedBudgetBroadcast;
1101-
1102-
const uint256& nHash = finalizedBudgetBroadcast.GetHash();
1098+
if (strCommand == NetMsgType::FINALBUDGET) {
1099+
// Finalized Budget Suggestion
1100+
CFinalizedBudget finalbudget;
1101+
if (!finalbudget.ParseBroadcast(vRecv)) {
1102+
// !TODO: we should probably call misbehaving here
1103+
return;
1104+
}
1105+
const uint256& nHash = finalbudget.GetHash();
11031106
if (HaveFinalizedBudget(nHash)) {
11041107
masternodeSync.AddedBudgetItem(nHash);
11051108
return;
11061109
}
1107-
1108-
CFinalizedBudget finalizedBudget(finalizedBudgetBroadcast);
1109-
if (!AddFinalizedBudget(finalizedBudget)) {
1110+
if (!AddFinalizedBudget(finalbudget)) {
11101111
return;
11111112
}
1112-
finalizedBudgetBroadcast.Relay();
1113+
finalbudget.Relay();
11131114
masternodeSync.AddedBudgetItem(nHash);
11141115

11151116
LogPrint(BCLog::MNBUDGET,"fbs (new) %s\n", nHash.ToString());
1116-
11171117
//we might have active votes for this budget that are now valid
11181118
CheckOrphanVotes();
11191119
}
@@ -1614,6 +1614,12 @@ inline bool CBudgetProposal::PtrHigherYes(CBudgetProposal* a, CBudgetProposal* b
16141614
return netYes_a > netYes_b;
16151615
}
16161616

1617+
void CBudgetProposal::Relay()
1618+
{
1619+
CInv inv(MSG_BUDGET_PROPOSAL, GetHash());
1620+
g_connman->RelayInv(inv);
1621+
}
1622+
16171623
CBudgetProposalBroadcast::CBudgetProposalBroadcast(std::string strProposalNameIn, std::string strURLIn, int nPaymentCount, CScript addressIn, CAmount nAmountIn, int nBlockStartIn, uint256 nFeeTXHashIn)
16181624
{
16191625
strProposalName = strProposalNameIn;
@@ -2183,6 +2189,12 @@ bool CFinalizedBudget::operator>(const CFinalizedBudget& other) const
21832189
return count > otherCount;
21842190
}
21852191

2192+
void CFinalizedBudget::Relay()
2193+
{
2194+
CInv inv(MSG_BUDGET_FINALIZED, GetHash());
2195+
g_connman->RelayInv(inv);
2196+
}
2197+
21862198
CFinalizedBudgetBroadcast::CFinalizedBudgetBroadcast() :
21872199
CFinalizedBudget()
21882200
{ }

src/masternode-budget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ class CFinalizedBudget
467467
// Serialization for network messages.
468468
bool ParseBroadcast(CDataStream& broadcast);
469469
CDataStream GetBroadcast() const;
470+
void Relay();
470471

471472
// compare finalized budget by votes (sort tie with feeHash)
472473
bool operator>(const CFinalizedBudget& other) const;
@@ -625,6 +626,7 @@ class CBudgetProposal
625626
// Serialization for network messages.
626627
bool ParseBroadcast(CDataStream& broadcast);
627628
CDataStream GetBroadcast() const;
629+
void Relay();
628630

629631
// compare proposals by proposal hash
630632
inline bool operator>(const CBudgetProposal& other) const { return GetHash() > other.GetHash(); }

0 commit comments

Comments
 (0)