mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
refactor: 'ListReceived' use optional for filtered address
Plus remove open bracket jump line
This commit is contained in:
parent
b459fc122f
commit
324f00a642
1 changed files with 16 additions and 29 deletions
|
@ -85,14 +85,12 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
|
||||||
filter |= ISMINE_WATCH_ONLY;
|
filter |= ISMINE_WATCH_ONLY;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool has_filtered_address = false;
|
std::optional<CTxDestination> filtered_address{std::nullopt};
|
||||||
CTxDestination filtered_address = CNoDestination();
|
|
||||||
if (!by_label && !params[3].isNull() && !params[3].get_str().empty()) {
|
if (!by_label && !params[3].isNull() && !params[3].get_str().empty()) {
|
||||||
if (!IsValidDestinationString(params[3].get_str())) {
|
if (!IsValidDestinationString(params[3].get_str())) {
|
||||||
throw JSONRPCError(RPC_WALLET_ERROR, "address_filter parameter was invalid");
|
throw JSONRPCError(RPC_WALLET_ERROR, "address_filter parameter was invalid");
|
||||||
}
|
}
|
||||||
filtered_address = DecodeDestination(params[3].get_str());
|
filtered_address = DecodeDestination(params[3].get_str());
|
||||||
has_filtered_address = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tally
|
// Tally
|
||||||
|
@ -106,23 +104,21 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
|
||||||
|
|
||||||
// Coinbase with less than 1 confirmation is no longer in the main chain
|
// Coinbase with less than 1 confirmation is no longer in the main chain
|
||||||
if ((wtx.IsCoinBase() && (nDepth < 1))
|
if ((wtx.IsCoinBase() && (nDepth < 1))
|
||||||
|| (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
|
|| (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase)) {
|
||||||
{
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const CTxOut& txout : wtx.tx->vout)
|
for (const CTxOut& txout : wtx.tx->vout) {
|
||||||
{
|
|
||||||
CTxDestination address;
|
CTxDestination address;
|
||||||
if (!ExtractDestination(txout.scriptPubKey, address))
|
if (!ExtractDestination(txout.scriptPubKey, address))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (has_filtered_address && !(filtered_address == address)) {
|
if (filtered_address && !(filtered_address == address)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
isminefilter mine = wallet.IsMine(address);
|
isminefilter mine = wallet.IsMine(address);
|
||||||
if(!(mine & filter))
|
if (!(mine & filter))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
tallyitem& item = mapTally[address];
|
tallyitem& item = mapTally[address];
|
||||||
|
@ -148,34 +144,27 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
|
||||||
CAmount nAmount = 0;
|
CAmount nAmount = 0;
|
||||||
int nConf = std::numeric_limits<int>::max();
|
int nConf = std::numeric_limits<int>::max();
|
||||||
bool fIsWatchonly = false;
|
bool fIsWatchonly = false;
|
||||||
if (it != mapTally.end())
|
if (it != mapTally.end()) {
|
||||||
{
|
|
||||||
nAmount = (*it).second.nAmount;
|
nAmount = (*it).second.nAmount;
|
||||||
nConf = (*it).second.nConf;
|
nConf = (*it).second.nConf;
|
||||||
fIsWatchonly = (*it).second.fIsWatchonly;
|
fIsWatchonly = (*it).second.fIsWatchonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (by_label)
|
if (by_label) {
|
||||||
{
|
|
||||||
tallyitem& _item = label_tally[label];
|
tallyitem& _item = label_tally[label];
|
||||||
_item.nAmount += nAmount;
|
_item.nAmount += nAmount;
|
||||||
_item.nConf = std::min(_item.nConf, nConf);
|
_item.nConf = std::min(_item.nConf, nConf);
|
||||||
_item.fIsWatchonly = fIsWatchonly;
|
_item.fIsWatchonly = fIsWatchonly;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
if(fIsWatchonly)
|
if (fIsWatchonly) obj.pushKV("involvesWatchonly", true);
|
||||||
obj.pushKV("involvesWatchonly", true);
|
|
||||||
obj.pushKV("address", EncodeDestination(address));
|
obj.pushKV("address", EncodeDestination(address));
|
||||||
obj.pushKV("amount", ValueFromAmount(nAmount));
|
obj.pushKV("amount", ValueFromAmount(nAmount));
|
||||||
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
|
obj.pushKV("confirmations", (nConf == std::numeric_limits<int>::max() ? 0 : nConf));
|
||||||
obj.pushKV("label", label);
|
obj.pushKV("label", label);
|
||||||
UniValue transactions(UniValue::VARR);
|
UniValue transactions(UniValue::VARR);
|
||||||
if (it != mapTally.end())
|
if (it != mapTally.end()) {
|
||||||
{
|
for (const uint256& _item : (*it).second.txids) {
|
||||||
for (const uint256& _item : (*it).second.txids)
|
|
||||||
{
|
|
||||||
transactions.push_back(_item.GetHex());
|
transactions.push_back(_item.GetHex());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -184,18 +173,16 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (has_filtered_address) {
|
if (filtered_address) {
|
||||||
const auto& entry = wallet.FindAddressBookEntry(filtered_address, /*allow_change=*/false);
|
const auto& entry = wallet.FindAddressBookEntry(*filtered_address, /*allow_change=*/false);
|
||||||
if (entry) func(filtered_address, entry->GetLabel(), entry->purpose, /*is_change=*/false);
|
if (entry) func(*filtered_address, entry->GetLabel(), entry->purpose, /*is_change=*/false);
|
||||||
} else {
|
} else {
|
||||||
// No filtered addr, walk-through the addressbook entry
|
// No filtered addr, walk-through the addressbook entry
|
||||||
wallet.ForEachAddrBookEntry(func);
|
wallet.ForEachAddrBookEntry(func);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (by_label)
|
if (by_label) {
|
||||||
{
|
for (const auto& entry : label_tally) {
|
||||||
for (const auto& entry : label_tally)
|
|
||||||
{
|
|
||||||
CAmount nAmount = entry.second.nAmount;
|
CAmount nAmount = entry.second.nAmount;
|
||||||
int nConf = entry.second.nConf;
|
int nConf = entry.second.nConf;
|
||||||
UniValue obj(UniValue::VOBJ);
|
UniValue obj(UniValue::VOBJ);
|
||||||
|
|
Loading…
Add table
Reference in a new issue