Browse Source

Merge pull request #4787

4b0deb3 Clean up CMerkleTx::SetMerkleBranch. (Daniel Kraft)
0.10
Wladimir J. van der Laan 10 years ago
parent
commit
3cdae61aa2
No known key found for this signature in database
GPG Key ID: 74810B012346C9A6
  1. 30
      src/wallet.cpp
  2. 2
      src/wallet.h

30
src/wallet.cpp

@ -646,7 +646,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlock* pbl @@ -646,7 +646,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);
}
}
@ -2229,32 +2229,19 @@ CWalletKey::CWalletKey(int64_t nExpires) @@ -2229,32 +2229,19 @@ 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();
hashBlock = block.GetHash();
// Locate the transaction
for (nIndex = 0; nIndex < (int)pblock->vtx.size(); nIndex++)
if (pblock->vtx[nIndex] == *(CTransaction*)this)
for (nIndex = 0; nIndex < (int)block.vtx.size(); nIndex++)
if (block.vtx[nIndex] == *(CTransaction*)this)
break;
if (nIndex == (int)pblock->vtx.size())
if (nIndex == (int)block.vtx.size())
{
vMerkleBranch.clear();
nIndex = -1;
@ -2263,14 +2250,13 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock) @@ -2263,14 +2250,13 @@ int CMerkleTx::SetMerkleBranch(const CBlock* pblock)
}
// Fill in merkle branch
vMerkleBranch = pblock->GetMerkleBranch(nIndex);
}
vMerkleBranch = block.GetMerkleBranch(nIndex);
// Is the tx in a block that's in the main chain
BlockMap::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;

2
src/wallet.h

@ -504,7 +504,7 @@ public: @@ -504,7 +504,7 @@ public:
READWRITE(nIndex);
}
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)

Loading…
Cancel
Save