Skip to content

Commit 229ee81

Browse files
committed
finished up dynamic fee process. still testing (debug print statements in code)
1 parent 284ed95 commit 229ee81

6 files changed

Lines changed: 70 additions & 9 deletions

File tree

src/main.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1483,7 +1483,7 @@ bool CTransaction::ConnectInputs(CTxDB& txdb, MapPrevTx inputs,
14831483
}
14841484

14851485
// If the given transaction is coinbase then check for correct refund outputs
1486-
else if (VOTING_START >= pindexBlock->nHeight){
1486+
else if (pindexBlock->nHeight >= VOTING_START){
14871487
CBlock block;
14881488
if (!block.ReadFromDisk(pindexBlock))
14891489
return error("ConnectInputs() : ReadFromDisk for connect failed");
@@ -4433,6 +4433,18 @@ CBlock* CreateNewBlock(CWallet* pwallet, bool fProofOfStake)
44334433

44344434
// Size limits
44354435
unsigned int nTxSize = ::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION);
4436+
4437+
// If the transaction is a proposal then the size of the refund output must be accounted for
4438+
if (pindexPrev->nHeight >= VOTING_START && tx.IsProposal()) {
4439+
int nRefundSize;
4440+
if (!proposalManager.GetRefundOutputSize(tx, nRefundSize)) {
4441+
printf("Couldn't calculate refund output size for the given transaction.");
4442+
continue;
4443+
}
4444+
4445+
nTxSize += nRefundSize;
4446+
}
4447+
44364448
if (nBlockSize + nTxSize >= nBlockMaxSize)
44374449
continue;
44384450

src/script.cpp

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,12 +1358,16 @@ bool Solver(const CScript& scriptPubKey, txnouttype& typeRet, vector<vector<unsi
13581358
bool Sign1(const CKeyID& address, const CKeyStore& keystore, uint256 hash, int nHashType, CScript& scriptSigRet)
13591359
{
13601360
CKey key;
1361-
if (!keystore.GetKey(address, key))
1361+
if (!keystore.GetKey(address, key)) {
1362+
printf("could not find the right key ******************");
13621363
return false;
1364+
}
13631365

13641366
vector<unsigned char> vchSig;
1365-
if (!key.Sign(hash, vchSig))
1367+
if (!key.Sign(hash, vchSig)) {
1368+
printf("signing failed :( *****************");
13661369
return false;
1370+
}
13671371
vchSig.push_back((unsigned char)nHashType);
13681372
scriptSigRet << vchSig;
13691373

@@ -1403,12 +1407,17 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
14031407
switch (whichTypeRet)
14041408
{
14051409
case TX_NONSTANDARD:
1410+
printf("****************** tx is not standard");
14061411
return false;
14071412
case TX_PUBKEY:
14081413
keyID = CPubKey(vSolutions[0]).GetID();
1414+
printf("***************** tx is pubkey: %s", keyID.ToString());
1415+
printf("\n");
14091416
return Sign1(keyID, keystore, hash, nHashType, scriptSigRet);
14101417
case TX_PUBKEYHASH:
14111418
keyID = CKeyID(uint160(vSolutions[0]));
1419+
printf("***************** tx is pubkeyhash: %s", uint160(vSolutions[0]));
1420+
printf("\n");
14121421
if (!Sign1(keyID, keystore, hash, nHashType, scriptSigRet))
14131422
return false;
14141423
else
@@ -1419,13 +1428,16 @@ bool Solver(const CKeyStore& keystore, const CScript& scriptPubKey, uint256 hash
14191428
}
14201429
return true;
14211430
case TX_SCRIPTHASH:
1431+
printf("***************** tx is scripthash");
14221432
return keystore.GetCScript(uint160(vSolutions[0]), scriptSigRet);
14231433

14241434
case TX_MULTISIG:
1435+
printf("***************** tx is multisig");
14251436
scriptSigRet << OP_0; // workaround CHECKMULTISIG bug
14261437
return (SignN(vSolutions, keystore, hash, nHashType, scriptSigRet));
14271438
case TX_NULL_DATA:
1428-
return true;
1439+
printf("**************** tx is null data");
1440+
return true;
14291441
}
14301442
return false;
14311443
}
@@ -1645,8 +1657,10 @@ bool SignSignature(const CKeyStore &keystore, const CScript& fromPubKey, CTransa
16451657
uint256 hash = SignatureHash(fromPubKey, txTo, nIn, nHashType);
16461658

16471659
txnouttype whichType;
1648-
if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType))
1660+
if (!Solver(keystore, fromPubKey, hash, nHashType, txin.scriptSig, whichType)) {
1661+
printf("******************** solver failed :(");
16491662
return false;
1663+
}
16501664

16511665
if (whichType == TX_SCRIPTHASH)
16521666
{

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
@@ -170,6 +170,8 @@ namespace
170170
continue;
171171
vConflictingTime.emplace_back(data);
172172
}
173+
174+
return vConflictingTime;
173175
}
174176
}
175177

@@ -384,4 +386,28 @@ bool CVoteProposalManager::GetNextLocation(int nBitCount, int nStartHeight, int
384386
}
385387
}
386388
return false;
387-
}
389+
}
390+
391+
bool CVoteProposalManager::GetRefundOutputSize(const CTransaction& txProposal, int& nSize) const
392+
{
393+
394+
CTransaction txEmpty;
395+
unsigned int nBaseSize = ::GetSerializeSize(txEmpty, SER_NETWORK, PROTOCOL_VERSION);
396+
397+
if (!txProposal.IsProposal()) {
398+
return error("GetRefundOutputSize() : Given transaction must be a proposal.");
399+
}
400+
401+
CVoteProposal proposal;
402+
if (!ProposalFromTransaction(txProposal, proposal)) {
403+
return error("GetRefundOutputSize() : Failed to extract proposal from transaction.");
404+
}
405+
406+
// Every refund output should increase the size of the coinbase tx by the same amount.
407+
// 0, 0, and false are just filler values.
408+
proposalManager.AddRefundToCoinBase(proposal, 0, 0, false, txEmpty);
409+
410+
nSize = ::GetSerializeSize(txEmpty, SER_NETWORK, PROTOCOL_VERSION) - nBaseSize;
411+
412+
return true;
413+
}

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
};

src/wallet.cpp

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

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

26052609
//! Broadcast the transaction to the network
26062610
CReserveKey reserveKey = CReserveKey(this);
2607-
if (!CommitTransaction(wtx, reserveKey))
2611+
if (!CommitTransaction(wtx, reserveKey)) {
2612+
printf("failed to commit transaction");
26082613
return error("%s: Failed to commit transaction", __func__);
2614+
}
26092615

26102616
txid = wtx.GetHash();
26112617

0 commit comments

Comments
 (0)