2011-05-27 19:48:42 +02:00
|
|
|
#ifndef TRANSACTIONRECORD_H
|
|
|
|
#define TRANSACTIONRECORD_H
|
|
|
|
|
2011-06-28 21:41:56 +02:00
|
|
|
#include "uint256.h"
|
2011-05-27 19:48:42 +02:00
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
|
2011-06-26 19:23:24 +02:00
|
|
|
class CWallet;
|
2011-06-28 21:41:56 +02:00
|
|
|
class CWalletTx;
|
2011-06-26 19:23:24 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** UI model for transaction status. The transaction status is the part of a transaction that will change over time.
|
|
|
|
*/
|
2011-05-27 19:48:42 +02:00
|
|
|
class TransactionStatus
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TransactionStatus():
|
|
|
|
confirmed(false), sortKey(""), maturity(Mature),
|
2011-06-04 21:41:31 +02:00
|
|
|
matures_in(0), status(Offline), depth(0), open_for(0), cur_num_blocks(-1)
|
2011-05-27 19:48:42 +02:00
|
|
|
{ }
|
|
|
|
|
|
|
|
enum Maturity
|
|
|
|
{
|
|
|
|
Immature,
|
|
|
|
Mature,
|
2011-11-13 13:19:52 +01:00
|
|
|
MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
|
2011-05-27 19:48:42 +02:00
|
|
|
NotAccepted
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Status {
|
|
|
|
OpenUntilDate,
|
|
|
|
OpenUntilBlock,
|
|
|
|
Offline,
|
|
|
|
Unconfirmed,
|
|
|
|
HaveConfirmations
|
|
|
|
};
|
|
|
|
|
|
|
|
bool confirmed;
|
|
|
|
std::string sortKey;
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** @name Generated (mined) transactions
|
|
|
|
@{*/
|
2011-05-27 19:48:42 +02:00
|
|
|
Maturity maturity;
|
|
|
|
int matures_in;
|
2011-11-13 13:19:52 +01:00
|
|
|
/**@}*/
|
2011-05-27 19:48:42 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** @name Reported status
|
|
|
|
@{*/
|
2011-05-27 19:48:42 +02:00
|
|
|
Status status;
|
2011-12-21 22:33:19 +01:00
|
|
|
int64 depth;
|
|
|
|
int64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number of blocks */
|
2011-11-13 13:19:52 +01:00
|
|
|
/**@}*/
|
2011-06-04 21:41:31 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Current number of blocks (to know whether cached status is still valid) */
|
2011-06-04 21:41:31 +02:00
|
|
|
int cur_num_blocks;
|
2011-05-27 19:48:42 +02:00
|
|
|
};
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** UI model for a transaction. A core transaction can be represented by multiple UI transactions if it has
|
|
|
|
multiple outputs.
|
|
|
|
*/
|
2011-05-27 19:48:42 +02:00
|
|
|
class TransactionRecord
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
Other,
|
|
|
|
Generated,
|
|
|
|
SendToAddress,
|
|
|
|
SendToIP,
|
2011-05-28 22:31:27 +02:00
|
|
|
RecvWithAddress,
|
2011-05-27 19:48:42 +02:00
|
|
|
RecvFromIP,
|
|
|
|
SendToSelf
|
|
|
|
};
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Number of confirmation needed for transaction */
|
2011-06-20 21:31:06 +02:00
|
|
|
static const int NumConfirmations = 6;
|
|
|
|
|
2011-05-27 19:48:42 +02:00
|
|
|
TransactionRecord():
|
2011-06-04 21:41:31 +02:00
|
|
|
hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
|
2011-05-27 19:48:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-21 22:33:19 +01:00
|
|
|
TransactionRecord(uint256 hash, int64 time):
|
2011-05-27 19:48:42 +02:00
|
|
|
hash(hash), time(time), type(Other), address(""), debit(0),
|
2011-06-04 21:41:31 +02:00
|
|
|
credit(0), idx(0)
|
2011-05-27 19:48:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-12-21 22:33:19 +01:00
|
|
|
TransactionRecord(uint256 hash, int64 time,
|
2011-05-27 19:48:42 +02:00
|
|
|
Type type, const std::string &address,
|
2011-12-21 22:33:19 +01:00
|
|
|
int64 debit, int64 credit):
|
2011-05-27 19:48:42 +02:00
|
|
|
hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
|
2011-06-04 21:41:31 +02:00
|
|
|
idx(0)
|
2011-05-27 19:48:42 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Decompose CWallet transaction to model transaction records.
|
2011-05-28 20:32:19 +02:00
|
|
|
*/
|
2011-05-27 19:48:42 +02:00
|
|
|
static bool showTransaction(const CWalletTx &wtx);
|
2011-06-26 19:23:24 +02:00
|
|
|
static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
|
2011-05-27 19:48:42 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** @name Immutable transaction attributes
|
|
|
|
@{*/
|
2011-05-27 19:48:42 +02:00
|
|
|
uint256 hash;
|
2011-12-21 22:33:19 +01:00
|
|
|
int64 time;
|
2011-05-27 19:48:42 +02:00
|
|
|
Type type;
|
|
|
|
std::string address;
|
2011-12-21 22:33:19 +01:00
|
|
|
int64 debit;
|
|
|
|
int64 credit;
|
2011-11-13 13:19:52 +01:00
|
|
|
/**@}*/
|
2011-05-27 19:48:42 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Subtransaction index, for sort key */
|
2011-06-04 21:41:31 +02:00
|
|
|
int idx;
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Status: can change with block chain update */
|
2011-05-27 19:48:42 +02:00
|
|
|
TransactionStatus status;
|
2011-06-04 21:41:31 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Return the unique identifier for this transaction (part) */
|
2011-07-07 14:27:16 +02:00
|
|
|
std::string getTxID();
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Update status from core wallet tx.
|
2011-06-04 21:41:31 +02:00
|
|
|
*/
|
|
|
|
void updateStatus(const CWalletTx &wtx);
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Return whether a status update is needed.
|
2011-06-04 21:41:31 +02:00
|
|
|
*/
|
|
|
|
bool statusUpdateNeeded();
|
2011-05-27 19:48:42 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // TRANSACTIONRECORD_H
|