Skip to content

Commit

Permalink
SelectCoins first pass tries not to use coins with less than 6 confir…
Browse files Browse the repository at this point in the history
…mations

git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@177 1a98c847-1fd6-4fd8-948a-caf3550aa51b
  • Loading branch information
non-github-bitcoin committed Nov 9, 2010
1 parent 461764c commit e2a186a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
14 changes: 13 additions & 1 deletion main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3400,7 +3400,7 @@ int64 GetBalance()
}


bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet)
bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set<CWalletTx*>& setCoinsRet)
{
setCoinsRet.clear();

Expand All @@ -3422,6 +3422,11 @@ bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet)
{
if (!pcoin->IsFinal() || pcoin->fSpent || !pcoin->IsConfirmed())
continue;

int nDepth = pcoin->GetDepthInMainChain();
if (nDepth < (pcoin->IsFromMe() ? nConfMine : nConfTheirs))
continue;

int64 n = pcoin->GetCredit();
if (n <= 0)
continue;
Expand Down Expand Up @@ -3506,6 +3511,13 @@ bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet)
return true;
}

bool SelectCoins(int64 nTargetValue, set<CWalletTx*>& setCoinsRet)
{
return (SelectCoinsMinConf(nTargetValue, 1, 6, setCoinsRet) ||
SelectCoinsMinConf(nTargetValue, 1, 1, setCoinsRet) ||
SelectCoinsMinConf(nTargetValue, 0, 1, setCoinsRet));
}




Expand Down
22 changes: 21 additions & 1 deletion main.h
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,11 @@ class CTransaction
return false;
}

bool IsFromMe() const
{
return (GetDebit() > 0);
}

int64 GetDebit() const
{
int64 nDebit = 0;
Expand Down Expand Up @@ -789,8 +794,23 @@ class CWalletTx : public CMerkleTx
return nCreditCached;
}

bool IsFromMe() const
{
return (GetDebit() > 0);
}

bool IsConfirmed() const
{
// Quick answer in most cases
if (!IsFinal())
return false;
if (GetDepthInMainChain() >= 1)
return true;
if (!IsFromMe()) // using wtx's cached debit
return false;

// If no confirmations but it's from us, we can still
// consider it confirmed if all dependencies are confirmed
map<uint256, const CMerkleTx*> mapPrev;
vector<const CMerkleTx*> vWorkQueue;
vWorkQueue.reserve(vtxPrev.size()+1);
Expand All @@ -803,7 +823,7 @@ class CWalletTx : public CMerkleTx
return false;
if (ptx->GetDepthInMainChain() >= 1)
return true;
if (ptx->GetDebit() <= 0)
if (!ptx->IsFromMe())
return false;

if (mapPrev.empty())
Expand Down

0 comments on commit e2a186a

Please sign in to comment.