lbrycrd/src/qt/transactionrecord.h

152 lines
4.5 KiB
C
Raw Normal View History

// Copyright (c) 2011-2013 The Bitcoin developers
// Distributed under the MIT/X11 software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#ifndef TRANSACTIONRECORD_H
#define TRANSACTIONRECORD_H
#include "uint256.h"
#include <QList>
#include <QString>
class CWallet;
class CWalletTx;
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.
*/
class TransactionStatus
{
public:
TransactionStatus():
countsForBalance(false), sortKey(""),
matures_in(0), status(Offline), hasConflicting(false), depth(0), open_for(0), cur_num_blocks(-1),
cur_num_conflicts(-1)
{ }
enum Status {
Confirmed, /**< Have 6 or more confirmations (normal tx) or fully mature (mined tx) **/
/// Normal (sent/received) transactions
OpenUntilDate, /**< Transaction not yet final, waiting for date */
OpenUntilBlock, /**< Transaction not yet final, waiting for block */
Offline, /**< Not sent to any other nodes **/
Unconfirmed, /**< Not yet mined into a block **/
Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
Conflicted, /**< Conflicts with other transaction or mempool **/
/// Generated (mined) transactions
Immature, /**< Mined but waiting for maturity */
MaturesWarning, /**< Transaction will likely not mature because no nodes have confirmed */
NotAccepted /**< Mined but not accepted */
};
/// Transaction counts towards available balance
bool countsForBalance;
/// Sorting key based on status
std::string sortKey;
2011-11-13 13:19:52 +01:00
/** @name Generated (mined) transactions
@{*/
int matures_in;
2011-11-13 13:19:52 +01:00
/**@}*/
2011-11-13 13:19:52 +01:00
/** @name Reported status
@{*/
Status status;
// Has conflicting transactions spending same prevout
bool hasConflicting;
qint64 depth;
qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
of additional blocks that need to be mined before
finalization */
2011-11-13 13:19:52 +01:00
/**@}*/
2011-11-13 13:19:52 +01:00
/** Current number of blocks (to know whether cached status is still valid) */
int cur_num_blocks;
/** Number of conflicts received into wallet as of last status update */
int64_t cur_num_conflicts;
};
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.
*/
class TransactionRecord
{
public:
enum Type
{
Other,
Generated,
SendToAddress,
SendToOther,
RecvWithAddress,
RecvFromOther,
SendToSelf
};
/** Number of confirmation recommended for accepting a transaction */
static const int RecommendedNumConfirmations = 6;
TransactionRecord():
hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0)
{
}
TransactionRecord(uint256 hash, qint64 time):
hash(hash), time(time), type(Other), address(""), debit(0),
credit(0), idx(0)
{
}
TransactionRecord(uint256 hash, qint64 time,
Type type, const std::string &address,
qint64 debit, qint64 credit):
hash(hash), time(time), type(type), address(address), debit(debit), credit(credit),
idx(0)
{
}
2011-11-13 13:19:52 +01:00
/** Decompose CWallet transaction to model transaction records.
2011-05-28 20:32:19 +02:00
*/
static bool showTransaction(const CWalletTx &wtx);
static QList<TransactionRecord> decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx);
2011-11-13 13:19:52 +01:00
/** @name Immutable transaction attributes
@{*/
uint256 hash;
qint64 time;
Type type;
std::string address;
qint64 debit;
qint64 credit;
2011-11-13 13:19:52 +01:00
/**@}*/
2011-11-13 13:19:52 +01:00
/** Subtransaction index, for sort key */
int idx;
2011-11-13 13:19:52 +01:00
/** Status: can change with block chain update */
TransactionStatus status;
/** Whether the transaction was sent/received with a watch-only address */
bool involvesWatchAddress;
2011-11-13 13:19:52 +01:00
/** Return the unique identifier for this transaction (part) */
QString getTxID() const;
/** Format subtransaction id */
static QString formatSubTxId(const uint256 &hash, int vout);
2011-11-13 13:19:52 +01:00
/** Update status from core wallet tx.
*/
void updateStatus(const CWalletTx &wtx);
2011-11-13 13:19:52 +01:00
/** Return whether a status update is needed.
*/
bool statusUpdateNeeded(int64_t nConflictsReceived);
};
#endif // TRANSACTIONRECORD_H