mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Merge #11039: Avoid second mapWallet lookup
8f2f1e0 wallet: Avoid second mapWallet lookup (João Barbosa)
Pull request description:
All calls to `mapWallet.count()` have the intent to detect if a `txid` exists and most are followed by a second lookup to retrieve the `CWalletTx`.
This PR replaces all `mapWallet.count()` calls with `mapWallet.find()` to avoid the second lookup.
Tree-SHA512: 96b7de7f5520ebf789a1aec1949a4e9c74e13683869cee012f717e5be8e51097d068e2347a36e89097c9a89f1ed1a1529db71760dac9b572e36a3e9ac1155f29
This commit is contained in:
@@ -1874,10 +1874,11 @@ UniValue listsinceblock(const JSONRPCRequest& request)
|
||||
throw JSONRPCError(RPC_INTERNAL_ERROR, "Can't read block from disk");
|
||||
}
|
||||
for (const CTransactionRef& tx : block.vtx) {
|
||||
if (pwallet->mapWallet.count(tx->GetHash()) > 0) {
|
||||
auto it = pwallet->mapWallet.find(tx->GetHash());
|
||||
if (it != pwallet->mapWallet.end()) {
|
||||
// We want all transactions regardless of confirmation count to appear here,
|
||||
// even negative confirmation ones, hence the big negative.
|
||||
ListTransactions(pwallet, pwallet->mapWallet[tx->GetHash()], "*", -100000000, true, removed, filter);
|
||||
ListTransactions(pwallet, it->second, "*", -100000000, true, removed, filter);
|
||||
}
|
||||
}
|
||||
paltindex = paltindex->pprev;
|
||||
@@ -1957,10 +1958,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[hash];
|
||||
const CWalletTx& wtx = it->second;
|
||||
|
||||
CAmount nCredit = wtx.GetCredit(filter);
|
||||
CAmount nDebit = wtx.GetDebit(filter);
|
||||
|
||||
Reference in New Issue
Block a user