Fabcoin Core  0.16.2
P2P Digital Currency
tokentransactionrecord.cpp
Go to the documentation of this file.
2 
3 #include <base58.h>
4 #include <consensus/consensus.h>
5 #include <validation.h>
6 #include <timedata.h>
7 #include <wallet/wallet.h>
8 
9 #include <stdint.h>
10 
11 /*
12  * Decompose CWallet transaction to model transaction records.
13  */
14 QList<TokenTransactionRecord> TokenTransactionRecord::decomposeTransaction(const CWallet *wallet, const CTokenTx &wtx)
15 {
16  // Initialize variables
17  QList<TokenTransactionRecord> parts;
19  uint256 debit;
20  std::string tokenSymbol;
21  uint8_t decimals = 18;
22  if(wallet && !wtx.nValue.IsNull() && wallet->GetTokenTxDetails(wtx, credit, debit, tokenSymbol, decimals))
23  {
24  // Get token transaction data
26  rec.time = wtx.nCreateTime;
27  rec.credit = dev::u2s(uintTou256(credit));
28  rec.debit = -dev::u2s(uintTou256(debit));
29  rec.hash = wtx.GetHash();
30  rec.txid = wtx.transactionHash;
32  rec.decimals = decimals;
33  rec.label = wtx.strLabel;
34  dev::s256 net = rec.credit + rec.debit;
35 
36  // Determine type
37  if(net == 0)
38  {
39  rec.type = SendToSelf;
40  }
41  else if(net > 0)
42  {
43  rec.type = RecvWithAddress;
44  }
45  else
46  {
47  rec.type = SendToAddress;
48  }
49 
50  if(net)
51  {
52  rec.status.countsForBalance = true;
53  }
54 
55  // Set address
56  switch (rec.type) {
57  case SendToSelf:
58  case SendToAddress:
59  case SendToOther:
60  case RecvWithAddress:
61  case RecvFromOther:
62  rec.address = wtx.strReceiverAddress;
63  default:
64  break;
65  }
66 
67  // Append record
68  if(rec.type != Other)
69  parts.append(rec);
70  }
71 
72  return parts;
73 }
74 
75 void TokenTransactionRecord::updateStatus(const CWallet *wallet, const CTokenTx &wtx)
76 {
78 
79  // Determine transaction status
81  if(wtx.blockNumber == -1)
82  {
83  status.depth = 0;
84  }
85  else
86  {
88  }
89 
90  auto mi = wallet->mapWallet.find(wtx.transactionHash);
91  if (mi != wallet->mapWallet.end() && (GetAdjustedTime() - mi->second.nTimeReceived > 2 * 60) && mi->second.GetRequestCount() == 0)
92  {
94  }
95  else if (status.depth == 0)
96  {
98  }
100  {
102  }
103  else
104  {
106  }
107 }
108 
110 {
113 }
114 
116 {
117  return QString::fromStdString(txid.ToString());
118 }
void updateStatus(const CWallet *wallet, const CTokenTx &wtx)
Update status from core wallet tx.
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
bool GetTokenTxDetails(const CTokenTx &wtx, uint256 &credit, uint256 &debit, std::string &tokenSymbol, uint8_t &decimals) const
Definition: wallet.cpp:4555
CCriticalSection cs_main
Definition: validation.cpp:77
UI model for a token transaction.
Confirmed, but waiting for the recommended number of confirmations.
int64_t blockNumber
Definition: wallet.h:1364
std::string ToString() const
Definition: uint256.cpp:95
int cur_num_blocks
Current number of blocks (to know whether cached status is still valid)
#define AssertLockHeld(cs)
Definition: sync.h:85
bool countsForBalance
Token transaction counts towards available balance.
int Height() const
Return the maximal height in the chain.
Definition: chain.h:543
static QList< TokenTransactionRecord > decomposeTransaction(const CWallet *wallet, const CTokenTx &wtx)
Decompose Token transaction into a record.
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
dev::u256 uintTou256(const uint256 &in)
Definition: uint256.h:184
bool IsNull() const
Definition: uint256.h:38
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)
std::string strLabel
Definition: wallet.h:1365
256-bit opaque blob.
Definition: uint256.h:132
s256 u2s(u256 _u)
Interprets _u as a two&#39;s complement signed number and returns the resulting s256. ...
Definition: Common.h:159
int64_t nCreateTime
Definition: wallet.h:1362
Normal (sent/received) token transactions.
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
TokenTransactionStatus status
Status: can change with block chain update.
uint256 nValue
Definition: wallet.h:1358
uint256 GetHash() const
Definition: wallet.cpp:4549
uint256 transactionHash
Definition: wallet.h:1359
bool statusUpdateNeeded()
Return whether a status update is needed.
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a token transaction.