mirror of
https://github.com/bitcoin/bitcoin.git
synced 2024-11-20 10:38:42 +01:00
wallet: unify FindNonChangeParentOutput functions
The function is only used in ListCoins.
This commit is contained in:
parent
b3f4e82737
commit
a2ac6f9582
@ -362,28 +362,24 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
|
|||||||
return AvailableCoins(wallet, coinControl).GetTotalAmount();
|
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)
|
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint)
|
||||||
{
|
{
|
||||||
AssertLockHeld(wallet.cs_wallet);
|
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)
|
std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
|
||||||
|
@ -99,7 +99,6 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
|
|||||||
/**
|
/**
|
||||||
* Find non-change parent output.
|
* 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);
|
const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user