Skip to content

Commit 2a88276

Browse files
committed
removed debug statements and added voting tests
1 parent 7131af9 commit 2a88276

8 files changed

Lines changed: 278 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/miner.cpp

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,57 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake)
405405
}
406406
}
407407

408+
// TODO: ADD BLOCK HEIGHT FOR VOTING HARD FORK
409+
// TODO: MIGHT NEED TO CHECK BLOCK SIZE CONSTRAINTS
410+
// TODO: PUT THIS IN ANOTHER METHOD TO IMPROVE MODULARIZATION AND CODE REUSE
411+
if(pindexPrev->nHeight >= VOTING_START) {
412+
std::vector<CTransaction> vProposalTransactions;
413+
for(CTransaction tx: pblock->vtx) {
414+
if(tx.IsProposal()) {
415+
vProposalTransactions.emplace_back(tx);
416+
}
417+
}
418+
419+
std::vector <CTransaction> vOrderedProposalTransactions;
420+
proposalManager.GetDeterministicOrdering(pindexPrev->hashProofOfStake, vProposalTransactions,
421+
vOrderedProposalTransactions);
422+
for (CTransaction txProposal: vOrderedProposalTransactions) {
423+
// output variables
424+
int nRequiredFee;
425+
CVoteProposal proposal;
426+
VoteLocation location;
427+
CTransaction txCoinBase = pblock->vtx[0];
428+
429+
// Skip this txProposal if a proposal object cannot be extracted from it
430+
if (!ProposalFromTransaction(txProposal, proposal)) {
431+
continue;
432+
}
433+
434+
// input variables
435+
int nTxFee = CVoteProposal::BASE_FEE; //TODO: DETERMINE THE BEST VALUE FROM TRIALS
436+
int nBitCount = proposal.GetBitCount();
437+
int nStartHeight = proposal.GetStartHeight();
438+
int nCheckSpan = proposal.GetCheckSpan();
439+
440+
// If a valid voting location cannot be found then create an unaccepted proposal refund
441+
if (!proposalManager.GetNextLocation(nBitCount, nStartHeight, nCheckSpan, location)) {
442+
proposalManager.AddRefundToCoinBase(proposal, nRequiredFee, nTxFee, false, txCoinBase);
443+
} else {
444+
// If a fee cannot be calculated then skip this proposal without creating a refund tx
445+
proposal.SetLocation(location);
446+
if (!proposalManager.GetFee(proposal, nRequiredFee)) continue;
447+
448+
// If the maximum fee provided by the proposal creator is less than the required fee
449+
// then create an unaccepted proposal refund
450+
if (nRequiredFee > proposal.GetMaxFee()) {
451+
proposalManager.AddRefundToCoinBase(proposal, nRequiredFee, nTxFee, false, txCoinBase);
452+
} else {
453+
proposalManager.AddRefundToCoinBase(proposal, nRequiredFee, nTxFee, true, txCoinBase);
454+
}
455+
}
456+
}
457+
}
458+
408459
nLastBlockTx = nBlockTx;
409460
nLastBlockSize = nBlockSize;
410461

src/script.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,13 +1327,11 @@ bool Sign1(const CKeyID& address, const CKeyStore& keystore, uint256 hash, int n
13271327
{
13281328
CKey key;
13291329
if (!keystore.GetKey(address, key)) {
1330-
printf("could not find the right key ******************");
13311330
return false;
13321331
}
13331332

13341333
vector<unsigned char> vchSig;
13351334
if (!key.Sign(hash, vchSig)) {
1336-
printf("signing failed :( *****************");
13371335
return false;
13381336
}
13391337
vchSig.push_back((unsigned char)nHashType);
@@ -1375,17 +1373,12 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
13751373
switch (whichTypeRet)
13761374
{
13771375
case TX_NONSTANDARD:
1378-
printf("****************** tx is not standard");
13791376
return false;
13801377
case TX_PUBKEY:
13811378
keyID = CPubKey(vSolutions[0]).GetID();
1382-
printf("***************** tx is pubkey: %s", keyID.ToString());
1383-
printf("\n");
13841379
return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
13851380
case TX_PUBKEYHASH:
13861381
keyID = CKeyID(uint160(vSolutions[0]));
1387-
printf("***************** tx is pubkeyhash: %s", uint160(vSolutions[0]));
1388-
printf("\n");
13891382
if (!Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
13901383
return false;
13911384
else
@@ -1396,15 +1389,12 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
13961389
}
13971390
return true;
13981391
case TX_SCRIPTHASH:
1399-
printf("***************** tx is scripthash");
14001392
return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet);
14011393

14021394
case TX_MULTISIG:
1403-
printf("***************** tx is multisig");
14041395
scriptSigRet << OP_0; // workaround CHECKMULTISIG bug
14051396
return (SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
14061397
case TX_NULL_DATA:
1407-
printf("**************** tx is null data");
14081398
return true;
14091399
}
14101400
return false;
@@ -1626,7 +1616,6 @@ bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CTransa
16261616

16271617
txnouttype whichType;
16281618
if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType)) {
1629-
printf("******************** solver failed :(");
16301619
return false;
16311620
}
16321621

0 commit comments

Comments
 (0)