From e2a186af10d81a0e27b2e7c34783711d65caeae7 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Tue, 9 Nov 2010 19:47:07 +0000 Subject: [PATCH] SelectCoins first pass tries not to use coins with less than 6 confirmations git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@177 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- main.cpp | 14 +++++++++++++- main.h | 22 +++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/main.cpp b/main.cpp index 904c2b8f76..190cd4b296 100644 --- a/main.cpp +++ b/main.cpp @@ -3400,7 +3400,7 @@ int64 GetBalance() } -bool SelectCoins(int64 nTargetValue, set& setCoinsRet) +bool SelectCoinsMinConf(int64 nTargetValue, int nConfMine, int nConfTheirs, set& setCoinsRet) { setCoinsRet.clear(); @@ -3422,6 +3422,11 @@ bool SelectCoins(int64 nTargetValue, set& 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; @@ -3506,6 +3511,13 @@ bool SelectCoins(int64 nTargetValue, set& setCoinsRet) return true; } +bool SelectCoins(int64 nTargetValue, set& setCoinsRet) +{ + return (SelectCoinsMinConf(nTargetValue, 1, 6, setCoinsRet) || + SelectCoinsMinConf(nTargetValue, 1, 1, setCoinsRet) || + SelectCoinsMinConf(nTargetValue, 0, 1, setCoinsRet)); +} + diff --git a/main.h b/main.h index 5176d90cea..d5734103c0 100644 --- a/main.h +++ b/main.h @@ -487,6 +487,11 @@ public: return false; } + bool IsFromMe() const + { + return (GetDebit() > 0); + } + int64 GetDebit() const { int64 nDebit = 0; @@ -789,8 +794,23 @@ public: 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 mapPrev; vector vWorkQueue; vWorkQueue.reserve(vtxPrev.size()+1); @@ -803,7 +823,7 @@ public: return false; if (ptx->GetDepthInMainChain() >= 1) return true; - if (ptx->GetDebit() <= 0) + if (!ptx->IsFromMe()) return false; if (mapPrev.empty())