8d4ab032a118bd5b136e7918d495396f70ee6a9e
[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         StakeMint
73     };
74
75     /** Number of confirmation needed for transaction */
76     static const int NumConfirmations = 6;
77
78     TransactionRecord():
79             hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
80     {
81     }
82
83     TransactionRecord(uint256 hash, int64 time):
84             hash(hash), time(time), type(Other), address(""), debit(0),
85             credit(0), idx(0)
86     {
87     }
88
89     TransactionRecord(uint256 hash, int64 time,
90                 Type type, const std::string &address,
91                 int64 debit, int64 credit):
92             hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
93             idx(0)
94     {
95     }
96
97     /** Decompose CWallet transaction to model transaction records.
98      */
99     static bool showTransaction(const CWalletTx &wtx);
100     static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
101
102     /** @name Immutable transaction attributes
103       @{*/
104     uint256 hash;
105     int64 time;
106     Type type;
107     std::string address;
108     int64 debit;
109     int64 credit;
110     /**@}*/
111
112     /** Subtransaction index, for sort key */
113     int idx;
114
115     /** Status: can change with block chain update */
116     TransactionStatus status;
117
118     /** Return the unique identifier for this transaction (part) */
119     std::string getTxID();
120
121     /** Update status from core wallet tx.
122      */
123     void updateStatus(const CWalletTx &wtx);
124
125     /** Return whether a status update is needed.
126      */
127     bool statusUpdateNeeded();
128 };
129
130 #endif // TRANSACTIONRECORD_H