aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorfurszy <matiasfurszyfer@protonmail.com>2022-07-20 13:24:05 -0300
committerfurszy <matiasfurszyfer@protonmail.com>2023-01-03 17:25:36 -0300
commita2ac6f9582c4c996fa36e4801fa0aac756235754 (patch)
treedcc456eea53dead19d97220334cd5a9b422b7067 /src/wallet
parentb3f4e827378e010cd2a5d1b876d01db52c054d26 (diff)
wallet: unify FindNonChangeParentOutput functions
The function is only used in ListCoins.
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/spend.cpp22
-rw-r--r--src/wallet/spend.h1
2 files changed, 9 insertions, 14 deletions
diff --git a/src/wallet/spend.cpp b/src/wallet/spend.cpp
index 28f939f0fd..0e573badc2 100644
--- a/src/wallet/spend.cpp
+++ b/src/wallet/spend.cpp
@@ -362,30 +362,26 @@ CAmount GetAvailableBalance(const CWallet& wallet, const CCoinControl* coinContr
return AvailableCoins(wallet, coinControl).GetTotalAmount();
}
-const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const CTransaction& tx, int output)
+const CTxOut& FindNonChangeParentOutput(const CWallet& wallet, const COutPoint& outpoint)
{
AssertLockHeld(wallet.cs_wallet);
- const CTransaction* ptx = &tx;
- int n = output;
+ 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;
- 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])) {
+ 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->second.tx.get();
+ ptx = it->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);
-}
-
std::map<CTxDestination, std::vector<COutput>> ListCoins(const CWallet& wallet)
{
AssertLockHeld(wallet.cs_wallet);
diff --git a/src/wallet/spend.h b/src/wallet/spend.h
index 281a6ca9e8..14a057b1ea 100644
--- a/src/wallet/spend.h
+++ b/src/wallet/spend.h
@@ -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);
/**