Skip to content

Commit d660344

Browse files
committed
Wallet::AddToWalletIfInvolvingMe use blockHash instead of CBlockIndex pointer. The block index is not needed and it will make unit tests simpler to code.
1 parent 2996db3 commit d660344

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ bool CWallet::LoadToWallet(const CWalletTx& wtxIn)
10111011
* pblock is optional, but should be provided if the transaction is known to be in a block.
10121012
* If fUpdate is true, existing transactions will be updated.
10131013
*/
1014-
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate)
1014+
bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const uint256& blockHash, int posInBlock, bool fUpdate)
10151015
{
10161016
{
10171017
AssertLockHeld(cs_wallet);
@@ -1021,8 +1021,8 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
10211021
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range = mapTxSpends.equal_range(txin.prevout);
10221022
while (range.first != range.second) {
10231023
if (range.first->second != tx.GetHash()) {
1024-
LogPrintf("Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n", tx.GetHash().ToString(), pIndex->GetBlockHash().ToString(), range.first->second.ToString(), range.first->first.hash.ToString(), range.first->first.n);
1025-
MarkConflicted(pIndex->GetBlockHash(), range.first->second);
1024+
LogPrintf("Transaction %s (in block %s) conflicts with wallet transaction %s (both spend %s:%i)\n", tx.GetHash().ToString(), blockHash.ToString(), range.first->second.ToString(), range.first->first.hash.ToString(), range.first->first.n);
1025+
MarkConflicted(blockHash, range.first->second);
10261026
}
10271027
range.first++;
10281028
}
@@ -1067,7 +1067,7 @@ bool CWallet::AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex
10671067

10681068
// Get merkle branch if transaction was found in a block
10691069
if (posInBlock != -1)
1070-
wtx.SetMerkleBranch(pIndex->GetBlockHash(), posInBlock);
1070+
wtx.SetMerkleBranch(blockHash, posInBlock);
10711071

10721072
return AddToWallet(wtx, false);
10731073
}
@@ -1195,7 +1195,7 @@ void CWallet::MarkConflicted(const uint256& hashBlock, const uint256& hashTx)
11951195
void CWallet::SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, int posInBlock)
11961196
{
11971197
LOCK(cs_wallet);
1198-
if (!AddToWalletIfInvolvingMe(tx, pindex, posInBlock, true))
1198+
if (!AddToWalletIfInvolvingMe(tx, (pindex) ? pindex->GetBlockHash() : uint256(), posInBlock, true))
11991199
return; // Not one of ours
12001200

12011201
MarkAffectedTransactionsDirty(tx);
@@ -1641,7 +1641,7 @@ int CWallet::ScanForWalletTransactions(CBlockIndex* pindexStart, bool fUpdate, b
16411641
int posInBlock;
16421642
for (posInBlock = 0; posInBlock < (int)block.vtx.size(); posInBlock++) {
16431643
const auto& tx = block.vtx[posInBlock];
1644-
if (AddToWalletIfInvolvingMe(*tx, pindex, posInBlock, fUpdate)) {
1644+
if (AddToWalletIfInvolvingMe(*tx, pindex->GetBlockHash(), posInBlock, fUpdate)) {
16451645
myTxHashes.push_back(tx->GetHash());
16461646
ret++;
16471647
}

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ class CWallet : public CCryptoKeyStore, public CValidationInterface
573573
bool AddToWallet(const CWalletTx& wtxIn, bool fFlushOnClose = true);
574574
bool LoadToWallet(const CWalletTx& wtxIn);
575575
void SyncTransaction(const CTransaction& tx, const CBlockIndex *pindex, int posInBlock);
576-
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const CBlockIndex* pIndex, int posInBlock, bool fUpdate);
576+
bool AddToWalletIfInvolvingMe(const CTransaction& tx, const uint256& blockHash, int posInBlock, bool fUpdate);
577577
void EraseFromWallet(const uint256& hash);
578578

579579
/**

0 commit comments

Comments
 (0)