Skip to content

Commit 83d6c7e

Browse files
committed
Overview page with colored coin support
1 parent 1daab39 commit 83d6c7e

File tree

11 files changed

+292
-90
lines changed

11 files changed

+292
-90
lines changed

doc/tapyrus/colored_coin_gui.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Tapyrus core GUI
2+
3+
Tapyrus GUI has been enhanced to allow Token transactions. Following are the changes made
4+
5+
### Overview Page
6+
Overview in the new Tapyrus GUI shows tokens as well. TPC is in view when the gui starts. _Prev_ and _Next_ buttons can be used to scroll through all the available tokens. When no other tokens are available only TPC is visible.
7+
8+
![Overview Page with token](./images/Tapyrus-overview-token.png)
191 KB
Loading

src/interfaces/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,10 +358,10 @@ class WalletImpl : public Wallet
358358
num_blocks = ::chainActive.Height();
359359
return true;
360360
}
361-
CAmount getBalance() override { return m_wallet.GetBalance()[ColorIdentifier()]; }
362-
CAmount getAvailableBalance(const CCoinControl& coin_control) override
361+
CAmount getBalance(ColorIdentifier colorId) override { return m_wallet.GetBalance()[colorId]; }
362+
CAmount getAvailableBalance(const CCoinControl& coin_control, ColorIdentifier colorId) override
363363
{
364-
return m_wallet.GetAvailableBalance(&coin_control)[ColorIdentifier()];
364+
return m_wallet.GetAvailableBalance(&coin_control)[colorId];
365365
}
366366
isminetype txinIsMine(const CTxIn& txin) override
367367
{

src/interfaces/wallet.h

Lines changed: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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.

src/key_io.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,3 +213,21 @@ bool IsValidDestinationString(const std::string& str)
213213
{
214214
return IsValidDestinationString(str, Params());
215215
}
216+
217+
bool IsColoredDestination(const std::string& str, ColorIdentifier* colorId)
218+
{
219+
CTxDestination dest = DecodeDestination(str, Params());
220+
if(dest.which() == 3)
221+
{
222+
if(colorId)
223+
*colorId = boost::get<CColorKeyID>(dest).color;
224+
return true;
225+
}
226+
else if(dest.which() == 4)
227+
{
228+
if(colorId)
229+
*colorId = boost::get<CColorScriptID>(dest).color;
230+
return true;
231+
}
232+
return false;
233+
}

src/key_io.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ std::string EncodeDestination(const CTxDestination& dest);
2525
CTxDestination DecodeDestination(const std::string& str);
2626
bool IsValidDestinationString(const std::string& str);
2727
bool IsValidDestinationString(const std::string& str, const CChainParams& params);
28+
bool IsColoredDestination(const std::string& str, ColorIdentifier* colorId);
2829

2930
#endif // BITCOIN_KEY_IO_H

0 commit comments

Comments
 (0)