Fabcoin Core  0.16.2
P2P Digital Currency
tokentransactiondesc.cpp
Go to the documentation of this file.
1 #include <tokentransactiondesc.h>
3 #include <fabcoinunits.h>
4 #include <guiutil.h>
5 #include <uint256.h>
6 #include <validation.h>
7 #include <wallet/wallet.h>
8 #include <timedata.h>
9 
11 {
13 
14  // Determine transaction status
15  int nDepth= 0;
16  if(wtx.blockNumber == -1)
17  {
18  nDepth = 0;
19  }
20  else
21  {
22  nDepth = chainActive.Height() - wtx.blockNumber + 1;
23  }
24 
25  auto mi = wallet->mapWallet.find(wtx.transactionHash);
26  if (nDepth < 0)
27  return tr("conflicted with a transaction with %1 confirmations").arg(-nDepth);
28  else if (mi != wallet->mapWallet.end() && (GetAdjustedTime() - mi->second.nTimeReceived > 2 * 60) && mi->second.GetRequestCount() == 0)
29  return tr("%1/offline").arg(nDepth);
30  else if (nDepth == 0)
31  {
32  if(mi != wallet->mapWallet.end() && mi->second.InMempool())
33  return tr("0/unconfirmed, in memory pool");
34  else
35  return tr("0/unconfirmed, not in memory pool");
36  }
38  return tr("%1/unconfirmed").arg(nDepth);
39  else
40  return tr("%1 confirmations").arg(nDepth);
41 }
42 
44 {
45  QString strHTML;
46 
47  LOCK2(cs_main, wallet->cs_wallet);
48  strHTML.reserve(4000);
49  strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
50 
51  int64_t nTime = rec->time;
52  dev::s256 nDebit = rec->debit;
53  dev::s256 nCredit = rec->credit;
54  dev::s256 nNet = nCredit + nDebit;
55  QString unit = QString::fromStdString(rec->tokenSymbol);
56 
57  strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wallet, wtx);
58 
59  strHTML += "<br>";
60 
61  strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>";
62 
63  strHTML += "<b>" + tr("Transaction ID") + ":</b> " + rec->getTxID() + "<br>";
64 
65  strHTML += "<b>" + tr("Token Address") + ":</b> " + QString::fromStdString(wtx.strContractAddress) + "<br>";
66 
67  strHTML += "<b>" + tr("From") + ":</b> " + QString::fromStdString(wtx.strSenderAddress) + "<br>";
68 
69  strHTML += "<b>" + tr("To") + ":</b> " + QString::fromStdString(wtx.strReceiverAddress) + "<br>";
70 
71  if(nCredit > 0)
72  {
73  strHTML += "<b>" + tr("Credit") + ":</b> " + FabcoinUnits::formatTokenWithUnit(unit, rec->decimals, nCredit, true) + "<br>";
74  }
75  if(nDebit < 0)
76  {
77  strHTML += "<b>" + tr("Debit") + ":</b> " + FabcoinUnits::formatTokenWithUnit(unit, rec->decimals, nDebit, true) + "<br>";
78  }
79  strHTML += "<b>" + tr("Net Amount") + ":</b> " + FabcoinUnits::formatTokenWithUnit(unit, rec->decimals, nNet, true) + "<br>";
80 
81 
82  strHTML += "</font></html>";
83  return strHTML;
84 }
std::string strReceiverAddress
Definition: wallet.h:1357
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::signed_magnitude, boost::multiprecision::unchecked, void >> s256
Definition: Common.h:126
CCriticalSection cs_wallet
Definition: wallet.h:748
CCriticalSection cs_main
Definition: validation.cpp:77
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:80
static QString formatTokenWithUnit(const QString unit, int decimals, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
UI model for a token transaction.
static QString FormatTxStatus(CWallet *wallet, const CTokenTx &wtx)
int64_t blockNumber
Definition: wallet.h:1364
std::string strContractAddress
Definition: wallet.h:1355
#define AssertLockHeld(cs)
Definition: sync.h:85
#define LOCK2(cs1, cs2)
Definition: sync.h:176
int Height() const
Return the maximal height in the chain.
Definition: chain.h:543
static QString toHTML(CWallet *wallet, CTokenTx &wtx, TokenTransactionRecord *rec)
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:80
QString getTxID() const
Return the unique identifier for this transaction (part)
int64_t GetAdjustedTime()
Definition: timedata.cpp:35
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:672
std::map< uint256, CWalletTx > mapWallet
Definition: wallet.h:815
std::string strSenderAddress
Definition: wallet.h:1356
uint256 transactionHash
Definition: wallet.h:1359
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a token transaction.