Skip to content

Commit a2ac6f9

Browse files
committed
wallet: unify FindNonChangeParentOutput functions
The function is only used in ListCoins.
1 parent b3f4e82 commit a2ac6f9

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/wallet/spend.cpp

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -362,30 +362,26 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
362362
return AvailableCoins(wallet, coinControl).GetTotalAmount();
363363
}
364364

365-
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output)
365+
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint)
366366
{
367367
AssertLockHeld(wallet.cs_wallet);
368-
const CTransaction* ptx = &tx;
369-
int n = output;
368+
const CWalletTx* wtx{Assert(wallet.GetWalletTx(outpoint.hash))};
369+
370+
const CTransaction* ptx = wtx->tx.get();
371+
int n = outpoint.n;
370372
while (OutputIsChange(wallet, ptx->vout[n]) && ptx->vin.size() > 0) {
371373
const COutPoint& prevout = ptx->vin[0].prevout;
372-
auto it = wallet.mapWallet.find(prevout.hash);
373-
if (it == wallet.mapWallet.end() || it->second.tx->vout.size() <= prevout.n ||
374-
!wallet.IsMine(it->second.tx->vout[prevout.n])) {
374+
const CWalletTx* it = wallet.GetWalletTx(prevout.hash);
375+
if (!it || it->tx->vout.size() <= prevout.n ||
376+
!wallet.IsMine(it->tx->vout[prevout.n])) {
375377
break;
376378
}
377-
ptx = it->second.tx.get();
379+
ptx = it->tx.get();
378380
n = prevout.n;
379381
}
380382
return ptx->vout[n];
381383
}
382384

383-
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint)
384-
{
385-
AssertLockHeld(wallet.cs_wallet);
386-
return FindNonChangeParentOutput(wallet, *wallet.GetWalletTx(outpoint.hash)->tx, outpoint.n);
387-
}
388-
389385
std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
390386
{
391387
AssertLockHeld(wallet.cs_wallet);

src/wallet/spend.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,6 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
9999
/**
100100
* Find non-change parent output.
101101
*/
102-
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
103102
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
104103

105104
/**

0 commit comments

Comments
 (0)