diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -4091,11 +4091,16 @@ UniValue results(UniValue::VARR); std::vector vecOutputs; - LOCK2(cs_main, pwallet->cs_wallet); + { + LOCK2(cs_main, pwallet->cs_wallet); + pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, + nMinimumAmount, nMaximumAmount, + nMinimumSumAmount, nMaximumCount, nMinDepth, + nMaxDepth); + } + + LOCK(pwallet->cs_wallet); - pwallet->AvailableCoins(vecOutputs, !include_unsafe, nullptr, - nMinimumAmount, nMaximumAmount, nMinimumSumAmount, - nMaximumCount, nMinDepth, nMaxDepth); for (const COutput &out : vecOutputs) { CTxDestination address; const CScript &scriptPubKey = out.tx->tx->vout[out.i].scriptPubKey; @@ -4113,11 +4118,11 @@ if (fValidAddress) { entry.pushKV("address", EncodeDestination(address, config)); - if (pwallet->mapAddressBook.count(address)) { - entry.pushKV("label", pwallet->mapAddressBook[address].name); + auto i = pwallet->mapAddressBook.find(address); + if (i != pwallet->mapAddressBook.end()) { + entry.pushKV("label", i->second.name); if (IsDeprecatedRPCEnabled(gArgs, "accounts")) { - entry.pushKV("account", - pwallet->mapAddressBook[address].name); + entry.pushKV("account", i->second.name); } }