Skip to content

Commit 4926a92

Browse files
committed
colored coin support in transaction page in tapyrus qt gui
1 parent c48da8e commit 4926a92

File tree

12 files changed

+353
-247
lines changed

12 files changed

+353
-247
lines changed

doc/tapyrus/colored_coin_gui.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,7 @@ Receiving tokens is also similar to receiving TPC. In addition to lable, message
2121

2222
A new entry is added to the payment history table after the address is generated.
2323
![Received payment dialog](./images/Tapyrus-receive-dialog.png)
24+
25+
A new column called Token is added to the transaction table. It shows the token name or TPC for every transaction output. Amount column for TPC is formatted according to wallet setting. For tokens, it is always the number of tokens.
26+
27+
![Transaction page](./images/Tapyrus-transaction-page.png)
272 KB
Loading

src/interfaces/node.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <amount.h> // For CAmount
1010
#include <net.h> // For CConnman::NumConnections
1111
#include <netaddress.h> // For Network
12+
#include <coins.h>
1213

1314
#include <functional>
1415
#include <memory>
@@ -21,7 +22,6 @@
2122
class CCoinControl;
2223
class CFeeRate;
2324
class CNodeStats;
24-
class Coin;
2525
class RPCTimerInterface;
2626
class UniValue;
2727
class proxyType;

src/interfaces/wallet.cpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class PendingWalletTxImpl : public PendingWalletTx
5858
};
5959

6060
//! Construct wallet tx struct.
61-
WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
61+
WalletTx MakeWalletTx(Node& node, CWallet& wallet, const CWalletTx& wtx)
6262
{
6363
WalletTx result;
6464
result.tx = wtx.tx;
@@ -83,11 +83,13 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
8383
result.time = wtx.GetTxTime();
8484
result.value_map = wtx.mapValue;
8585
result.is_coinbase = wtx.IsCoinBase();
86+
result.is_tokenInput = result.isTokenInput(node);
87+
result.is_tokenOutput = result.isTokenOutput();
8688
return result;
8789
}
8890

8991
//! Construct wallet tx status struct.
90-
WalletTxStatus MakeWalletTxStatus(const CWalletTx& wtx)
92+
WalletTxStatus MakeWalletTxStatus(Node& node, const CWalletTx& wtx)
9193
{
9294
WalletTxStatus result;
9395
auto mi = ::mapBlockIndex.find(wtx.hashBlock);
@@ -274,26 +276,26 @@ class WalletImpl : public Wallet
274276
}
275277
return {};
276278
}
277-
WalletTx getWalletTx(const uint256& txid) override
279+
WalletTx getWalletTx(Node& node, const uint256& txid) override
278280
{
279281
LOCK2(::cs_main, m_wallet.cs_wallet);
280282
auto mi = m_wallet.mapWallet.find(txid);
281283
if (mi != m_wallet.mapWallet.end()) {
282-
return MakeWalletTx(m_wallet, mi->second);
284+
return MakeWalletTx(node, m_wallet, mi->second);
283285
}
284286
return {};
285287
}
286-
std::vector<WalletTx> getWalletTxs() override
288+
std::vector<WalletTx> getWalletTxs(Node& node) override
287289
{
288290
LOCK2(::cs_main, m_wallet.cs_wallet);
289291
std::vector<WalletTx> result;
290292
result.reserve(m_wallet.mapWallet.size());
291293
for (const auto& entry : m_wallet.mapWallet) {
292-
result.emplace_back(MakeWalletTx(m_wallet, entry.second));
294+
result.emplace_back(MakeWalletTx(node, m_wallet, entry.second));
293295
}
294296
return result;
295297
}
296-
bool tryGetTxStatus(const uint256& txid,
298+
bool tryGetTxStatus(Node& node, const uint256& txid,
297299
interfaces::WalletTxStatus& tx_status,
298300
int& num_blocks,
299301
int64_t& adjusted_time) override
@@ -312,10 +314,10 @@ class WalletImpl : public Wallet
312314
}
313315
num_blocks = ::chainActive.Height();
314316
adjusted_time = GetAdjustedTime();
315-
tx_status = MakeWalletTxStatus(mi->second);
317+
tx_status = MakeWalletTxStatus(node, mi->second);
316318
return true;
317319
}
318-
WalletTx getWalletTxDetails(const uint256& txid,
320+
WalletTx getWalletTxDetails(Node& node, const uint256& txid,
319321
WalletTxStatus& tx_status,
320322
WalletOrderForm& order_form,
321323
bool& in_mempool,
@@ -329,8 +331,8 @@ class WalletImpl : public Wallet
329331
adjusted_time = GetAdjustedTime();
330332
in_mempool = mi->second.InMempool();
331333
order_form = mi->second.vOrderForm;
332-
tx_status = MakeWalletTxStatus(mi->second);
333-
return MakeWalletTx(m_wallet, mi->second);
334+
tx_status = MakeWalletTxStatus(node, mi->second);
335+
return MakeWalletTx(node, m_wallet, mi->second);
334336
}
335337
return {};
336338
}

