Skip to content

Commit a7b65af

Browse files
committed
rpc: avoid scriptPubKey<->CTxDestination conversions in GetReceived tally
1 parent 926fc2a commit a7b65af

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/wallet/rpc/coins.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
1919
{
20-
std::set<CTxDestination> address_set;
20+
std::set<CScript> output_scripts;
2121

2222
if (by_label) {
2323
// Get the set of addresses assigned to label
2424
std::string label = LabelFromValue(params[0]);
25-
address_set = wallet.GetLabelAddresses(label);
25+
for (const auto& address : wallet.GetLabelAddresses(label)) {
26+
output_scripts.insert(GetScriptForDestination(address));
27+
}
2628
} else {
2729
// Get the address
2830
CTxDestination dest = DecodeDestination(params[0].get_str());
@@ -33,7 +35,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
3335
if (!wallet.IsMine(script_pub_key)) {
3436
throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet");
3537
}
36-
address_set.insert(dest);
38+
output_scripts.insert(script_pub_key);
3739
}
3840

3941
// Minimum confirmations
@@ -65,8 +67,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
6567
}
6668

6769
for (const CTxOut& txout : wtx.tx->vout) {
68-
CTxDestination address;
69-
if (ExtractDestination(txout.scriptPubKey, address) && wallet.IsMine(address) && address_set.count(address)) {
70+
if (wallet.IsMine(txout.scriptPubKey) && output_scripts.count(txout.scriptPubKey) > 0) {
7071
amount += txout.nValue;
7172
}
7273
}

0 commit comments

Comments
 (0)