Skip to content

Commit a06fa94

Browse files
committed
wallet: IsSpent, 'COutPoint' arg instead of (hash, index)
1 parent 91902b7 commit a06fa94

File tree

7 files changed

+15
-18
lines changed

7 files changed

+15
-18
lines changed

src/wallet/interfaces.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet,
110110
result.txout = wtx.tx->vout[n];
111111
result.time = wtx.GetTxTime();
112112
result.depth_in_main_chain = depth;
113-
result.is_spent = wallet.IsSpent(wtx.GetHash(), n);
113+
result.is_spent = wallet.IsSpent(COutPoint(wtx.GetHash(), n));
114114
return result;
115115
}
116116

@@ -121,7 +121,7 @@ WalletTxOut MakeWalletTxOut(const CWallet& wallet,
121121
result.txout = output.txout;
122122
result.time = output.time;
123123
result.depth_in_main_chain = output.depth;
124-
result.is_spent = wallet.IsSpent(output.outpoint.hash, output.outpoint.n);
124+
result.is_spent = wallet.IsSpent(output.outpoint);
125125
return result;
126126
}
127127

src/wallet/receive.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,8 @@ CAmount CachedTxGetAvailableCredit(const CWallet& wallet, const CWalletTx& wtx,
204204
bool allow_used_addresses = (filter & ISMINE_USED) || !wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE);
205205
CAmount nCredit = 0;
206206
uint256 hashTx = wtx.GetHash();
207-
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++)
208-
{
209-
if (!wallet.IsSpent(hashTx, i) && (allow_used_addresses || !wallet.IsSpentKey(hashTx, i))) {
207+
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
208+
if (!wallet.IsSpent(COutPoint(hashTx, i)) && (allow_used_addresses || !wallet.IsSpentKey(hashTx, i))) {
210209
const CTxOut &txout = wtx.tx->vout[i];
211210
nCredit += OutputGetCredit(wallet, txout, filter);
212211
if (!MoneyRange(nCredit))
@@ -371,15 +370,15 @@ std::map<CTxDestination, CAmount> GetAddressBalances(const CWallet& wallet)
371370
if (nDepth < (CachedTxIsFromMe(wallet, wtx, ISMINE_ALL) ? 0 : 1))
372371
continue;
373372

374-
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++)
375-
{
373+
for (unsigned int i = 0; i < wtx.tx->vout.size(); i++) {
374+
const auto& output = wtx.tx->vout[i];
376375
CTxDestination addr;
377-
if (!wallet.IsMine(wtx.tx->vout[i]))
376+
if (!wallet.IsMine(output))
378377
continue;
379-
if(!ExtractDestination(wtx.tx->vout[i].scriptPubKey, addr))
378+
if(!ExtractDestination(output.scriptPubKey, addr))
380379
continue;
381380

382-
CAmount n = wallet.IsSpent(walletEntry.first, i) ? 0 : wtx.tx->vout[i].nValue;
381+
CAmount n = wallet.IsSpent(COutPoint(walletEntry.first, i)) ? 0 : output.nValue;
383382
balances[addr] += n;
384383
}
385384
}

src/wallet/rpc/coins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ RPCHelpMan lockunspent()
341341
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, vout index out of bounds");
342342
}
343343

344-
if (pwallet->IsSpent(outpt.hash, outpt.n)) {
344+
if (pwallet->IsSpent(outpt)) {
345345
throw JSONRPCError(RPC_INVALID_PARAMETER, "Invalid parameter, expected unspent output");
346346
}
347347

src/wallet/rpc/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1387,7 +1387,7 @@ RPCHelpMan sendall()
13871387
throw JSONRPCError(RPC_INVALID_PARAMETER, "Cannot combine send_max with specific inputs.");
13881388
} else if (options.exists("inputs")) {
13891389
for (const CTxIn& input : rawTx.vin) {
1390-
if (pwallet->IsSpent(input.prevout.hash, input.prevout.n)) {
1390+
if (pwallet->IsSpent(input.prevout)) {
13911391
throw JSONRPCError(RPC_INVALID_PARAMETER, strprintf("Input not available. UTXO (%s:%d) was already spent.", input.prevout.hash.ToString(), input.prevout.n));
13921392
}
13931393
const CWalletTx* tx{pwallet->GetWalletTx(input.prevout.hash)};

src/wallet/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
182182
if (wallet.IsLockedCoin(outpoint))
183183
continue;
184184

185-
if (wallet.IsSpent(wtxid, i))
185+
if (wallet.IsSpent(outpoint))
186186
continue;
187187

188188
isminetype mine = wallet.IsMine(output);

src/wallet/wallet.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,14 +629,12 @@ void CWallet::SyncMetaData(std::pair<TxSpends::iterator, TxSpends::iterator> ran
629629
* Outpoint is spent if any non-conflicted transaction
630630
* spends it:
631631
*/
632-
bool CWallet::IsSpent(const uint256& hash, unsigned int n) const
632+
bool CWallet::IsSpent(const COutPoint& outpoint) const
633633
{
634-
const COutPoint outpoint(hash, n);
635634
std::pair<TxSpends::const_iterator, TxSpends::const_iterator> range;
636635
range = mapTxSpends.equal_range(outpoint);
637636

638-
for (TxSpends::const_iterator it = range.first; it != range.second; ++it)
639-
{
637+
for (TxSpends::const_iterator it = range.first; it != range.second; ++it) {
640638
const uint256& wtxid = it->second;
641639
std::map<uint256, CWalletTx>::const_iterator mit = mapWallet.find(wtxid);
642640
if (mit != mapWallet.end()) {

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ class CWallet final : public WalletStorage, public interfaces::Chain::Notificati
441441
//! check whether we support the named feature
442442
bool CanSupportFeature(enum WalletFeature wf) const override EXCLUSIVE_LOCKS_REQUIRED(cs_wallet) { AssertLockHeld(cs_wallet); return IsFeatureSupported(nWalletVersion, wf); }
443443

444-
bool IsSpent(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
444+
bool IsSpent(const COutPoint& outpoint) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
445445

446446
// Whether this or any known UTXO with the same single key has been spent.
447447
bool IsSpentKey(const uint256& hash, unsigned int n) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);

0 commit comments

Comments
 (0)