Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
transactiondesc.cpp
Go to the documentation of this file.
1 #include "transactiondesc.h"
2 
3 #include "guiutil.h"
4 #include "bitcoinunits.h"
5 #include "main.h"
6 #include "wallet.h"
7 #include "db.h"
8 #include "ui_interface.h"
9 #include "base58.h"
10 
11 #include <string>
12 
14 {
15  if (!wtx.IsFinal())
16  {
17  if (wtx.nLockTime < LOCKTIME_THRESHOLD)
18  return tr("Open for %n more block(s)", "", wtx.nLockTime - nBestHeight + 1);
19  else
20  return tr("Open until %1").arg(GUIUtil::dateTimeStr(wtx.nLockTime));
21  }
22  else
23  {
24  int nDepth = wtx.GetDepthInMainChain();
25  if (GetAdjustedTime() - wtx.nTimeReceived > 2 * 60 && wtx.GetRequestCount() == 0)
26  return tr("%1/offline").arg(nDepth);
27  else if (nDepth < 6)
28  return tr("%1/unconfirmed").arg(nDepth);
29  else
30  return tr("%1 confirmations").arg(nDepth);
31  }
32 }
33 
35 {
36  QString strHTML;
37 
38  {
39  LOCK(wallet->cs_wallet);
40  strHTML.reserve(4000);
41  strHTML += "<html><font face='verdana, arial, helvetica, sans-serif'>";
42 
43  int64 nTime = wtx.GetTxTime();
44  int64 nCredit = wtx.GetCredit();
45  int64 nDebit = wtx.GetDebit();
46  int64 nNet = nCredit - nDebit;
47 
48  strHTML += "<b>" + tr("Status") + ":</b> " + FormatTxStatus(wtx);
49  int nRequests = wtx.GetRequestCount();
50  if (nRequests != -1)
51  {
52  if (nRequests == 0)
53  strHTML += tr(", has not been successfully broadcast yet");
54  else if (nRequests > 0)
55  strHTML += tr(", broadcast through %n node(s)", "", nRequests);
56  }
57  strHTML += "<br>";
58 
59  strHTML += "<b>" + tr("Date") + ":</b> " + (nTime ? GUIUtil::dateTimeStr(nTime) : "") + "<br>";
60 
61  //
62  // From
63  //
64  if (wtx.IsCoinBase())
65  {
66  strHTML += "<b>" + tr("Source") + ":</b> " + tr("Generated") + "<br>";
67  }
68  else if (wtx.mapValue.count("from") && !wtx.mapValue["from"].empty())
69  {
70  // Online transaction
71  strHTML += "<b>" + tr("From") + ":</b> " + GUIUtil::HtmlEscape(wtx.mapValue["from"]) + "<br>";
72  }
73  else
74  {
75  // Offline transaction
76  if (nNet > 0)
77  {
78  // Credit
79  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
80  {
81  if (wallet->IsMine(txout))
82  {
83  CTxDestination address;
84  if (ExtractDestination(txout.scriptPubKey, address) && IsMine(*wallet, address))
85  {
86  if (wallet->mapAddressBook.count(address))
87  {
88  strHTML += "<b>" + tr("From") + ":</b> " + tr("unknown") + "<br>";
89  strHTML += "<b>" + tr("To") + ":</b> ";
90  strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString());
91  if (!wallet->mapAddressBook[address].empty())
92  strHTML += " (" + tr("own address") + ", " + tr("label") + ": " + GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + ")";
93  else
94  strHTML += " (" + tr("own address") + ")";
95  strHTML += "<br>";
96  }
97  }
98  break;
99  }
100  }
101  }
102  }
103 
104  //
105  // To
106  //
107  if (wtx.mapValue.count("to") && !wtx.mapValue["to"].empty())
108  {
109  // Online transaction
110  std::string strAddress = wtx.mapValue["to"];
111  strHTML += "<b>" + tr("To") + ":</b> ";
112  CTxDestination dest = CBitcoinAddress(strAddress).Get();
113  if (wallet->mapAddressBook.count(dest) && !wallet->mapAddressBook[dest].empty())
114  strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[dest]) + " ";
115  strHTML += GUIUtil::HtmlEscape(strAddress) + "<br>";
116  }
117 
118  //
119  // Amount
120  //
121  if (wtx.IsCoinBase() && nCredit == 0)
122  {
123  //
124  // Coinbase
125  //
126  int64 nUnmatured = 0;
127  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
128  nUnmatured += wallet->GetCredit(txout);
129  strHTML += "<b>" + tr("Credit") + ":</b> ";
130  if (wtx.IsInMainChain())
131  strHTML += BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nUnmatured)+ " (" + tr("matures in %n more block(s)", "", wtx.GetBlocksToMaturity()) + ")";
132  else
133  strHTML += "(" + tr("not accepted") + ")";
134  strHTML += "<br>";
135  }
136  else if (nNet > 0)
137  {
138  //
139  // Credit
140  //
141  strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nNet) + "<br>";
142  }
143  else
144  {
145  bool fAllFromMe = true;
146  BOOST_FOREACH(const CTxIn& txin, wtx.vin)
147  fAllFromMe = fAllFromMe && wallet->IsMine(txin);
148 
149  bool fAllToMe = true;
150  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
151  fAllToMe = fAllToMe && wallet->IsMine(txout);
152 
153  if (fAllFromMe)
154  {
155  //
156  // Debit
157  //
158  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
159  {
160  if (wallet->IsMine(txout))
161  continue;
162 
163  if (!wtx.mapValue.count("to") || wtx.mapValue["to"].empty())
164  {
165  // Offline transaction
166  CTxDestination address;
167  if (ExtractDestination(txout.scriptPubKey, address))
168  {
169  strHTML += "<b>" + tr("To") + ":</b> ";
170  if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
171  strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
172  strHTML += GUIUtil::HtmlEscape(CBitcoinAddress(address).ToString());
173  strHTML += "<br>";
174  }
175  }
176 
177  strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -txout.nValue) + "<br>";
178  }
179 
180  if (fAllToMe)
181  {
182  // Payment to self
183  int64 nChange = wtx.GetChange();
184  int64 nValue = nCredit - nChange;
185  strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -nValue) + "<br>";
186  strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nValue) + "<br>";
187  }
188 
189  int64 nTxFee = nDebit - wtx.GetValueOut();
190  if (nTxFee > 0)
191  strHTML += "<b>" + tr("Transaction fee") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -nTxFee) + "<br>";
192  }
193  else
194  {
195  //
196  // Mixed debit transaction
197  //
198  BOOST_FOREACH(const CTxIn& txin, wtx.vin)
199  if (wallet->IsMine(txin))
200  strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -wallet->GetDebit(txin)) + "<br>";
201  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
202  if (wallet->IsMine(txout))
203  strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout)) + "<br>";
204  }
205  }
206 
207  strHTML += "<b>" + tr("Net amount") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, nNet, true) + "<br>";
208 
209  //
210  // Message
211  //
212  if (wtx.mapValue.count("message") && !wtx.mapValue["message"].empty())
213  strHTML += "<br><b>" + tr("Message") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["message"], true) + "<br>";
214  if (wtx.mapValue.count("comment") && !wtx.mapValue["comment"].empty())
215  strHTML += "<br><b>" + tr("Comment") + ":</b><br>" + GUIUtil::HtmlEscape(wtx.mapValue["comment"], true) + "<br>";
216 
217  strHTML += "<b>" + tr("Transaction ID") + ":</b> " + wtx.GetHash().ToString().c_str() + "<br>";
218 
219  if (wtx.IsCoinBase())
220  strHTML += "<br>" + tr("Generated coins must mature 120 blocks before they can be spent. When you generated this block, it was broadcast to the network to be added to the block chain. If it fails to get into the chain, its state will change to \"not accepted\" and it won't be spendable. This may occasionally happen if another node generates a block within a few seconds of yours.") + "<br>";
221 
222  //
223  // Debug view
224  //
225  if (fDebug)
226  {
227  strHTML += "<hr><br>" + tr("Debug information") + "<br><br>";
228  BOOST_FOREACH(const CTxIn& txin, wtx.vin)
229  if(wallet->IsMine(txin))
230  strHTML += "<b>" + tr("Debit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, -wallet->GetDebit(txin)) + "<br>";
231  BOOST_FOREACH(const CTxOut& txout, wtx.vout)
232  if(wallet->IsMine(txout))
233  strHTML += "<b>" + tr("Credit") + ":</b> " + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, wallet->GetCredit(txout)) + "<br>";
234 
235  strHTML += "<br><b>" + tr("Transaction") + ":</b><br>";
236  strHTML += GUIUtil::HtmlEscape(wtx.ToString(), true);
237 
238  strHTML += "<br><b>" + tr("Inputs") + ":</b>";
239  strHTML += "<ul>";
240 
241  {
242  LOCK(wallet->cs_wallet);
243  BOOST_FOREACH(const CTxIn& txin, wtx.vin)
244  {
245  COutPoint prevout = txin.prevout;
246 
247  CCoins prev;
248  if(pcoinsTip->GetCoins(prevout.hash, prev))
249  {
250  if (prevout.n < prev.vout.size())
251  {
252  strHTML += "<li>";
253  const CTxOut &vout = prev.vout[prevout.n];
254  CTxDestination address;
255  if (ExtractDestination(vout.scriptPubKey, address))
256  {
257  if (wallet->mapAddressBook.count(address) && !wallet->mapAddressBook[address].empty())
258  strHTML += GUIUtil::HtmlEscape(wallet->mapAddressBook[address]) + " ";
259  strHTML += QString::fromStdString(CBitcoinAddress(address).ToString());
260  }
261  strHTML = strHTML + " " + tr("Amount") + "=" + BitcoinUnits::formatWithUnit(BitcoinUnits::BTC, vout.nValue);
262  strHTML = strHTML + " IsMine=" + (wallet->IsMine(vout) ? tr("true") : tr("false")) + "</li>";
263  }
264  }
265  }
266  }
267 
268  strHTML += "</ul>";
269  }
270 
271  strHTML += "</font></html>";
272  }
273  return strHTML;
274 }
LRUHandle * prev
Definition: cache.cc:30
static QString toHTML(CWallet *wallet, CWalletTx &wtx)
bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
Definition: main.h:520
bool IsMine(const CTxIn &txin) const
Definition: wallet.cpp:540
static QString formatWithUnit(int unit, qint64 amount, bool plussign=false)
Format as string (with unit)
CScript scriptPubKey
Definition: main.h:404
std::vector< CTxOut > vout
Definition: main.h:903
bool fDebug
Definition: util.cpp:73
CCriticalSection cs_wallet
Definition: wallet.h:83
QString dateTimeStr(const QDateTime &date)
Definition: guiutil.cpp:51
uint256 GetHash() const
Definition: main.h:515
QString HtmlEscape(const QString &str, bool fMultiLine)
Definition: guiutil.cpp:150
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
Definition: main.h:896
int64 GetDebit(const CTxIn &txin) const
Definition: wallet.cpp:556
unsigned int n
Definition: main.h:282
CTxDestination Get() const
Definition: base58.h:345
bool GetCoins(const uint256 &txid, CCoins &coins)
Definition: main.cpp:202
int64 GetCredit(bool fUseCache=true) const
Definition: wallet.h:565
mapValue_t mapValue
Definition: wallet.h:374
int GetBlocksToMaturity() const
Definition: main.cpp:931
int GetRequestCount() const
Definition: wallet.cpp:598
bool IsInMainChain() const
Definition: main.h:1165
unsigned int nLockTime
Definition: main.h:486
An input of a transaction.
Definition: main.h:323
#define LOCK(cs)
Definition: sync.h:108
std::vector< CTxOut > vout
Definition: main.h:485
std::vector< CTxIn > vin
Definition: main.h:484
int64 GetAdjustedTime()
Definition: util.cpp:1317
int64 GetDebit() const
Definition: wallet.h:554
An output of a transaction.
Definition: main.h:400
int64 GetValueOut() const
Amount of bitcoins spent by this transaction.
Definition: main.h:602
int64 GetChange() const
Definition: wallet.h:620
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: main.h:278
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:289
int64 GetCredit(const CTxOut &txout) const
Definition: wallet.h:209
std::string ToString() const
Definition: main.h:649
A transaction with a bunch of additional info that only the owner cares about.
Definition: wallet.h:367
int64 GetTxTime() const
Definition: wallet.cpp:592
int64 nValue
Definition: main.h:403
std::string ToString() const
Definition: uint256.h:343
bool IsMine(const CKeyStore &keystore, const CTxDestination &dest)
Definition: script.cpp:1378
bool ExtractDestination(const CScript &scriptPubKey, CTxDestination &addressRet)
Definition: script.cpp:1422
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:69
int GetDepthInMainChain(CBlockIndex *&pindexRet) const
Definition: main.cpp:905
std::map< CTxDestination, std::string > mapAddressBook
Definition: wallet.h:119
bool IsCoinBase() const
Definition: main.h:566
boost::variant< CNoDestination, CKeyID, CScriptID > CTxDestination
A txout script template with a specific destination.
Definition: script.h:62
static QString FormatTxStatus(const CWalletTx &wtx)
unsigned int nTimeReceived
Definition: wallet.h:377
int nBestHeight
Definition: main.cpp:41
COutPoint prevout
Definition: main.h:326
uint256 hash
Definition: main.h:281
long long int64
Definition: serialize.h:25