@@ -85,14 +85,12 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
85
85
filter |= ISMINE_WATCH_ONLY;
86
86
}
87
87
88
- bool has_filtered_address = false ;
89
- CTxDestination filtered_address = CNoDestination ();
88
+ std::optional<CTxDestination> filtered_address{std::nullopt};
90
89
if (!by_label && !params[3 ].isNull () && !params[3 ].get_str ().empty ()) {
91
90
if (!IsValidDestinationString (params[3 ].get_str ())) {
92
91
throw JSONRPCError (RPC_WALLET_ERROR, " address_filter parameter was invalid" );
93
92
}
94
93
filtered_address = DecodeDestination (params[3 ].get_str ());
95
- has_filtered_address = true ;
96
94
}
97
95
98
96
// Tally
@@ -106,23 +104,21 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
106
104
107
105
// Coinbase with less than 1 confirmation is no longer in the main chain
108
106
if ((wtx.IsCoinBase () && (nDepth < 1 ))
109
- || (wallet.IsTxImmatureCoinBase (wtx) && !include_immature_coinbase))
110
- {
107
+ || (wallet.IsTxImmatureCoinBase (wtx) && !include_immature_coinbase)) {
111
108
continue ;
112
109
}
113
110
114
- for (const CTxOut& txout : wtx.tx ->vout )
115
- {
111
+ for (const CTxOut& txout : wtx.tx ->vout ) {
116
112
CTxDestination address;
117
113
if (!ExtractDestination (txout.scriptPubKey , address))
118
114
continue ;
119
115
120
- if (has_filtered_address && !(filtered_address == address)) {
116
+ if (filtered_address && !(filtered_address == address)) {
121
117
continue ;
122
118
}
123
119
124
120
isminefilter mine = wallet.IsMine (address);
125
- if (!(mine & filter))
121
+ if (!(mine & filter))
126
122
continue ;
127
123
128
124
tallyitem& item = mapTally[address];
@@ -148,34 +144,27 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
148
144
CAmount nAmount = 0 ;
149
145
int nConf = std::numeric_limits<int >::max ();
150
146
bool fIsWatchonly = false ;
151
- if (it != mapTally.end ())
152
- {
147
+ if (it != mapTally.end ()) {
153
148
nAmount = (*it).second .nAmount ;
154
149
nConf = (*it).second .nConf ;
155
150
fIsWatchonly = (*it).second .fIsWatchonly ;
156
151
}
157
152
158
- if (by_label)
159
- {
153
+ if (by_label) {
160
154
tallyitem& _item = label_tally[label];
161
155
_item.nAmount += nAmount;
162
156
_item.nConf = std::min (_item.nConf , nConf);
163
157
_item.fIsWatchonly = fIsWatchonly ;
164
- }
165
- else
166
- {
158
+ } else {
167
159
UniValue obj (UniValue::VOBJ);
168
- if (fIsWatchonly )
169
- obj.pushKV (" involvesWatchonly" , true );
160
+ if (fIsWatchonly ) obj.pushKV (" involvesWatchonly" , true );
170
161
obj.pushKV (" address" , EncodeDestination (address));
171
162
obj.pushKV (" amount" , ValueFromAmount (nAmount));
172
163
obj.pushKV (" confirmations" , (nConf == std::numeric_limits<int >::max () ? 0 : nConf));
173
164
obj.pushKV (" label" , label);
174
165
UniValue transactions (UniValue::VARR);
175
- if (it != mapTally.end ())
176
- {
177
- for (const uint256& _item : (*it).second .txids )
178
- {
166
+ if (it != mapTally.end ()) {
167
+ for (const uint256& _item : (*it).second .txids ) {
179
168
transactions.push_back (_item.GetHex ());
180
169
}
181
170
}
@@ -184,18 +173,16 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
184
173
}
185
174
};
186
175
187
- if (has_filtered_address ) {
188
- const auto & entry = wallet.FindAddressBookEntry (filtered_address, /* allow_change=*/ false );
189
- if (entry) func (filtered_address, entry->GetLabel (), entry->purpose , /* is_change=*/ false );
176
+ if (filtered_address ) {
177
+ const auto & entry = wallet.FindAddressBookEntry (* filtered_address, /* allow_change=*/ false );
178
+ if (entry) func (* filtered_address, entry->GetLabel (), entry->purpose , /* is_change=*/ false );
190
179
} else {
191
180
// No filtered addr, walk-through the addressbook entry
192
181
wallet.ForEachAddrBookEntry (func);
193
182
}
194
183
195
- if (by_label)
196
- {
197
- for (const auto & entry : label_tally)
198
- {
184
+ if (by_label) {
185
+ for (const auto & entry : label_tally) {
199
186
CAmount nAmount = entry.second .nAmount ;
200
187
int nConf = entry.second .nConf ;
201
188
UniValue obj (UniValue::VOBJ);
0 commit comments