From b22c88423160d026e93130e606d2e1afc4ca40d5 Mon Sep 17 00:00:00 2001 From: s_nakamoto Date: Wed, 6 Oct 2010 02:19:47 +0000 Subject: recursive function to determine if own unconfirmed transaction can be spent git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@161 1a98c847-1fd6-4fd8-948a-caf3550aa51b --- main.h | 41 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 5 deletions(-) (limited to 'main.h') diff --git a/main.h b/main.h index c5a0127c41..f6993691ed 100644 --- a/main.h +++ b/main.h @@ -195,7 +195,7 @@ public: string ToString() const { - return strprintf("COutPoint(%s, %d)", hash.ToString().substr(0,6).c_str(), n); + return strprintf("COutPoint(%s, %d)", hash.ToString().substr(0,10).c_str(), n); } void print() const @@ -599,7 +599,7 @@ public: { string str; str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%d, vout.size=%d, nLockTime=%d)\n", - GetHash().ToString().substr(0,6).c_str(), + GetHash().ToString().substr(0,10).c_str(), nVersion, vin.size(), vout.size(), @@ -787,6 +787,37 @@ public: return nCreditCached; } + bool IsConfirmed() const + { + map mapPrev; + vector vWorkQueue; + vWorkQueue.reserve(vtxPrev.size()+1); + vWorkQueue.push_back(this); + for (int i = 0; i < vWorkQueue.size(); i++) + { + const CMerkleTx* ptx = vWorkQueue[i]; + + if (!ptx->IsFinal()) + return false; + if (ptx->GetDepthInMainChain() >= 1) + return true; + if (ptx->GetDebit() <= 0) + return false; + + if (mapPrev.empty()) + foreach(const CMerkleTx& tx, vtxPrev) + mapPrev[tx.GetHash()] = &tx; + + foreach(const CTxIn& txin, ptx->vin) + { + if (!mapPrev.count(txin.prevout.hash)) + return false; + vWorkQueue.push_back(mapPrev[txin.prevout.hash]); + } + } + return true; + } + bool WriteToDisk() { return CWalletDB().WriteTx(GetHash(), *this); @@ -1065,7 +1096,7 @@ public: GetHash().ToString().substr(0,20).c_str(), nVersion, hashPrevBlock.ToString().substr(0,20).c_str(), - hashMerkleRoot.ToString().substr(0,6).c_str(), + hashMerkleRoot.ToString().substr(0,10).c_str(), nTime, nBits, nNonce, vtx.size()); for (int i = 0; i < vtx.size(); i++) @@ -1075,7 +1106,7 @@ public: } printf(" vMerkleTree: "); for (int i = 0; i < vMerkleTree.size(); i++) - printf("%s ", vMerkleTree[i].ToString().substr(0,6).c_str()); + printf("%s ", vMerkleTree[i].ToString().substr(0,10).c_str()); printf("\n"); } @@ -1233,7 +1264,7 @@ public: { return strprintf("CBlockIndex(nprev=%08x, pnext=%08x, nFile=%d, nBlockPos=%-6d nHeight=%d, merkle=%s, hashBlock=%s)", pprev, pnext, nFile, nBlockPos, nHeight, - hashMerkleRoot.ToString().substr(0,6).c_str(), + hashMerkleRoot.ToString().substr(0,10).c_str(), GetBlockHash().ToString().substr(0,20).c_str()); } -- cgit v1.2.3