Pre-0.4.8 update
[novacoin.git] / src / qt / transactionrecord.h
1 #ifndef TRANSACTIONRECORD_H
2 #define TRANSACTIONRECORD_H
3
4 #include "uint256.h"
5
6 #include <QList>
7
8 class CWallet;
9 class CWalletTx;
10
11 /** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
12  */
13 class TransactionStatus
14 {
15 public:
16     TransactionStatus():
17             confirmed(false), sortKey(""), maturity(Mature),
18             matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
19     { }
20
21     enum Maturity
22     {
23         Immature,
24         Mature,
25         MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
26         NotAccepted
27     };
28
29     enum Status {
30         OpenUntilDate,
31         OpenUntilBlock,
32         Offline,
33         Unconfirmed,
34         HaveConfirmations
35     };
36
37     bool confirmed;
38     std::string sortKey;
39
40     /** @name Generated (mined) transactions
41        @{*/
42     Maturity maturity;
43     int matures_in;
44     /**@}*/
45
46     /** @name Reported status
47        @{*/
48     Status status;
49     int64 depth;
50     int64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number of blocks */
51     /**@}*/
52
53     /** Current number of blocks (to know whether cached status is still valid) */
54     int cur_num_blocks;
55 };
56
57 /** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
58     multiple outputs.
59  */
60 class TransactionRecord
61 {
62 public:
63     enum Type
64     {
65         Other,
66         Generated,
67         SendToAddress,
68         SendToOther,
69         RecvWithAddress,
70         RecvFromOther,
71         SendToSelf
72     };
73
74     /** Number of confirmation needed for transaction */
75     static const int NumConfirmations = 6;
76
77     TransactionRecord():
78             hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
79     {
80     }
81
82     TransactionRecord(uint256 hash, int64 time):
83             hash(hash), time(time), type(Other), address(""), debit(0),
84             credit(0), idx(0)
85     {
86     }
87
88     TransactionRecord(uint256 hash, int64 time,
89                 Type type, const std::string &address,
90                 int64 debit, int64 credit):
91             hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
92             idx(0)
93     {
94     }
95
96     /** Decompose CWallet transaction to model transaction records.
97      */
98     static bool showTransaction(const CWalletTx &wtx);
99     static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
100
101     /** @name Immutable transaction attributes
102       @{*/
103     uint256 hash;
104     int64 time;
105     Type type;
106     std::string address;
107     int64 debit;
108     int64 credit;
109     /**@}*/
110
111     /** Subtransaction index, for sort key */
112     int idx;
113
114     /** Status: can change with block chain update */
115     TransactionStatus status;
116
117     /** Return the unique identifier for this transaction (part) */
118     std::string getTxID();
119
120     /** Update status from core wallet tx.
121      */
122     void updateStatus(const CWalletTx &wtx);
123
124     /** Return whether a status update is needed.
125      */
126     bool statusUpdateNeeded();
127 };
128
129 #endif // TRANSACTIONRECORD_H