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