Skip to content

Commit decea43

Browse files
committed
removed debug statements and added voting tests
1 parent 229ee81 commit decea43

7 files changed

Lines changed: 227 additions & 70 deletions

File tree

src/main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -333,11 +333,19 @@ bool CTransaction::IsProposal() const
333333
for (unsigned int i = 0; i < vout.size(); i++) {
334334
CScript scriptPubKey = vout[i].scriptPubKey;
335335
if (scriptPubKey.IsDataCarrier()) {
336-
if (scriptPubKey.size() >= 5) {
336+
if (scriptPubKey.size() > 0x4c) {
337+
// "PROP" in ascii
338+
if (scriptPubKey.at(3) == 0x70 && scriptPubKey.at(4) == 0x72 && scriptPubKey.at(5) == 0x6f &&
339+
scriptPubKey.at(6) == 0x70) {
340+
return true;
341+
}
342+
}
343+
else if(scriptPubKey.size() > 6) {
337344
// "PROP" in ascii
338345
if (scriptPubKey.at(2) == 0x70 && scriptPubKey.at(3) == 0x72 && scriptPubKey.at(4) == 0x6f &&
339-
scriptPubKey.at(5) == 0x70)
346+
scriptPubKey.at(5) == 0x70) {
340347
return true;
348+
}
341349
}
342350
}
343351
}

src/script.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,13 +1359,11 @@ bool Sign1(const CKeyID& address, const CKeyStore& keystore, uint256 hash, int n
13591359
{
13601360
CKey key;
13611361
if (!keystore.GetKey(address, key)) {
1362-
printf("could not find the right key ******************");
13631362
return false;
13641363
}
13651364

13661365
vector<unsigned char> vchSig;
13671366
if (!key.Sign(hash, vchSig)) {
1368-
printf("signing failed :( *****************");
13691367
return false;
13701368
}
13711369
vchSig.push_back((unsigned char)nHashType);
@@ -1407,17 +1405,12 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
14071405
switch (whichTypeRet)
14081406
{
14091407
case TX_NONSTANDARD:
1410-
printf("****************** tx is not standard");
14111408
return false;
14121409
case TX_PUBKEY:
14131410
keyID = CPubKey(vSolutions[0]).GetID();
1414-
printf("***************** tx is pubkey: %s", keyID.ToString());
1415-
printf("\n");
14161411
return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
14171412
case TX_PUBKEYHASH:
14181413
keyID = CKeyID(uint160(vSolutions[0]));
1419-
printf("***************** tx is pubkeyhash: %s", uint160(vSolutions[0]));
1420-
printf("\n");
14211414
if (!Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
14221415
return false;
14231416
else
@@ -1428,15 +1421,12 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
14281421
}
14291422
return true;
14301423
case TX_SCRIPTHASH:
1431-
printf("***************** tx is scripthash");
14321424
return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet);
14331425

14341426
case TX_MULTISIG:
1435-
printf("***************** tx is multisig");
14361427
scriptSigRet << OP_0; // workaround CHECKMULTISIG bug
14371428
return (SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
14381429
case TX_NULL_DATA:
1439-
printf("**************** tx is null data");
14401430
return true;
14411431
}
14421432
return false;
@@ -1658,7 +1648,6 @@ bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CTransa
16581648

16591649
txnouttype whichType;
16601650
if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType)) {
1661-
printf("******************** solver failed :(");
16621651
return false;
16631652
}
16641653

src/test/voting_tests.cpp

Lines changed: 200 additions & 41 deletions
Large diffs are not rendered by default.

src/voteproposal.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ bool CVoteProposal::IsValid() const
2121
return error("Abstract needs to be between 1 and %d characters long", MAX_CHAR_ABSTRACT);
2222
}
2323

24-
if (nStartHeight <= nBestHeight || nStartHeight > nBestHeight + MAX_BLOCKS_IN_FUTURE) {
25-
return error("Start height needs to be greater than current height (%d) and less than %d.", nBestHeight, (nStartHeight + MAX_BLOCKS_IN_FUTURE));
26-
}
27-
2824
if (!nCheckSpan || nCheckSpan > MAX_CHECKSPAN) {
2925
return error("Voting length needs to be between 1 and %d blocks", MAX_CHECKSPAN);
3026
}
@@ -84,7 +80,9 @@ bool ProposalFromTransaction(const CTransaction& tx, CVoteProposal& proposal)
8480
vector<unsigned char> vchProposal;
8581

8682
CScript scriptProposal = tx.vout[0].scriptPubKey;
87-
vchProposal.insert(vchProposal.end(), scriptProposal.begin() + 6, scriptProposal.end());
83+
84+
vchProposal.insert(vchProposal.end(), scriptProposal.begin() + (scriptProposal.size() > 0x04c ? 7 : 6), scriptProposal.end());
85+
8886
CDataStream ss(vchProposal, SER_NETWORK, 0);
8987

