aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kraft <d@domob.eu>2014-08-29 20:24:16 +0200
committerDaniel Kraft <d@domob.eu>2014-08-30 18:00:55 +0200
commit4b0deb3b2df5882061ae6c44947eda831420cd5e (patch)
tree0f92881b989b537c4bf79edbd35b472ea7b3be7f
parent9f3d47677973cb894fdbb437b9b322e2062a1bf1 (diff)
Clean up CMerkleTx::SetMerkleBranch.
The case SetMerkleBranch(NULL) was never actually used, and thus the involved code (loading the block from disk) can be removed and the implementation simplified.
-rw-r--r--src/wallet.cpp50
-rw-r--r--src/wallet.h2
2 files changed, 19 insertions, 33 deletions
diff --git a/src/wallet.cpp b/src/wallet.cpp
index 18a5b3971c..f7efeaec4a 100644
--- a/src/wallet.cpp
+++ b/src/wallet.cpp
@@ -644,7 +644,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl
CWalletTx wtx(this,tx);
// Get merkle branch if transaction was found in a block
if (pblock)
- wtx.SetMerkleBranch(pblock);
+ wtx.SetMerkleBranch(*pblock);
return AddToWallet(wtx);
}
}
@@ -2195,48 +2195,34 @@ CWalletKey::CWalletKey(int64_t nExpires)
nTimeExpires = nExpires;
}
-int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
+int CMerkleTx::SetMerkleBranch(const CBlock& block)
{
AssertLockHeld(cs_main);
CBlock blockTmp;
- if (pblock == NULL) {
- CCoins coins;
- if (pcoinsTip->GetCoins(GetHash(), coins)) {
- CBlockIndex *pindex = chainActive[coins.nHeight];
- if (pindex) {
- if (!ReadBlockFromDisk(blockTmp, pindex))
- return 0;
- pblock = &blockTmp;
- }
- }
- }
-
- if (pblock) {
- // Update the tx's hashBlock
- hashBlock = pblock->GetHash();
-
- // Locate the transaction
- for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++)
- if (pblock->vtx[nIndex] == *(CTransaction*)this)
- break;
- if (nIndex == (int)pblock->vtx.size())
- {
- vMerkleBranch.clear();
- nIndex = -1;
- LogPrintf("ERROR: SetMerkleBranch() : couldn't find tx in block\n");
- return 0;
- }
+ // Update the tx's hashBlock
+ hashBlock = block.GetHash();
- // Fill in merkle branch
- vMerkleBranch = pblock->GetMerkleBranch(nIndex);
+ // Locate the transaction
+ for (nIndex = 0; nIndex < (int)block.vtx.size(); nIndex++)
+ if (block.vtx[nIndex] == *(CTransaction*)this)
+ break;
+ if (nIndex == (int)block.vtx.size())
+ {
+ vMerkleBranch.clear();
+ nIndex = -1;
+ LogPrintf("ERROR: SetMerkleBranch() : couldn't find tx in block\n");
+ return 0;
}
+ // Fill in merkle branch
+ vMerkleBranch = block.GetMerkleBranch(nIndex);
+
// Is the tx in a block that's in the main chain
map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
if (mi == mapBlockIndex.end())
return 0;
- CBlockIndex* pindex = (*mi).second;
+ const CBlockIndex* pindex = (*mi).second;
if (!pindex || !chainActive.Contains(pindex))
return 0;
diff --git a/src/wallet.h b/src/wallet.h
index 544b4f5bfb..3becc396c1 100644
--- a/src/wallet.h
+++ b/src/wallet.h
@@ -500,7 +500,7 @@ public:
)
- int SetMerkleBranch(const CBlock* pblock=NULL);
+ int SetMerkleBranch(const CBlock& block);
// Return depth of transaction in blockchain:
// -1 : not in blockchain, and not in memory pool (conflicted transaction)