@@ -85,14 +85,12 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
8585 filter |= ISMINE_WATCH_ONLY;
8686 }
8787
88- bool has_filtered_address = false ;
89- CTxDestination filtered_address = CNoDestination ();
88+ std::optional<CTxDestination> filtered_address{std::nullopt };
9089 if (!by_label && !params[3 ].isNull () && !params[3 ].get_str ().empty ()) {
9190 if (!IsValidDestinationString (params[3 ].get_str ())) {
9291 throw JSONRPCError (RPC_WALLET_ERROR, " address_filter parameter was invalid" );
9392 }
9493 filtered_address = DecodeDestination (params[3 ].get_str ());
95- has_filtered_address = true ;
9694 }
9795
9896 // Tally
@@ -106,23 +104,21 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
106104
107105 // Coinbase with less than 1 confirmation is no longer in the main chain
108106 if ((wtx.IsCoinBase () && (nDepth < 1 ))
109- || (wallet.IsTxImmatureCoinBase (wtx) && !include_immature_coinbase))
110- {
107+ || (wallet.IsTxImmatureCoinBase (wtx) && !include_immature_coinbase)) {
111108 continue ;
112109 }
113110
114- for (const CTxOut& txout : wtx.tx ->vout )
115- {
111+ for (const CTxOut& txout : wtx.tx ->vout ) {
116112 CTxDestination address;
117113 if (!ExtractDestination (txout.scriptPubKey , address))
118114 continue ;
119115
120- if (has_filtered_address && !(filtered_address == address)) {
116+ if (filtered_address && !(filtered_address == address)) {
121117 continue ;
122118 }
123119
124120 isminefilter mine = wallet.IsMine (address);
125- if (!(mine & filter))
121+ if (!(mine & filter))
126122 continue ;
127123
128124 tallyitem& item = mapTally[address];
@@ -148,34 +144,27 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
148144 CAmount nAmount = 0 ;
149145 int nConf = std::numeric_limits<int >::max ();
150146 bool fIsWatchonly = false ;
151- if (it != mapTally.end ())
152- {
147+ if (it != mapTally.end ()) {
153148 nAmount = (*it).second .nAmount ;
154149 nConf = (*it).second .nConf ;
155150 fIsWatchonly = (*it).second .fIsWatchonly ;
156151 }
157152
158- if (by_label)
159- {
153+ if (by_label) {
160154 tallyitem& _item = label_tally[label];
161155 _item.nAmount += nAmount;
162156 _item.nConf = std::min (_item.nConf , nConf);
163157 _item.fIsWatchonly = fIsWatchonly ;
164- }
165- else
166- {
158+ } else {
167159 UniValue obj (UniValue::VOBJ);
168- if (fIsWatchonly )
169- obj.pushKV (" involvesWatchonly" , true );
160+ if (fIsWatchonly ) obj.pushKV (" involvesWatchonly" , true );
170161 obj.pushKV (" address" , EncodeDestination (address));
171162 obj.pushKV (" amount" , ValueFromAmount (nAmount));
172163 obj.pushKV (" confirmations" , (nConf == std::numeric_limits<int >::max () ? 0 : nConf));
173164 obj.pushKV (" label" , label);
174165 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 ) {
179168 transactions.push_back (_item.GetHex ());
180169 }
181170 }
@@ -184,18 +173,16 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
184173 }
185174 };
186175
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 );
190179 } else {
191180 // No filtered addr, walk-through the addressbook entry
192181 wallet.ForEachAddrBookEntry (func);
193182 }
194183
195- if (by_label)
196- {
197- for (const auto & entry : label_tally)
198- {
184+ if (by_label) {
185+ for (const auto & entry : label_tally) {
199186 CAmount nAmount = entry.second .nAmount ;
200187 int nConf = entry.second .nConf ;
201188 UniValue obj (UniValue::VOBJ);
0 commit comments