Use standard C99 (and Qt) types for 64-bit integers
[novacoin.git] / src / qt / transactionrecord.h
1 #ifndef TRANSACTIONRECORD_H
2 #define TRANSACTIONRECORD_H
3
4 #include "uint256.h"
5
6 #include <QtGlobal>
7 #include <QList>
8
9 class CWallet;
10 class CWalletTx;
11
12 /** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
13  */
14 class TransactionStatus
15 {
16 public:
17     TransactionStatus():
18             confirmed(false), sortKey(""), maturity(Mature),
19             matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
20     { }
21
22     enum Maturity
23     {
24         Immature,
25         Mature,
26         MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
27         NotAccepted
28     };
29
30     enum Status {
31         OpenUntilDate,
32         OpenUntilBlock,
33         Offline,
34         Unconfirmed,
35         HaveConfirmations
36     };
37
38     bool confirmed;
39     std::string sortKey;
40
41     /** @name Generated (mined) transactions
42        @{*/
43     Maturity maturity;
44     int matures_in;
45     /**@}*/
46
47     /** @name Reported status
48        @{*/
49     Status status;
50     qint64 depth;
51     qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number of blocks */
52     /**@}*/
53
54     /** Current number of blocks (to know whether cached status is still valid) */
55     int cur_num_blocks;
56 };
57
58 /** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
59     multiple outputs.
60  */
61 class TransactionRecord
62 {
63 public:
64     enum Type
65     {
66         Other,
67         Generated,
68         SendToAddress,
69         SendToIP,
70         RecvWithAddress,
71         RecvFromIP,
72         SendToSelf
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, qint64 time):
84             hash(hash), time(time), type(Other), address(""), debit(0),
85             credit(0), idx(0)
86     {
87     }
88
89     TransactionRecord(uint256 hash, qint64 time,
90                 Type type, const std::string &address,
91                 qint64 debit, qint64 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     qint64 time;
106     Type type;
107     std::string address;
108     qint64 debit;
109     qint64 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