Line data Source code
1 : // Copyright (c) 2011-2013 The Bitcoin Core developers
2 : // Distributed under the MIT software license, see the accompanying
3 : // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 :
5 : #ifndef BITCOIN_QT_TRANSACTIONRECORD_H
6 : #define BITCOIN_QT_TRANSACTIONRECORD_H
7 :
8 : #include "amount.h"
9 : #include "uint256.h"
10 :
11 : #include <QList>
12 : #include <QString>
13 :
14 : class CWallet;
15 : class CWalletTx;
16 :
17 : /** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
18 : */
19 0 : class TransactionStatus
20 : {
21 : public:
22 0 : TransactionStatus():
23 : countsForBalance(false), sortKey(""),
24 0 : matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
25 0 : { }
26 :
27 : enum Status {
28 : Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
29 : /// Normal (sent/received) transactions
30 : OpenUntilDate, /**< Transaction not yet final, waiting for date */
31 : OpenUntilBlock, /**< Transaction not yet final, waiting for block */
32 : Offline, /**< Not sent to any other nodes **/
33 : Unconfirmed, /**< Not yet mined into a block **/
34 : Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
35 : Conflicted, /**< Conflicts with other transaction or mempool **/
36 : /// Generated (mined) transactions
37 : Immature, /**< Mined but waiting for maturity */
38 : MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
39 : NotAccepted /**< Mined but not accepted */
40 : };
41 :
42 : /// Transaction counts towards available balance
43 : bool countsForBalance;
44 : /// Sorting key based on status
45 : std::string sortKey;
46 :
47 : /** @name Generated (mined) transactions
48 : @{*/
49 : int matures_in;
50 : /**@}*/
51 :
52 : /** @name Reported status
53 : @{*/
54 : Status status;
55 : qint64 depth;
56 : qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
57 : of additional blocks that need to be mined before
58 : finalization */
59 : /**@}*/
60 :
61 : /** Current number of blocks (to know whether cached status is still valid) */
62 : int cur_num_blocks;
63 : };
64 :
65 : /** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
66 : multiple outputs.
67 : */
68 0 : class TransactionRecord
69 : {
70 : public:
71 : enum Type
72 : {
73 : Other,
74 : Generated,
75 : SendToAddress,
76 : SendToOther,
77 : RecvWithAddress,
78 : RecvFromOther,
79 : SendToSelf
80 : };
81 :
82 : /** Number of confirmation recommended for accepting a transaction */
83 : static const int RecommendedNumConfirmations = 6;
84 :
85 : TransactionRecord():
86 : hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
87 : {
88 : }
89 :
90 0 : TransactionRecord(uint256 hash, qint64 time):
91 : hash(hash), time(time), type(Other), address(""), debit(0),
92 0 : credit(0), idx(0)
93 : {
94 0 : }
95 :
96 0 : TransactionRecord(uint256 hash, qint64 time,
97 : Type type, const std::string &address,
98 : const CAmount& debit, const CAmount& credit):
99 : hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
100 0 : idx(0)
101 : {
102 0 : }
103 :
104 : /** Decompose CWallet transaction to model transaction records.
105 : */
106 : static bool showTransaction(const CWalletTx &wtx);
107 : static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
108 :
109 : /** @name Immutable transaction attributes
110 : @{*/
111 : uint256 hash;
112 : qint64 time;
113 : Type type;
114 : std::string address;
115 : CAmount debit;
116 : CAmount credit;
117 : /**@}*/
118 :
119 : /** Subtransaction index, for sort key */
120 : int idx;
121 :
122 : /** Status: can change with block chain update */
123 : TransactionStatus status;
124 :
125 : /** Whether the transaction was sent/received with a watch-only address */
126 : bool involvesWatchAddress;
127 :
128 : /** Return the unique identifier for this transaction (part) */
129 : QString getTxID() const;
130 :
131 : /** Format subtransaction id */
132 : static QString formatSubTxId(const uint256 &hash, int vout);
133 :
134 : /** Update status from core wallet tx.
135 : */
136 : void updateStatus(const CWalletTx &wtx);
137 :
138 : /** Return whether a status update is needed.
139 : */
140 : bool statusUpdateNeeded();
141 : };
142 :
143 : #endif // BITCOIN_QT_TRANSACTIONRECORD_H
|