9088
try {

src/voteproposalmanager.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,25 +202,24 @@ bool CVoteProposalManager::GetFee(const CVoteProposal& proposal, int& nFee)
202202
return true;
203203
}
204204

205-
bool CVoteProposalManager::GetDeterministicOrdering(const uint256 &proofhash, std::vector<CTransaction> &vProposalTransactions,
205+
bool CVoteProposalManager::GetDeterministicOrdering(const uint256 &proofhash, std::vector<CTransaction> vProposalTransactions,
206206
std::vector<CTransaction> &vOrderedProposalTransactions)
207207
{
208-
int nMask = 0x000FFFFF;
209-
int nSegmentSize = 20;
208+
uint256 nMask(0x000FFFFF);
210209
int nSegmentOffset = 0;
211210
while(!vProposalTransactions.empty()) {
212-
uint256 nFormattedMask = nMask << (nSegmentOffset * nSegmentSize);
213-
int segment = (int)((proofhash & nFormattedMask) >> (nSegmentOffset * nSegmentOffset)).Get64();
211+
uint256 nFormattedMask = nMask << (nSegmentOffset);
212+
int segment = (int)((proofhash & nFormattedMask) >> (nSegmentOffset)).Get64();
214213
int index = (int)(segment % vProposalTransactions.size());
215214

216215
if(segment < 0 || index < 0) {
217216
return error("Generated index is invalid");
218217
}
219218

220219
vOrderedProposalTransactions.emplace_back(vProposalTransactions.at(index));
221-
vProposalTransactions.erase(vProposalTransactions.begin() + index);
222220

223-
nSegmentOffset = (nSegmentOffset + nSegmentSize) % 256;
221+
vProposalTransactions.erase(vProposalTransactions.begin() + index);
222+
nSegmentOffset = (nSegmentOffset + segment) % 235;
224223
}
225224

226225
return true;
@@ -256,6 +255,9 @@ bool CVoteProposalManager::CheckRefundTransaction(const std::vector<CTransaction
256255
}
257256

258257
CTransaction txExpectedCoinBase;
258+
txExpectedCoinBase.vin.resize(1);
259+
txExpectedCoinBase.vin[0].prevout.SetNull();
260+
txExpectedCoinBase.vout.resize(1);
259261

260262
for(auto txProposal: vOrderedTxProposals) {
261263
// output variables
@@ -294,6 +296,10 @@ bool CVoteProposalManager::CheckRefundTransaction(const std::vector<CTransaction
294296
}
295297
}
296298

299+
if (txCoinBase.vout.size() != txExpectedCoinBase.vout.size()) {
300+
return error("CheckRefundTransaction() : The output vector of the coinbase transaction isn't the correct size.");
301+
}
302+
297303
for(int i = 0; i < txCoinBase.vout.size(); i++) {
298304
if(txCoinBase.vout.at(i).scriptPubKey.GetID().GetHex() != txExpectedCoinBase.vout.at(i).scriptPubKey.GetID().GetHex()) {
299305
return error("CheckRefundTransaction() : The scriptPubKey of the refund transaction isn't what it should be"

src/voteproposalmanager.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class CVoteProposalManager
3838

3939
//methods used in dynamic fee calculation
4040
bool GetFee(const CVoteProposal& proposal, int& nFee);
41-
bool GetDeterministicOrdering(const uint256& proofhash, std::vector<CTransaction>& vProposalTransactions,
41+
bool GetDeterministicOrdering(const uint256& proofhash, std::vector<CTransaction> vProposalTransactions,
4242
std::vector<CTransaction>& vOrderedProposalTransactions);
4343
bool GetNextLocation(int nBitCount, int nStartHeight, int nCheckSpan, VoteLocation& location);
4444
bool AddRefundToCoinBase(const CVoteProposal &proposal, const int &nRequiredFee, const int &nTxFee,

src/wallet.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,7 +2586,6 @@ bool CWallet::SendProposal(const CVoteProposal& proposal, uint256& txid)
25862586
uint256 hashBlock;
25872587
CTransaction txPrev;
25882588
if(!::GetTransaction(wtx.vin[0].prevout.hash, txPrev, hashBlock)) {
2589-
printf("failed to select coins");
25902589
return error("%s: Failed to select coins", __func__);
25912590
}
25922591

@@ -2601,15 +2600,13 @@ bool CWallet::SendProposal(const CVoteProposal& proposal, uint256& txid)
26012600
int nIn = 0;
26022601
for (const pair<const CWalletTx*,unsigned int>& coin : setCoins) {
26032602
if (!SignSignature(*this, *coin.first, wtx, nIn++)) {
2604-
printf("could not sign transaction");
26052603
return false;
26062604
}
26072605
}
26082606

26092607
//! Broadcast the transaction to the network
26102608
CReserveKey reserveKey = CReserveKey(this);
26112609
if (!CommitTransaction(wtx, reserveKey)) {
2612-
printf("failed to commit transaction");
26132610
return error("%s: Failed to commit transaction", __func__);
26142611
}
26152612

0 commit comments

Comments
 (0)