@@ -136,27 +136,13 @@ void BalancesDialog::UpdatePropSelector()
136136 ui->propSelectorWidget ->clear ();
137137 ui->propSelectorWidget ->addItem (" Wallet Totals (Summary)" ," 2147483646" ); // use last possible ID for summary for now
138138 // populate property selector
139- unsigned int nextPropIdMainEco = GetNextPropertyId (true ); // these allow us to end the for loop at the highest existing
140- unsigned int nextPropIdTestEco = GetNextPropertyId (false ); // property ID rather than a fixed value like 100000 (optimization)
141- for (unsigned int propertyId = 1 ; propertyId < nextPropIdMainEco; propertyId++) {
142- if ((global_balance_money_maineco[propertyId] > 0 ) || (global_balance_reserved_maineco[propertyId] > 0 )) {
143- string spName;
144- spName = getPropertyName (propertyId).c_str ();
145- if (spName.size ()>20 ) spName=spName.substr (0 ,20 )+" ..." ;
146- string spId = static_cast <ostringstream*>( &(ostringstream () << propertyId) )->str ();
147- spName += " (#" + spId + " )" ;
148- ui->propSelectorWidget ->addItem (spName.c_str (),spId.c_str ());
149- }
150- }
151- for (unsigned int propertyId = 2147483647 ; propertyId < nextPropIdTestEco; propertyId++) {
152- if ((global_balance_money_testeco[propertyId-2147483647 ] > 0 ) || (global_balance_reserved_testeco[propertyId-2147483647 ] > 0 )) {
153- string spName;
154- spName = getPropertyName (propertyId).c_str ();
155- if (spName.size ()>20 ) spName=spName.substr (0 ,20 )+" ..." ;
156- string spId = static_cast <ostringstream*>( &(ostringstream () << propertyId) )->str ();
157- spName += " (#" + spId + " )" ;
158- ui->propSelectorWidget ->addItem (spName.c_str (),spId.c_str ());
159- }
139+ for (std::vector<uint32_t >::iterator it = global_wallet_property_list.begin () ; it != global_wallet_property_list.end (); ++it) {
140+ uint32_t propertyId = *it;
141+ std::string spId = static_cast <ostringstream*>( &(ostringstream () << propertyId) )->str ();
142+ std::string spName = getPropertyName (propertyId).c_str ();
143+ if (spName.size ()>20 ) spName=spName.substr (0 ,20 )+" ..." ;
144+ spName += " (#" + spId + " )" ;
145+ ui->propSelectorWidget ->addItem (spName.c_str (), spId.c_str ());
160146 }
161147 int propIdx = ui->propSelectorWidget ->findData (spId);
162148 if (propIdx != -1 ) { ui->propSelectorWidget ->setCurrentIndex (propIdx); }
@@ -187,71 +173,71 @@ void BalancesDialog::PopulateBalances(unsigned int propertyId)
187173 if (propertyId==2147483646 ) {
188174 ui->balancesTable ->setHorizontalHeaderItem (0 , new QTableWidgetItem (" Property ID" ));
189175 ui->balancesTable ->setHorizontalHeaderItem (1 , new QTableWidgetItem (" Property Name" ));
190- unsigned int nextPropIdMainEco = GetNextPropertyId (true );
191- unsigned int nextPropIdTestEco = GetNextPropertyId (false );
192- for (unsigned int propertyId = 1 ; propertyId < nextPropIdMainEco; propertyId++) {
193- if ((global_balance_money_maineco[propertyId] > 0 ) || (global_balance_reserved_maineco[propertyId] > 0 )) {
194- string spName = getPropertyName (propertyId).c_str ();
195- string spId = static_cast <ostringstream*>( &(ostringstream () << propertyId) )->str ();
196- string reserved;
197- string available;
198- if (isPropertyDivisible (propertyId)) {
199- reserved = FormatDivisibleMP (global_balance_reserved_maineco[propertyId]);
200- available = FormatDivisibleMP (global_balance_money_maineco[propertyId]);
201- } else {
202- reserved = FormatIndivisibleMP (global_balance_reserved_maineco[propertyId]);
203- available = FormatIndivisibleMP (global_balance_money_maineco[propertyId]);
204- }
205- AddRow (spId,spName,reserved,available);
206- }
207- }
208- for (unsigned int propertyId = 2147483647 ; propertyId < nextPropIdTestEco; propertyId++) {
209- if ((global_balance_money_testeco[propertyId-2147483647 ] > 0 ) || (global_balance_reserved_testeco[propertyId-2147483647 ] > 0 )) {
210- string spName = getPropertyName (propertyId).c_str ();
211- string spId = static_cast <ostringstream*>( &(ostringstream () << propertyId) )->str ();
212- string reserved;
213- string available;
214- if (isPropertyDivisible (propertyId)) {
215- reserved = FormatDivisibleMP (global_balance_reserved_testeco[propertyId-2147483647 ]);
216- available = FormatDivisibleMP (global_balance_money_testeco[propertyId-2147483647 ]);
217- } else {
218- reserved = FormatIndivisibleMP (global_balance_reserved_testeco[propertyId-2147483647 ]);
219- available = FormatIndivisibleMP (global_balance_money_testeco[propertyId-2147483647 ]);
220- }
221- AddRow (spId,spName,reserved,available);
176+
177+ // loop over the wallet property list and add the wallet totals
178+ for (std::vector<uint32_t >::iterator it = global_wallet_property_list.begin () ; it != global_wallet_property_list.end (); ++it) {
179+ uint32_t propertyId = *it;
180+ std::string spId = static_cast <ostringstream*>( &(ostringstream () << propertyId) )->str ();
181+ std::string spName = getPropertyName (propertyId).c_str ();
182+ std::string available, reserved;
183+ // TODO: merge test & main eco globals
184+ if (!isTestEcosystemProperty (propertyId)) {
185+ available = FormatMP (propertyId, global_balance_money_maineco[propertyId]);
186+ reserved = FormatMP (propertyId, global_balance_reserved_maineco[propertyId]);
187+ } else {
188+ available = FormatMP (propertyId, global_balance_money_testeco[propertyId]);
189+ reserved = FormatMP (propertyId, global_balance_reserved_testeco[propertyId]);
222190 }
191+ AddRow (spId, spName, reserved, available);
223192 }
224193 } else {
225194 ui->balancesTable ->setHorizontalHeaderItem (0 , new QTableWidgetItem (" Label" ));
226195 ui->balancesTable ->setHorizontalHeaderItem (1 , new QTableWidgetItem (" Address" ));
227196 LOCK (cs_tally);
228- for (std::map<string, CMPTally>::iterator my_it = mp_tally_map.begin (); my_it != mp_tally_map.end (); ++my_it)
229- {
230- string address = (my_it->first ).c_str ();
231- unsigned int id;
232- bool includeAddress=false ;
233- (my_it->second ).init ();
197+ bool propertyIsDivisible = isPropertyDivisible (propertyId); // only fetch the SP once, not for every address
198+
199+ // iterate mp_tally_map looking for addresses that hold a balance in propertyId
200+ for (std::map<string, CMPTally>::iterator my_it = mp_tally_map.begin (); my_it != mp_tally_map.end (); ++my_it) {
201+ string address = my_it->first .c_str ();
202+ my_it->second .init ();
203+ uint32_t id;
204+ bool watchAddress = false , includeAddress = false ;
234205 while (0 != (id = (my_it->second ).next ())) {
235- if (id==propertyId) { includeAddress=true ; break ; }
206+ if (id == propertyId) {
207+ includeAddress = true ;
208+ break ;
209+ }
236210 }
237211 if (!includeAddress) continue ; // ignore this address, has never transacted in this propertyId
212+
213+ // determine if this address is in the wallet
238214 if (!IsMyAddress (address)) continue ; // ignore this address, it's not ours
215+ if (!IsMyAddressSpendable (address)) watchAddress = true ;
216+
217+ // obtain the balances for the address
239218 int64_t available = getUserAvailableMPbalance (address, propertyId);
240219 int64_t reserved = getMPbalance (address, propertyId, METADEX_RESERVE);
241220 if (propertyId<3 ) {
242221 reserved += getMPbalance (address, propertyId, ACCEPT_RESERVE);
243222 reserved += getMPbalance (address, propertyId, SELLOFFER_RESERVE);
244223 }
245- string reservedStr;
246- string availableStr;
247- if (isPropertyDivisible (propertyId)) {
224+
225+ // format the balances
226+ string reservedStr, availableStr;
227+ if (propertyIsDivisible) {
248228 reservedStr = FormatDivisibleMP (reserved);
249229 availableStr = FormatDivisibleMP (available);
250230 } else {
251231 reservedStr = FormatIndivisibleMP (reserved);
252232 availableStr = FormatIndivisibleMP (available);
253233 }
254- AddRow (getLabel (my_it->first ),my_it->first ,reservedStr,availableStr);
234+
235+ // add the row
236+ if (!watchAddress) {
237+ AddRow (getLabel (my_it->first ), address, reservedStr, availableStr);
238+ } else {
239+ AddRow (getLabel (my_it->first ), address + " (watch-only)" , reservedStr, availableStr);
240+ }
255241 }
256242 }
257243}
0 commit comments