]>
Commit | Line | Data |
---|---|---|
f914f1a7 | 1 | // Copyright (c) 2011-2013 The Bitcoin Core developers |
78253fcb | 2 | // Distributed under the MIT software license, see the accompanying |
e592d43f WL |
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | ||
84738627 PJ |
5 | #ifndef BITCOIN_QT_TRANSACTIONRECORD_H |
6 | #define BITCOIN_QT_TRANSACTIONRECORD_H | |
f488e735 | 7 | |
a372168e | 8 | #include "amount.h" |
ceb6d4e1 | 9 | #include "uint256.h" |
f488e735 WL |
10 | |
11 | #include <QList> | |
ed4c7fd4 | 12 | #include <QString> |
f488e735 | 13 | |
e8ef3da7 | 14 | class CWallet; |
ceb6d4e1 | 15 | class CWalletTx; |
e8ef3da7 | 16 | |
af836ad5 WL |
17 | /** UI model for transaction status. The transaction status is the part of a transaction that will change over time. |
18 | */ | |
f488e735 WL |
19 | class TransactionStatus |
20 | { | |
21 | public: | |
22 | TransactionStatus(): | |
ad26dc9c | 23 | countsForBalance(false), sortKey(""), |
3015e0bc | 24 | matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1) |
ad26dc9c | 25 | { } |
f488e735 | 26 | |
f488e735 | 27 | enum Status { |
f642fd9d WL |
28 | Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/ |
29 | /// Normal (sent/received) transactions | |
30 | OpenUntilDate, /**< Transaction not yet final, waiting for date */ | |
31 | OpenUntilBlock, /**< Transaction not yet final, waiting for block */ | |
32 | Offline, /**< Not sent to any other nodes **/ | |
33 | Unconfirmed, /**< Not yet mined into a block **/ | |
34 | Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/ | |
35 | Conflicted, /**< Conflicts with other transaction or mempool **/ | |
36 | /// Generated (mined) transactions | |
37 | Immature, /**< Mined but waiting for maturity */ | |
38 | MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */ | |
39 | NotAccepted /**< Mined but not accepted */ | |
f488e735 WL |
40 | }; |
41 | ||
f642fd9d WL |
42 | /// Transaction counts towards available balance |
43 | bool countsForBalance; | |
44 | /// Sorting key based on status | |
f488e735 WL |
45 | std::string sortKey; |
46 | ||
af836ad5 WL |
47 | /** @name Generated (mined) transactions |
48 | @{*/ | |
f488e735 | 49 | int matures_in; |
af836ad5 | 50 | /**@}*/ |
f488e735 | 51 | |
af836ad5 WL |
52 | /** @name Reported status |
53 | @{*/ | |
f488e735 | 54 | Status status; |
51ed9ec9 BD |
55 | qint64 depth; |
56 | qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number | |
10046e27 PT |
57 | of additional blocks that need to be mined before |
58 | finalization */ | |
af836ad5 | 59 | /**@}*/ |
64bca50d | 60 | |
af836ad5 | 61 | /** Current number of blocks (to know whether cached status is still valid) */ |
64bca50d | 62 | int cur_num_blocks; |
f488e735 WL |
63 | }; |
64 | ||
af836ad5 WL |
65 | /** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has |
66 | multiple outputs. | |
67 | */ | |
f488e735 WL |
68 | class TransactionRecord |
69 | { | |
70 | public: | |
71 | enum Type | |
72 | { | |
73 | Other, | |
74 | Generated, | |
75 | SendToAddress, | |
56c6e369 | 76 | SendToOther, |
8c937da5 | 77 | RecvWithAddress, |
56c6e369 | 78 | RecvFromOther, |
f488e735 WL |
79 | SendToSelf |
80 | }; | |
81 | ||
f642fd9d WL |
82 | /** Number of confirmation recommended for accepting a transaction */ |
83 | static const int RecommendedNumConfirmations = 6; | |
18b99e3f | 84 | |
f488e735 | 85 | TransactionRecord(): |
64bca50d | 86 | hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0) |
f488e735 WL |
87 | { |
88 | } | |
89 | ||
51ed9ec9 | 90 | TransactionRecord(uint256 hash, qint64 time): |
f488e735 | 91 | hash(hash), time(time), type(Other), address(""), debit(0), |
64bca50d | 92 | credit(0), idx(0) |
f488e735 WL |
93 | { |
94 | } | |
95 | ||
51ed9ec9 | 96 | TransactionRecord(uint256 hash, qint64 time, |
f488e735 | 97 | Type type, const std::string &address, |
a372168e | 98 | const CAmount& debit, const CAmount& credit): |
f488e735 | 99 | hash(hash), time(time), type(type), address(address), debit(debit), credit(credit), |
64bca50d | 100 | idx(0) |
f488e735 WL |
101 | { |
102 | } | |
103 | ||
af836ad5 | 104 | /** Decompose CWallet transaction to model transaction records. |
63760fa1 | 105 | */ |
f488e735 | 106 | static bool showTransaction(const CWalletTx &wtx); |
e8ef3da7 | 107 | static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx); |
f488e735 | 108 | |
af836ad5 WL |
109 | /** @name Immutable transaction attributes |
110 | @{*/ | |
f488e735 | 111 | uint256 hash; |
51ed9ec9 | 112 | qint64 time; |
f488e735 WL |
113 | Type type; |
114 | std::string address; | |
a372168e MF |
115 | CAmount debit; |
116 | CAmount credit; | |
af836ad5 | 117 | /**@}*/ |
f488e735 | 118 | |
af836ad5 | 119 | /** Subtransaction index, for sort key */ |
64bca50d WL |
120 | int idx; |
121 | ||
af836ad5 | 122 | /** Status: can change with block chain update */ |
f488e735 | 123 | TransactionStatus status; |
64bca50d | 124 | |
d2692f61 J |
125 | /** Whether the transaction was sent/received with a watch-only address */ |
126 | bool involvesWatchAddress; | |
127 | ||
af836ad5 | 128 | /** Return the unique identifier for this transaction (part) */ |
ed4c7fd4 WL |
129 | QString getTxID() const; |
130 | ||
131 | /** Format subtransaction id */ | |
132 | static QString formatSubTxId(const uint256 &hash, int vout); | |
fbaee7a8 | 133 | |
af836ad5 | 134 | /** Update status from core wallet tx. |
64bca50d WL |
135 | */ |
136 | void updateStatus(const CWalletTx &wtx); | |
137 | ||
af836ad5 | 138 | /** Return whether a status update is needed. |
64bca50d | 139 | */ |
3015e0bc | 140 | bool statusUpdateNeeded(); |
f488e735 WL |
141 | }; |
142 | ||
84738627 | 143 | #endif // BITCOIN_QT_TRANSACTIONRECORD_H |