src/interfaces/wallet.h

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <script/standard.h> // For CTxDestination
1212
#include <support/allocators/secure.h> // For SecureString
1313
#include <ui_interface.h> // For ChangeType
14+
#include "node.h"
1415

1516
#include <functional>
1617
#include <map>
@@ -166,19 +167,19 @@ class Wallet
166167
virtual CTransactionRef getTx(const uint256& txid) = 0;
167168

168169
//! Get transaction information.
169-
virtual WalletTx getWalletTx(const uint256& txid) = 0;
170+
virtual WalletTx getWalletTx(Node& node, const uint256& txid) = 0;
170171

171172
//! Get list of all wallet transactions.
172-
virtual std::vector<WalletTx> getWalletTxs() = 0;
173+
virtual std::vector<WalletTx> getWalletTxs(Node& node) = 0;
173174

174175
//! Try to get updated status for a particular transaction, if possible without blocking.
175-
virtual bool tryGetTxStatus(const uint256& txid,
176+
virtual bool tryGetTxStatus(Node& node, const uint256& txid,
176177
WalletTxStatus& tx_status,
177178
int& num_blocks,
178179
int64_t& adjusted_time) = 0;
179180

180181
//! Get transaction details.
181-
virtual WalletTx getWalletTxDetails(const uint256& txid,
182+
virtual WalletTx getWalletTxDetails(Node& node, const uint256& txid,
182183
WalletTxStatus& tx_status,
183184
WalletOrderForm& order_form,
184185
bool& in_mempool,
@@ -412,6 +413,8 @@ struct WalletTx
412413
int64_t time;
413414
std::map<std::string, std::string> value_map;
414415
bool is_coinbase;
416+
bool is_tokenInput;
417+
bool is_tokenOutput;
415418

416419
CAmount getCredit(const ColorIdentifier& colorId = ColorIdentifier()) const
417420
{
@@ -430,6 +433,40 @@ struct WalletTx
430433
auto it = changes.find(colorId);
431434
return it != changes.end() ? it->second : 0;
432435
}
436+
437+
std::set<ColorIdentifier> getAllColorIds(Node& node) const
438+
{
439+
std::set<ColorIdentifier> txColorIdSet{ColorIdentifier()};
440+
//Get all color ids from all inputs and outputs
441+
for(auto in :tx->vin)
442+
{
443+
Coin prev;
444+
if(node.getUnspentOutput(in.prevout, prev))
445+
txColorIdSet.insert(GetColorIdFromScript(prev.out.scriptPubKey));
446+
}
447+
for(auto out:tx->vout)
448+
txColorIdSet.insert(GetColorIdFromScript(out.scriptPubKey));
449+
450+
return txColorIdSet;
451+
}
452+
453+
bool isTokenInput(Node& node) const
454+
{
455+
Coin prev;
456+
for(auto in :tx->vin)
457+
if(node.getUnspentOutput(in.prevout, prev) && GetColorIdFromScript(prev.out.scriptPubKey).type != TokenTypes::NONE)
458+
return true;
459+
return false;
460+
}
461+
462+
bool isTokenOutput() const
463+
{
464+
for(auto out:tx->vout)
465+
if(GetColorIdFromScript(out.scriptPubKey).type != TokenTypes::NONE)
466+
return true;
467+
468+
return false;
469+
}
433470
};
434471

435472
//! Updated transaction status.

src/qt/test_tapyrus_qt

11.4 MB
Binary file not shown.

0 commit comments

Comments
 (0)