Skip to content

Commit dee4224

Browse files
committed
Wallet:GetLockedCoins() loop only over the locked coins, not over the entire wallet txes map.
Plus return early if no coins were locked.
1 parent 0a61f7f commit dee4224

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,10 +2129,20 @@ CAmount CWallet::GetLockedCoins() const
21292129
{
21302130
if (fLiteMode) return 0;
21312131

2132-
return loopTxsBalance([](const uint256& id, const CWalletTx& pcoin, CAmount& nTotal) {
2133-
if (pcoin.IsTrusted() && pcoin.GetDepthInMainChain() > 0)
2134-
nTotal += pcoin.GetLockedCredit();
2135-
});
2132+
LOCK(cs_wallet);
2133+
if (setLockedCoins.empty()) return 0;
2134+
2135+
CAmount ret = 0;
2136+
for (const auto& coin : setLockedCoins) {
2137+
auto it = mapWallet.find(coin.hash);
2138+
if (it != mapWallet.end()) {
2139+
const CWalletTx& pcoin = it->second;
2140+
if (pcoin.IsTrusted() && pcoin.GetDepthInMainChain() > 0) {
2141+
ret += it->second.tx->vout.at(coin.n).nValue;
2142+
}
2143+
}
2144+
}
2145+
return ret;
21362146
}
21372147

21382148
CAmount CWallet::GetUnconfirmedBalance(isminetype filter) const

0 commit comments

Comments
 (0)