@@ -1492,7 +1492,9 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
14921492 return DoS (100 , error (" ConnectInputs() : nFees out of range" ));
14931493 }
14941494 }
1495- else {
1495+
1496+ // If the given transaction is coinbase then check for correct refund outputs
1497+ else if (VOTING_START >= pindexBlock->nHeight ){
14961498 CBlock block;
14971499 if (!block.ReadFromDisk (pindexBlock))
14981500 return error (" ConnectInputs() : ReadFromDisk for connect failed" );
@@ -1612,7 +1614,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
16121614 else
16131615 nTxPos = pindex->nBlockPos + ::GetSerializeSize (CBlock (), SER_DISK , CLIENT_VERSION ) - (2 * GetSizeOfCompactSize (0 )) + GetSizeOfCompactSize (vtx.size ());
16141616
1615- vector<uint256> vQueuedProposals ;
1617+ vector<CTransaction> vQueuedTxProposals ;
16161618 map<uint256, CTxIndex> mapQueuedChanges;
16171619 int64 nFees = 0 ;
16181620 int64 nValueIn = 0 ;
@@ -1674,11 +1676,7 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
16741676 return error (" Proposal was not successfully extracted from transaction. This shouldn't happen." );
16751677 }
16761678
1677- int nFee = CVoteProposal::BASE_FEE ;
1678-
1679- // Needs to have the proper fee or else it will not be counted
1680- if (nTxValueIn - nTxValueOut >= nFee - MIN_TXOUT_AMOUNT )
1681- vQueuedProposals.push_back (hashTx);
1679+ vQueuedTxProposals.push_back (tx);
16821680 }
16831681 }
16841682
@@ -1697,21 +1695,34 @@ bool CBlock::ConnectBlock(CTxDB& txdb, CBlockIndex* pindex, bool fJustCheck)
16971695 if (fJustCheck )
16981696 return true ;
16991697
1698+ // TODO: LOG ERRORS OR TERMINATE METHOD AND RETURN ERROR?
1699+ vector<CTransaction> vOrderedTxProposals;
1700+ if (!proposalManager.GetDeterministicOrdering (pindex->pprev ->hashProofOfStake , vQueuedTxProposals, vOrderedTxProposals)) {
1701+ printf (" ConnectBlock() : encountered error when determining deterministic ordering of proposals." );
1702+ }
1703+
1704+ vector<CTransaction> vAcceptedTxProposals;
1705+ if (!proposalManager.GetAcceptedTxProposals (vtx[0 ], vOrderedTxProposals, vAcceptedTxProposals)) {
1706+ printf (" ConnectBlock() : encountered error when extracting accepted proposals from coinbase" );
1707+ }
1708+
17001709 // Keep track of any vote proposals that were added to the blockchain
17011710 CVoteDB voteDB;
1702- if (vQueuedProposals.size ()) {
1703- for (const CTransaction& tx : vtx) {
1704- uint256 txid = tx.GetHash ();
1705- if (count (vQueuedProposals.begin (), vQueuedProposals.end (), txid)) {
1706- CVoteProposal proposal;
1707- if (ProposalFromTransaction (tx, proposal)) {
1708- mapProposals[txid] = proposal.GetHash ();
1709- if (!voteDB.WriteProposal (txid, proposal))
1710- printf (" %s : failed to record proposal to db\n " , __func__);
1711- else if (!proposalManager.Add (proposal))
1712- printf (" %s: failed to add proposal %s to manager\n " , __func__, txid.GetHex ().c_str ());
1713- }
1714- }
1711+ for (const CTransaction& txProposal: vAcceptedTxProposals) {
1712+
1713+ // if the proposal isn't able to be extracted from transaction then skip it
1714+ CVoteProposal proposal;
1715+ if (!ProposalFromTransaction (txProposal, proposal)) {
1716+ printf (" Proposal was not successfully extracted from transaction. This shouldn't happen." );
1717+ continue ;
1718+ }
1719+
1720+ // store proposal hash in mapProposals and store proposal on disk for later use
1721+ mapProposals[txProposal.GetHash ()] = proposal.GetHash ();
1722+ if (!voteDB.WriteProposal (txProposal.GetHash (), proposal)) {
1723+ printf (" %s : failed to record proposal to db\n " , __func__);
1724+ } else if (!proposalManager.Add (proposal)) {
1725+ printf (" %s: failed to add proposal %s to manager\n " , __func__, txProposal.GetHash ().GetHex ().c_str ());
17151726 }
17161727 }
17171728
0 commit comments