Skip to content

Commit 764016e

Browse files
committed
wallet: Retrieve TXO directly in FetchSelectedInputs
Instead of searching mapWallet for the preselected inputs, search m_txos. wallet_fundrawtransaction.py spends external inputs and needs the change output to also belong to the test wallet for the oversized tx test.
1 parent c1801b7 commit 764016e

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/wallet/spend.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,12 +277,8 @@ util::Result<PreSelectedInputs> FetchSelectedInputs(const CWallet& wallet, const
277277
input_bytes = GetVirtualTransactionSize(input_bytes, 0, 0);
278278
}
279279
CTxOut txout;
280-
if (auto ptr_wtx = wallet.GetWalletTx(outpoint.hash)) {
281-
// Clearly invalid input, fail
282-
if (ptr_wtx->tx->vout.size() <= outpoint.n) {
283-
return util::Error{strprintf(_("Invalid pre-selected input %s"), outpoint.ToString())};
284-
}
285-
txout = ptr_wtx->tx->vout.at(outpoint.n);
280+
if (auto txo = wallet.GetTXO(outpoint)) {
281+
txout = txo->GetTxOut();
286282
if (input_bytes == -1) {
287283
input_bytes = CalculateMaximumSignedInputSize(txout, &wallet, &coin_control);
288284
}

src/wallet/wallet.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4459,4 +4459,14 @@ void CWallet::RefreshAllTXOs()
44594459
RefreshTXOsFromTx(wtx);
44604460
}
44614461
}
4462+
4463+
std::optional<WalletTXO> CWallet::GetTXO(const COutPoint& outpoint) const
4464+
{
4465+
AssertLockHeld(cs_wallet);
4466+
const auto& it = m_txos.find(outpoint);
4467+
if (it == m_txos.end()) {
4468+
return std::nullopt;
4469+
}
4470+
return it->second;
4471+
}
44624472
} // namespace wallet

src/wallet/wallet.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
524524
std::set<Txid> GetTxConflicts(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
525525

526526
const std::unordered_map<COutPoint, WalletTXO, SaltedOutpointHasher>& GetTXOs() const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return m_txos; };
527+
std::optional<WalletTXO> GetTXO(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
527528

528529
/** Cache outputs that belong to the wallet from a single transaction */
529530
void RefreshTXOsFromTx(const CWalletTx& wtx) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);

0 commit comments

Comments
 (0)