Skip to content

Commit 4b83bf8

Browse files
committed
wallet: avoid extra IsSpentKey -> GetWalletTx lookups
1 parent 3d8a282 commit 4b83bf8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/wallet/receive.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ CAmount CachedTxGetAvailableCredit(const CWallet& wallet, const CWalletTx& wtx,
205205
CAmount nCredit = 0;
206206
uint256 hashTx = wtx.GetHash();
207207
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))) {
209-
const CTxOut &txout = wtx.tx->vout[i];
208+
const CTxOut& txout = wtx.tx->vout[i];
209+
if (!wallet.IsSpent(COutPoint(hashTx, i)) && (allow_used_addresses || !wallet.IsSpentKey(txout.scriptPubKey))) {
210210
nCredit += OutputGetCredit(wallet, txout, filter);
211211
if (!MoneyRange(nCredit))
212212
throw std::runtime_error(std::string(__func__) + " : value out of range");

src/wallet/rpc/coins.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ RPCHelpMan listunspent()
649649
CTxDestination address;
650650
const CScript& scriptPubKey = out.txout.scriptPubKey;
651651
bool fValidAddress = ExtractDestination(scriptPubKey, address);
652-
bool reused = avoid_reuse && pwallet->IsSpentKey(out.outpoint.hash, out.outpoint.n);
652+
bool reused = avoid_reuse && pwallet->IsSpentKey(scriptPubKey);
653653

654654
if (destinations.size() && (!fValidAddress || !destinations.count(address)))
655655
continue;

src/wallet/spend.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ CoinsResult AvailableCoins(const CWallet& wallet,
191191
continue;
192192
}
193193

194-
if (!allow_used_addresses && wallet.IsSpentKey(wtxid, i)) {
194+
if (!allow_used_addresses && wallet.IsSpentKey(output.scriptPubKey)) {
195195
continue;
196196
}
197197

0 commit comments

Comments
 (0)