|
18 | 18 | namespace wallet {
|
19 | 19 | static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
|
20 | 20 | {
|
21 |
| - std::set<CScript> output_scripts; |
22 |
| - |
| 21 | + std::set<CTxDestination> addresses; |
23 | 22 | if (by_label) {
|
24 | 23 | // Get the set of addresses assigned to label
|
25 |
| - std::string label = LabelFromValue(params[0]); |
26 |
| - for (const auto& address : wallet.GetLabelAddresses(label)) { |
27 |
| - auto output_script{GetScriptForDestination(address)}; |
28 |
| - if (wallet.IsMine(output_script)) { |
29 |
| - output_scripts.insert(output_script); |
30 |
| - } |
31 |
| - } |
| 24 | + addresses = wallet.GetLabelAddresses(LabelFromValue(params[0])); |
| 25 | + if (addresses.empty()) throw JSONRPCError(RPC_WALLET_ERROR, "Label not found in wallet"); |
32 | 26 | } else {
|
33 | 27 | // Get the address
|
34 | 28 | CTxDestination dest = DecodeDestination(params[0].get_str());
|
35 | 29 | if (!IsValidDestination(dest)) {
|
36 | 30 | throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Invalid Bitcoin address");
|
37 | 31 | }
|
38 |
| - CScript script_pub_key = GetScriptForDestination(dest); |
39 |
| - if (!wallet.IsMine(script_pub_key)) { |
40 |
| - throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); |
| 32 | + addresses.insert(dest); |
| 33 | + } |
| 34 | + |
| 35 | + // Filter by own scripts only |
| 36 | + std::set<CScript> output_scripts; |
| 37 | + for (const auto& address : addresses) { |
| 38 | + auto output_script{GetScriptForDestination(address)}; |
| 39 | + if (wallet.IsMine(output_script)) { |
| 40 | + output_scripts.insert(output_script); |
41 | 41 | }
|
42 |
| - output_scripts.insert(script_pub_key); |
| 42 | + } |
| 43 | + |
| 44 | + if (output_scripts.empty()) { |
| 45 | + throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet"); |
43 | 46 | }
|
44 | 47 |
|
45 | 48 | // Minimum confirmations
|
|
0 commit comments