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