aboutsummaryrefslogtreecommitdiff
path: root/main.h
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-10-06 02:19:47 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-10-06 02:19:47 +0000
commitb22c88423160d026e93130e606d2e1afc4ca40d5 (patch)
tree2f1885ceb327719c810af1ddc5b8df0b3d5e5a72 /main.h
parentdc8adc3b48bb2201f2bd796a5ffa0733c30aa6e1 (diff)
downloadbitcoin-b22c88423160d026e93130e606d2e1afc4ca40d5.tar.xz
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
Diffstat (limited to 'main.h')
-rw-r--r--main.h41
1 files changed, 36 insertions, 5 deletions
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<uint256, const CMerkleTx*> mapPrev;
+ vector<const CMerkleTx*> 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());
}