Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions doc/tapyrus/colored_coin_gui.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Tapyrus core GUI

Tapyrus GUI has been enhanced to allow Token transactions. Following are the changes made

### Overview Page
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.

![Overview Page with token](./images/Tapyrus-overview-token.png)
Binary file added doc/tapyrus/images/Tapyrus-overview-token.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions src/interfaces/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,10 @@ class WalletImpl : public Wallet
num_blocks = ::chainActive.Height();
return true;
}
CAmount getBalance() override { return m_wallet.GetBalance()[ColorIdentifier()]; }
CAmount getAvailableBalance(const CCoinControl& coin_control) override
CAmount getBalance(ColorIdentifier colorId) override { return m_wallet.GetBalance()[colorId]; }
CAmount getAvailableBalance(const CCoinControl& coin_control, ColorIdentifier colorId) override
{
return m_wallet.GetAvailableBalance(&coin_control)[ColorIdentifier()];
return m_wallet.GetAvailableBalance(&coin_control)[colorId];
}
isminetype txinIsMine(const CTxIn& txin) override
{
Expand Down
70 changes: 60 additions & 10 deletions src/interfaces/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,10 @@ class Wallet
virtual bool tryGetBalances(WalletBalances& balances, int& num_blocks) = 0;

//! Get balance.
virtual CAmount getBalance() = 0;
virtual CAmount getBalance(ColorIdentifier colorId = ColorIdentifier()) = 0;

//! Get available balance.
virtual CAmount getAvailableBalance(const CCoinControl& coin_control) = 0;
virtual CAmount getAvailableBalance(const CCoinControl& coin_control, ColorIdentifier colorId = ColorIdentifier()) = 0;

//! Return whether transaction input belongs to wallet.
virtual isminetype txinIsMine(const CTxIn& txin) = 0;
Expand Down Expand Up @@ -311,32 +311,35 @@ struct WalletBalances
bool have_watch_only;
TxColoredCoinBalancesMap watch_only_balances;
TxColoredCoinBalancesMap unconfirmed_watch_only_balances;
std::set<ColorIdentifier> tokens;
std::set<ColorIdentifier>::iterator tokenIndex;

WalletBalances(){
have_watch_only = false;
tokenIndex = tokens.begin();
}

CAmount getBalance(const ColorIdentifier& colorId = ColorIdentifier()) const
CAmount getBalance() const
{
auto it = balances.find(colorId);
auto it = balances.find(*tokenIndex);
return it != balances.end() ? it->second : 0;
}

CAmount getUnconfirmedBalance(const ColorIdentifier& colorId = ColorIdentifier()) const
CAmount getUnconfirmedBalance() const
{
auto it = unconfirmed_balances.find(colorId);
auto it = unconfirmed_balances.find(*tokenIndex);
return it != unconfirmed_balances.end() ? it->second : 0;
}

CAmount getWatchOnlyBalance(const ColorIdentifier& colorId = ColorIdentifier()) const
CAmount getWatchOnlyBalance() const
{
auto it = watch_only_balances.find(colorId);
auto it = watch_only_balances.find(*tokenIndex);
return it != watch_only_balances.end() ? it->second : 0;
}

CAmount getUnconfirmedWatchOnlyBalance(const ColorIdentifier& colorId = ColorIdentifier()) const
CAmount getUnconfirmedWatchOnlyBalance() const
{
auto it = unconfirmed_watch_only_balances.find(colorId);
auto it = unconfirmed_watch_only_balances.find(*tokenIndex);
return it != unconfirmed_watch_only_balances.end() ? it->second : 0;
}

Expand All @@ -346,6 +349,53 @@ struct WalletBalances
watch_only_balances != prev.watch_only_balances ||
unconfirmed_watch_only_balances != prev.unconfirmed_watch_only_balances;
}

//collect all tokens in the wallet from all the balance lists
void refreshTokens() {
tokens.clear();

for(auto pair:balances)
tokens.insert(pair.first);
for(auto pair:unconfirmed_balances)
tokens.insert(pair.first);
for(auto pair:watch_only_balances)
tokens.insert(pair.first);
for(auto pair:unconfirmed_watch_only_balances)
tokens.insert(pair.first);

tokenIndex = tokens.begin();
}

void prev()
{
if(tokenIndex != tokens.begin())
tokenIndex--;
else
{
tokenIndex = tokens.end();
tokenIndex--;
}
}

void next()
{
if(tokenIndex != tokens.end())
{
tokenIndex++;
if(tokenIndex == tokens.end())
tokenIndex = tokens.begin();
}
}

bool isToken()
{
return (*tokenIndex).type != TokenTypes::NONE;
}

std::string getTokenName()
{
return (*tokenIndex).toHexString();
}
};

// Wallet transaction information.
Expand Down
18 changes: 18 additions & 0 deletions src/key_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,21 @@ bool IsValidDestinationString(const std::string& str)
{
return IsValidDestinationString(str, Params());
}

bool IsColoredDestination(const std::string& str, ColorIdentifier* colorId)
{
CTxDestination dest = DecodeDestination(str, Params());
if(dest.which() == 3)
{
if(colorId)
*colorId = boost::get<CColorKeyID>(dest).color;
return true;
}
else if(dest.which() == 4)
{
if(colorId)
*colorId = boost::get<CColorScriptID>(dest).color;
return true;
}
return false;
}
1 change: 1 addition & 0 deletions src/key_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ std::string EncodeDestination(const CTxDestination& dest);
CTxDestination DecodeDestination(const std::string& str);
bool IsValidDestinationString(const std::string& str);
bool IsValidDestinationString(const std::string& str, const CChainParams& params);
bool IsColoredDestination(const std::string& str, ColorIdentifier* colorId);

#endif // BITCOIN_KEY_IO_H
Loading