Skip to content

Commit 7131af9

Browse files
committed
finished up dynamic fee process. still testing (debug print statements in code)
1 parent a64e32d commit 7131af9

6 files changed

Lines changed: 58 additions & 9 deletions

File tree

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1494,7 +1494,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
14941494
}
14951495

14961496
// If the given transaction is coinbase then check for correct refund outputs
1497-
else if (VOTING_START >= pindexBlock->nHeight){
1497+
else if (pindexBlock->nHeight >= VOTING_START){
14981498
CBlock block;
14991499
if (!block.ReadFromDisk(pindexBlock))
15001500
return error("ConnectInputs() : ReadFromDisk for connect failed");

src/script.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,12 +1326,16 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
13261326
bool Sign1(const CKeyID& address, const CKeyStore& keystore, uint256 hash, int nHashType, CScript& scriptSigRet)
13271327
{
13281328
CKey key;
1329-
if (!keystore.GetKey(address, key))
1329+
if (!keystore.GetKey(address, key)) {
1330+
printf("could not find the right key ******************");
13301331
return false;
1332+
}
13311333

13321334
vector<unsigned char> vchSig;
1333-
if (!key.Sign(hash, vchSig))
1335+
if (!key.Sign(hash, vchSig)) {
1336+
printf("signing failed :( *****************");
13341337
return false;
1338+
}
13351339
vchSig.push_back((unsigned char)nHashType);
13361340
scriptSigRet << vchSig;
13371341

@@ -1371,12 +1375,17 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
13711375
switch (whichTypeRet)
13721376
{
13731377
case TX_NONSTANDARD:
1378+
printf("****************** tx is not standard");
13741379
return false;
13751380
case TX_PUBKEY:
13761381
keyID = CPubKey(vSolutions[0]).GetID();
1382+
printf("***************** tx is pubkey: %s", keyID.ToString());
1383+
printf("\n");
13771384
return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
13781385
case TX_PUBKEYHASH:
13791386
keyID = CKeyID(uint160(vSolutions[0]));
1387+
printf("***************** tx is pubkeyhash: %s", uint160(vSolutions[0]));
1388+
printf("\n");
13801389
if (!Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
13811390
return false;
13821391
else
@@ -1387,13 +1396,16 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
13871396
}
13881397
return true;
13891398
case TX_SCRIPTHASH:
1399+
printf("***************** tx is scripthash");
13901400
return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet);
13911401

13921402
case TX_MULTISIG:
1403+
printf("***************** tx is multisig");
13931404
scriptSigRet << OP_0; // workaround CHECKMULTISIG bug
13941405
return (SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
13951406
case TX_NULL_DATA:
1396-
return true;
1407+
printf("**************** tx is null data");
1408+
return true;
13971409
}
13981410
return false;
13991411
}
@@ -1613,8 +1625,10 @@ bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CTransa
16131625
uint256 hash = SignatureHash(fromPubKey, txTo, nIn, nHashType);
16141626

16151627
txnouttype whichType;
1616-
if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType))
1628+
if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType)) {
1629+
printf("******************** solver failed :(");
16171630
return false;
1631+
}
16181632

16191633
if (whichType == TX_SCRIPTHASH)
16201634
{

src/voteproposal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class CVoteProposal
7878
this->strDescription = strDescription;
7979
this->nMaxFee = nMaxFee;
8080
this->strRefundAddress = strRefundAddress;
81+
//VoteLocation location;
82+
this->bitLocation = VoteLocation();
8183

8284
//VoteLocation will be set when the proposal is accepted by the network and the dynamic fee is determined
8385
}

src/voteproposalmanager.cpp

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ namespace
206206
continue;
207207
vConflictingTime.emplace_back(data);
208208
}
209+
210+
return vConflictingTime;
209211
}
210212
}
211213

@@ -420,4 +422,28 @@ bool CVoteProposalManager::GetNextLocation(int nBitCount, int nStartHeight, int
420422
}
421423
}
422424
return false;
423-
}
425+
}
426+
427+
bool CVoteProposalManager::GetRefundOutputSize(const CTransaction& txProposal, int& nSize) const
428+
{
429+
430+
CTransaction txEmpty;
431+
unsigned int nBaseSize = ::GetSerializeSize(txEmpty, SER_NETWORK, PROTOCOL_VERSION);
432+
433+
if (!txProposal.IsProposal()) {
434+
return error("GetRefundOutputSize() : Given transaction must be a proposal.");
435+
}
436+
437+
CVoteProposal proposal;
438+
if (!ProposalFromTransaction(txProposal, proposal)) {
439+
return error("GetRefundOutputSize() : Failed to extract proposal from transaction.");
440+
}
441+
442+
// Every refund output should increase the size of the coinbase tx by the same amount.
443+
// 0, 0, and false are just filler values.
444+
proposalManager.AddRefundToCoinBase(proposal, 0, 0, false, txEmpty);
445+
446+
nSize = ::GetSerializeSize(txEmpty, SER_NETWORK, PROTOCOL_VERSION) - nBaseSize;
447+
448+
return true;
449+
}

src/voteproposalmanager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class CVoteProposalManager
4646
bool CheckRefundTransaction(const std::vector<CTransaction> &vOrderedTxProposals, const CTransaction &txCoinBase);
4747
bool GetAcceptedTxProposals(const CTransaction& txCoinBase, const std::vector<CTransaction>& vOrderedTxProposals,
4848
std::vector<CTransaction>& vAcceptedTxProposals);
49+
bool GetRefundOutputSize(const CTransaction& txProposal, int& nSize) const;
4950

5051
std::map<uint256, CProposalMetaData> GetAllProposals() const { return mapProposalData; };
5152
bool CheckProposal (const CVoteProposal& proposal);

src/wallet.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2586,8 +2586,10 @@ bool CWallet::SendProposal(const CVoteProposal& proposal, uint256& txid)
25862586
//!Lookup the address of one of the inputs and return the change to that address
25872587
uint256 hashBlock;
25882588
CTransaction txPrev;
2589-
if(!::GetTransaction(wtx.vin[0].prevout.hash, txPrev, hashBlock))
2589+
if(!::GetTransaction(wtx.vin[0].prevout.hash, txPrev, hashBlock)) {
2590+
printf("failed to select coins");
25902591
return error("%s: Failed to select coins", __func__);
2592+
}
25912593

25922594
CScript scriptReturn = txPrev.vout[wtx.vin[0].prevout.n].scriptPubKey;
25932595
CTxOut out(nChange, scriptReturn);
@@ -2599,14 +2601,18 @@ bool CWallet::SendProposal(const CVoteProposal& proposal, uint256& txid)
25992601
//! Sign the transaction
26002602
int nIn = 0;
26012603
for (const pair<const CWalletTx*,unsigned int>& coin : setCoins) {
2602-
if (!SignSignature(*this, *coin.first, wtx, nIn++))
2604+
if (!SignSignature(*this, *coin.first, wtx, nIn++)) {
2605+
printf("could not sign transaction");
26032606
return false;
2607+
}
26042608
}
26052609

26062610
//! Broadcast the transaction to the network
26072611
CReserveKey reserveKey = CReserveKey(this);
2608-
if (!CommitTransaction(wtx, reserveKey))
2612+
if (!CommitTransaction(wtx, reserveKey)) {
2613+
printf("failed to commit transaction");
26092614
return error("%s: Failed to commit transaction", __func__);
2615+
}
26102616

26112617
txid = wtx.GetHash();
26122618

0 commit comments

Comments
 (0)