const CWalletTx *pcoin = output.tx;
int i = output.i;
+ // Ignore immature coins
+ if (pcoin->GetBlocksToMaturity() > 0)
+ continue;
+
// Stop if we've chosen enough inputs
if (nValueRet >= nTargetValue)
break;
set<pair<const CWalletTx*,unsigned int> > setCoins;
int64 nValueIn = 0;
+ // Simple coins selection - no randomization
if (!SelectCoinsSimple(nBalance - nReserveBalance, GetTime(), nCoinbaseMaturity * 10, setCoins, nValueIn))
return false;
wtxNew.vout.push_back(CTxOut(0, scriptOutput));
double dWeight = 0;
-
BOOST_FOREACH(PAIRTYPE(const CWalletTx*, unsigned int) pcoin, setCoins)
{
int64 nCredit = pcoin.first->vout[pcoin.second].nValue;
if (nCredit >= nMaxValue)
continue;
- // Ignore immature coins
- if (pcoin.first->GetBlocksToMaturity() > 0)
- continue;
-
// Add current coin to inputs list and add its credit to transaction output
wtxNew.vin.push_back(CTxIn(pcoin.first->GetHash(), pcoin.second));
wtxNew.vout[0].nValue += nCredit;
vwtxPrev.push_back(pcoin.first);
+/*
+ // Replaced with estimation for performance purposes
+
for (unsigned int i = 0; i < wtxNew.vin.size(); i++) {
const CWalletTx *txin = vwtxPrev[i];
if (!SignSignature(*this, *txin, wtxNew, i))
return false;
}
+*/
- int64 nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION);
+ // Assuming that average scriptsig size is 110 bytes
+ int64 nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION) + wtxNew.vin.size() * 110;
dWeight += (double)nCredit * pcoin.first->GetDepthInMainChain();
double dFinalPriority = dWeight /= nBytes;
bool fAllowFree = CTransaction::AllowFree(dFinalPriority);
- // Get actual transaction fee according to its size and priority
+ // Get actual transaction fee according to its estimated size and priority
int64 nMinFee = wtxNew.GetMinFee(1, fAllowFree, GMF_SEND, nBytes);
// Prepare transaction for commit if sum is enough ot its size is too big
- if (nBytes >= MAX_BLOCK_SIZE_GEN/6 || (wtxNew.vout[0].nValue >= nOutputValue && wtxNew.vout.size() > 1))
+ if (nBytes >= MAX_BLOCK_SIZE_GEN/6 || wtxNew.vout[0].nValue >= nOutputValue)
{
wtxNew.vout[0].nValue -= nMinFee; // Set actual fee
for (unsigned int i = 0; i < wtxNew.vin.size(); i++) {
const CWalletTx *txin = vwtxPrev[i];
- // Sign all scripts again
+ // Sign all scripts
if (!SignSignature(*this, *txin, wtxNew, i))
return false;
}
// Create transactions if there are some unhandled coins left
if (wtxNew.vout[0].nValue > 0) {
- int64 nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION);
+ int64 nBytes = ::GetSerializeSize(*(CTransaction*)&wtxNew, SER_NETWORK, PROTOCOL_VERSION) + wtxNew.vin.size() * 110;
double dFinalPriority = dWeight /= nBytes;
bool fAllowFree = CTransaction::AllowFree(dFinalPriority);