mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-03 13:44:42 -05:00
rpc: avoid scriptPubKey<->CTxDestination conversions in GetReceived
tally
This commit is contained in:
parent
926fc2a0d4
commit
a7b65af2a4
1 changed files with 6 additions and 5 deletions
|
@ -17,12 +17,14 @@
|
|||
|
||||
static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool by_label) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet)
|
||||
{
|
||||
std::set<CTxDestination> address_set;
|
||||
std::set<CScript> output_scripts;
|
||||
|
||||
if (by_label) {
|
||||
// Get the set of addresses assigned to label
|
||||
std::string label = LabelFromValue(params[0]);
|
||||
address_set = wallet.GetLabelAddresses(label);
|
||||
for (const auto& address : wallet.GetLabelAddresses(label)) {
|
||||
output_scripts.insert(GetScriptForDestination(address));
|
||||
}
|
||||
} else {
|
||||
// Get the address
|
||||
CTxDestination dest = DecodeDestination(params[0].get_str());
|
||||
|
@ -33,7 +35,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
|
|||
if (!wallet.IsMine(script_pub_key)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Address not found in wallet");
|
||||
}
|
||||
address_set.insert(dest);
|
||||
output_scripts.insert(script_pub_key);
|
||||
}
|
||||
|
||||
// Minimum confirmations
|
||||
|
@ -65,8 +67,7 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
|
|||
}
|
||||
|
||||
for (const CTxOut& txout : wtx.tx->vout) {
|
||||
CTxDestination address;
|
||||
if (ExtractDestination(txout.scriptPubKey, address) && wallet.IsMine(address) && address_set.count(address)) {
|
||||
if (wallet.IsMine(txout.scriptPubKey) && output_scripts.count(txout.scriptPubKey) > 0) {
|
||||
amount += txout.nValue;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue