diff --git a/.gitignore b/.gitignore index 770c046ce..3a3827fd0 100644 --- a/.gitignore +++ b/.gitignore @@ -47,60 +47,14 @@ src/qt/.deps src/qt/.dirstamp src/qt/bitcoin.moc src/qt/bitcoinamountfield.moc -src/qt/moc_aboutdialog.cpp -src/qt/moc_addressbookpage.cpp -src/qt/moc_addresstablemodel.cpp -src/qt/moc_askpassphrasedialog.cpp -src/qt/moc_bip38tooldialog.cpp -src/qt/moc_bitcoinaddressvalidator.cpp -src/qt/moc_bitcoinamountfield.cpp -src/qt/moc_bitcoingui.cpp -src/qt/moc_bitcoinunits.cpp -src/qt/moc_clientmodel.cpp -src/qt/moc_coincontroldialog.cpp -src/qt/moc_coincontroltreewidget.cpp -src/qt/moc_csvmodelwriter.cpp -src/qt/moc_editaddressdialog.cpp -src/qt/moc_guiutil.cpp -src/qt/moc_macdockiconhandler.cpp -src/qt/moc_monitoreddatamapper.cpp -src/qt/moc_notificator.cpp -src/qt/moc_optionsdialog.cpp -src/qt/moc_optionsmodel.cpp -src/qt/moc_overviewpage.cpp -src/qt/moc_qrcodedialog.cpp -src/qt/moc_qvalidatedlineedit.cpp -src/qt/moc_qvaluecombobox.cpp -src/qt/moc_rpcconsole.cpp -src/qt/moc_sendcoinsdialog.cpp -src/qt/moc_sendcoinsentry.cpp -src/qt/moc_signverifymessagedialog.cpp -src/qt/moc_transactiondesc.cpp -src/qt/moc_transactiondescdialog.cpp -src/qt/moc_transactionfilterproxy.cpp -src/qt/moc_transactiontablemodel.cpp -src/qt/moc_transactionview.cpp -src/qt/moc_walletmodel.cpp +src/qt/moc_* src/qt/overviewpage.moc src/qt/rpcconsole.moc Makefile.in src/config/bitcoin-config.h src/config/bitcoin-config.h.in src/config/stamp-h1 -src/qt/forms/ui_aboutdialog.h -src/qt/forms/ui_addressbookpage.h -src/qt/forms/ui_askpassphrasedialog.h -src/qt/forms/ui_bip38tooldialog.h -src/qt/forms/ui_coincontroldialog.h -src/qt/forms/ui_editaddressdialog.h -src/qt/forms/ui_optionsdialog.h -src/qt/forms/ui_overviewpage.h -src/qt/forms/ui_qrcodedialog.h -src/qt/forms/ui_rpcconsole.h -src/qt/forms/ui_sendcoinsdialog.h -src/qt/forms/ui_sendcoinsentry.h -src/qt/forms/ui_signverifymessagedialog.h -src/qt/forms/ui_transactiondescdialog.h +src/qt/forms/ui_* config.log config.status libtool diff --git a/src/main.cpp b/src/main.cpp index e4581b757..7513697d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -711,6 +711,17 @@ bool CTxMemPool::accept(CTxDB& txdb, CTransaction &tx, bool fCheckInputs, if (ptxOld) EraseFromWallets(ptxOld->GetHash()); + // If the transaction is a proposal then verify validity + if (tx.IsProposal()) { + CVoteProposal proposal; + ProposalFromTransaction(tx, proposal); + + // Verify that the proposal is valid + if(!proposalManager.CheckProposal(proposal)) { + return error("CTxMemPool::accept() : Invalid Proposal %s", hash.ToString().substr(0,10).c_str()); + } + } + printf("CTxMemPool::accept() : accepted %s (poolsz %lu)\n", hash.ToString().substr(0,10).c_str(), mapTx.size()); diff --git a/src/voteproposalmanager.cpp b/src/voteproposalmanager.cpp index 48307e4f7..c65186925 100644 --- a/src/voteproposalmanager.cpp +++ b/src/voteproposalmanager.cpp @@ -7,6 +7,42 @@ using namespace std; +bool CVoteProposalManager::CheckProposal(const CVoteProposal &proposal) +{ + // If the proposal is already in the blockchain then it's guaranteed to be valid + if (mapProposalData.count(proposal.GetHash()) != 0) { + return true; + } + + // Proposal name length must be between 1 and MAX_CHAR_NAME (inclusive) + if (proposal.GetName().empty() || proposal.GetName().size() > MAX_CHAR_NAME) { + return false; + } + + // Proposal description length must be between 1 and MAX_CHAR_ABSTRACT (inclusive) + if (proposal.GetDescription().empty() || proposal.GetDescription().size() > MAX_CHAR_ABSTRACT) { + return false; + } + + // Proposal voting period cannot start before or at the current height or after MAX_BLOCKS_IN_FUTURE + if (proposal.GetStartHeight() <= nBestHeight || proposal.GetStartHeight() > nBestHeight + MAX_BLOCKS_IN_FUTURE) { + return false; + } + + // Proposal voting period length must be between 1 and MAX_CHECKSPAN (inclusive) + if (!proposal.GetCheckSpan() || proposal.GetCheckSpan() > MAX_CHECKSPAN) { + return false; + } + + // Check to see if there is room on the blockchain for this proposal + VoteLocation location; + if (!GetNextLocation(proposal.GetBitCount(), proposal.GetStartHeight(), proposal.GetCheckSpan(), location)) { + return false; + } + + return true; +} + //! Add a proposal to the manager. Note that it must not have conflicts in its scheduling. bool CVoteProposalManager::Add(const CVoteProposal& proposal) { diff --git a/src/voteproposalmanager.h b/src/voteproposalmanager.h index 9195f9405..99d92b1ab 100644 --- a/src/voteproposalmanager.h +++ b/src/voteproposalmanager.h @@ -28,6 +28,7 @@ class CVoteProposalManager std::map GetActive(int nHeight); bool GetNextLocation(int nBitCount, int nStartHeight, int nCheckSpan, VoteLocation& location); std::map GetAllProposals() const { return mapProposalData; }; + bool CheckProposal (const CVoteProposal& proposal); }; #endif //HYPERSTAKE_VOTEPROPOSALMANAGER_H