@@ -192,10 +192,10 @@ class Wallet
192192 virtual bool tryGetBalances (WalletBalances& balances, int & num_blocks) = 0;
193193
194194 // ! Get balance.
195- virtual CAmount getBalance () = 0;
195+ virtual CAmount getBalance (ColorIdentifier colorId = ColorIdentifier() ) = 0;
196196
197197 // ! Get available balance.
198- virtual CAmount getAvailableBalance (const CCoinControl& coin_control) = 0;
198+ virtual CAmount getAvailableBalance (const CCoinControl& coin_control, ColorIdentifier colorId = ColorIdentifier() ) = 0;
199199
200200 // ! Return whether transaction input belongs to wallet.
201201 virtual isminetype txinIsMine (const CTxIn& txin) = 0;
@@ -311,32 +311,35 @@ struct WalletBalances
311311 bool have_watch_only;
312312 TxColoredCoinBalancesMap watch_only_balances;
313313 TxColoredCoinBalancesMap unconfirmed_watch_only_balances;
314+ std::set<ColorIdentifier> tokens;
315+ std::set<ColorIdentifier>::iterator tokenIndex;
314316
315317 WalletBalances (){
316318 have_watch_only = false ;
319+ tokenIndex = tokens.begin ();
317320 }
318321
319- CAmount getBalance (const ColorIdentifier& colorId = ColorIdentifier() ) const
322+ CAmount getBalance () const
320323 {
321- auto it = balances.find (colorId );
324+ auto it = balances.find (*tokenIndex );
322325 return it != balances.end () ? it->second : 0 ;
323326 }
324327
325- CAmount getUnconfirmedBalance (const ColorIdentifier& colorId = ColorIdentifier() ) const
328+ CAmount getUnconfirmedBalance () const
326329 {
327- auto it = unconfirmed_balances.find (colorId );
330+ auto it = unconfirmed_balances.find (*tokenIndex );
328331 return it != unconfirmed_balances.end () ? it->second : 0 ;
329332 }
330333
331- CAmount getWatchOnlyBalance (const ColorIdentifier& colorId = ColorIdentifier() ) const
334+ CAmount getWatchOnlyBalance () const
332335 {
333- auto it = watch_only_balances.find (colorId );
336+ auto it = watch_only_balances.find (*tokenIndex );
334337 return it != watch_only_balances.end () ? it->second : 0 ;
335338 }
336339
337- CAmount getUnconfirmedWatchOnlyBalance (const ColorIdentifier& colorId = ColorIdentifier() ) const
340+ CAmount getUnconfirmedWatchOnlyBalance () const
338341 {
339- auto it = unconfirmed_watch_only_balances.find (colorId );
342+ auto it = unconfirmed_watch_only_balances.find (*tokenIndex );
340343 return it != unconfirmed_watch_only_balances.end () ? it->second : 0 ;
341344 }
342345
@@ -346,6 +349,53 @@ struct WalletBalances
346349 watch_only_balances != prev.watch_only_balances ||
347350 unconfirmed_watch_only_balances != prev.unconfirmed_watch_only_balances ;
348351 }
352+
353+ // collect all tokens in the wallet from all the balance lists
354+ void refreshTokens () {
355+ tokens.clear ();
356+
357+ for (auto pair:balances)
358+ tokens.insert (pair.first );
359+ for (auto pair:unconfirmed_balances)
360+ tokens.insert (pair.first );
361+ for (auto pair:watch_only_balances)
362+ tokens.insert (pair.first );
363+ for (auto pair:unconfirmed_watch_only_balances)
364+ tokens.insert (pair.first );
365+
366+ tokenIndex = tokens.begin ();
367+ }
368+
369+ void prev ()
370+ {
371+ if (tokenIndex != tokens.begin ())
372+ tokenIndex--;
373+ else
374+ {
375+ tokenIndex = tokens.end ();
376+ tokenIndex--;
377+ }
378+ }
379+
380+ void next ()
381+ {
382+ if (tokenIndex != tokens.end ())
383+ {
384+ tokenIndex++;
385+ if (tokenIndex == tokens.end ())
386+ tokenIndex = tokens.begin ();
387+ }
388+ }
389+
390+ bool isToken ()
391+ {
392+ return (*tokenIndex).type != TokenTypes::NONE;
393+ }
394+
395+ std::string getTokenName ()
396+ {
397+ return (*tokenIndex).toHexString ();
398+ }
349399};
350400
351401// Wallet transaction information.
0 commit comments