From 2df4059f4ef4334fb96a8e71f8d7f9352bdeaf55 Mon Sep 17 00:00:00 2001 From: Evan Duffield Date: Tue, 26 Apr 2016 10:45:06 -0700 Subject: [PATCH] Fix masternode voting object --- src/governance-vote.cpp | 53 ++++++++++++++++++++++------------------- src/governance-vote.h | 2 +- 2 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/governance-vote.cpp b/src/governance-vote.cpp index d5d5f9d07..8c1f46e6b 100644 --- a/src/governance-vote.cpp +++ b/src/governance-vote.cpp @@ -20,19 +20,20 @@ CBudgetVote::CBudgetVote() { - // vin = CTxIn(); - // nProposalHash = uint256(); + vinMasternode = CTxIn(); + nParentHash = uint256(); nVoteAction = VOTE_ACTION_NONE; nVoteOutcome = VOTE_OUTCOME_NONE; nTime = 0; fValid = true; fSynced = false; + vchSig.clear(); } -CBudgetVote::CBudgetVote(CTxIn vinIn, uint256 nProposalHashIn, int nVoteActionIn, int nVoteOutcomeIn) +CBudgetVote::CBudgetVote(CTxIn vinMasternodeIn, uint256 nParentHashIn, int nVoteActionIn, int nVoteOutcomeIn) { - // vin = vinIn; - // nProposalHash = nProposalHashIn; + vinMasternode = vinMasternodeIn; + nParentHash = nParentHashIn; nVoteAction = nVoteActionIn; nVoteOutcome = nVoteOutcomeIn; nTime = GetAdjustedTime(); @@ -53,17 +54,18 @@ bool CBudgetVote::Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode) CKey keyCollateralAddress; std::string errorMessage; - // std::string strMessage = vin.prevout.ToStringShort() + nProposalHash.ToString() + boost::lexical_cast(nVote) + boost::lexical_cast(nTime); + std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" + + boost::lexical_cast(nVoteAction) + "|" + boost::lexical_cast(nVoteOutcome) + "|" + boost::lexical_cast(nTime); - // if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) { - // LogPrintf("CBudgetVote::Sign - Error upon calling SignMessage"); - // return false; - // } + if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchSig, keyMasternode)) { + LogPrintf("CBudgetVote::Sign - Error upon calling SignMessage"); + return false; + } - // if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) { - // LogPrintf("CBudgetVote::Sign - Error upon calling VerifyMessage"); - // return false; - // } + if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchSig, strMessage, errorMessage)) { + LogPrintf("CBudgetVote::Sign - Error upon calling VerifyMessage"); + return false; + } return true; } @@ -89,22 +91,23 @@ bool CBudgetVote::IsValid(bool fSignatureCheck) return false; } - // CMasternode* pmn = mnodeman.Find(vin); - // if(pmn == NULL) - // { - // LogPrint("mngovernance", "CBudgetVote::IsValid() - Unknown Masternode - %s\n", vin.ToString()); - // return false; - // } + CMasternode* pmn = mnodeman.Find(vinMasternode); + if(pmn == NULL) + { + LogPrint("mngovernance", "CBudgetVote::IsValid() - Unknown Masternode - %s\n", vinMasternode.ToString()); + return false; + } if(!fSignatureCheck) return true; std::string errorMessage; - // std::string strMessage = vin.prevout.ToStringShort() + nProposalHash.ToString() + boost::lexical_cast(nVote) + boost::lexical_cast(nTime); + std::string strMessage = vinMasternode.prevout.ToStringShort() + "|" + nParentHash.ToString() + "|" + + boost::lexical_cast(nVoteAction) + "|" + boost::lexical_cast(nVoteOutcome) + "|" + boost::lexical_cast(nTime); - // if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) { - // LogPrintf("CBudgetVote::IsValid() - Verify message failed - Error: %s\n", errorMessage); - // return false; - // } + if(!darkSendSigner.VerifyMessage(pmn->pubkey2, vchSig, strMessage, errorMessage)) { + LogPrintf("CBudgetVote::IsValid() - Verify message failed - Error: %s\n", errorMessage); + return false; + } return true; } \ No newline at end of file diff --git a/src/governance-vote.h b/src/governance-vote.h index 9f96db412..dbc743cb9 100644 --- a/src/governance-vote.h +++ b/src/governance-vote.h @@ -51,7 +51,7 @@ public: std::vector vchSig; CBudgetVote(); - CBudgetVote(CTxIn vinMasternode, uint256 nParentHash, int nVoteActionIn, int nVoteOutcomeIn); + CBudgetVote(CTxIn vinMasternodeIn, uint256 nParentHashIn, int nVoteActionIn, int nVoteOutcomeIn); bool Sign(CKey& keyMasternode, CPubKey& pubKeyMasternode); bool IsValid(bool fSignatureCheck);