Skip to content

Commit

Permalink
wallet: Avoid second mapWallet lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
promag authored and random-zebra committed Dec 13, 2021
1 parent 4b8b541 commit c706743
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3295,9 +3295,11 @@ UniValue gettransaction(const JSONRPCRequest& request)
filter = filter | ISMINE_WATCH_ONLY;

UniValue entry(UniValue::VOBJ);
if (!pwallet->mapWallet.count(hash))
auto it = pwallet->mapWallet.find(hash);
if (it == pwallet->mapWallet.end()) {
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid or non-wallet transaction id");
const CWalletTx& wtx = pwallet->mapWallet.at(hash);
}
const CWalletTx& wtx = it->second;

CAmount nCredit = wtx.GetCredit(filter);
CAmount nDebit = wtx.GetDebit(filter);
Expand Down
5 changes: 3 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,9 @@ void CWallet::AddToSpends(const COutPoint& outpoint, const uint256& wtxid)

void CWallet::AddToSpends(const uint256& wtxid)
{
assert(mapWallet.count(wtxid));
CWalletTx& thisTx = mapWallet.at(wtxid);
auto it = mapWallet.find(wtxid);
assert(it != mapWallet.end());
CWalletTx& thisTx = it->second;
if (thisTx.IsCoinBase()) // Coinbases don't spend anything!
return;

Expand Down

0 comments on commit c706743

Please sign in to comment.