wallet: unify FindNonChangeParentOutput functions

The function is only used in ListCoins.
This commit is contained in:
furszy 2022-07-20 13:24:05 -03:00
parent b3f4e82737
commit a2ac6f9582
No known key found for this signature in database
GPG Key ID: 5DD23CCC686AA623
2 changed files with 15 additions and 20 deletions

View File

@ -362,28 +362,24 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
return AvailableCoins(wallet, coinControl).GetTotalAmount();
}
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output)
{
AssertLockHeld(wallet.cs_wallet);
const CTransaction* ptx = &tx;
int n = output;
while (OutputIsChange(wallet, ptx->vout[n]) && ptx->vin.size() > 0) {
const COutPoint& prevout = ptx->vin[0].prevout;
auto it = wallet.mapWallet.find(prevout.hash);
if (it == wallet.mapWallet.end() || it->second.tx->vout.size() <= prevout.n ||
!wallet.IsMine(it->second.tx->vout[prevout.n])) {
break;
}
ptx = it->second.tx.get();
n = prevout.n;
}
return ptx->vout[n];
}
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint)
{
AssertLockHeld(wallet.cs_wallet);
return FindNonChangeParentOutput(wallet, *wallet.GetWalletTx(outpoint.hash)->tx, outpoint.n);
const CWalletTx* wtx{Assert(wallet.GetWalletTx(outpoint.hash))};
const CTransaction* ptx = wtx->tx.get();
int n = outpoint.n;
while (OutputIsChange(wallet, ptx->vout[n]) && ptx->vin.size() > 0) {
const COutPoint& prevout = ptx->vin[0].prevout;
const CWalletTx* it = wallet.GetWalletTx(prevout.hash);
if (!it || it->tx->vout.size() <= prevout.n ||
!wallet.IsMine(it->tx->vout[prevout.n])) {
break;
}
ptx = it->tx.get();
n = prevout.n;
}
return ptx->vout[n];
}
std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)

View File

@ -99,7 +99,6 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
/**
* Find non-change parent output.
*/
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
/**