lbrycrd/src/qt/transactionrecord.h

149 lines
4.3 KiB
C
Raw Normal View History

2018-07-27 00:36:45 +02:00
// Copyright (c) 2011-2018 The Bitcoin Core developers
2014-12-13 05:09:33 +01:00
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
2014-11-03 16:16:40 +01:00
#ifndef BITCOIN_QT_TRANSACTIONRECORD_H
#define BITCOIN_QT_TRANSACTIONRECORD_H
#include <amount.h>
#include <uint256.h>
#include <QList>
#include <QString>
namespace interfaces {
class Node;
class Wallet;
struct WalletTx;
struct WalletTxStatus;
}
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(Unconfirmed), depth(0), open_for(0), cur_num_blocks(-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 */
Unconfirmed, /**< Not yet mined into a block **/
Confirming, /**< Confirmed, but waiting for the recommended number of confirmations **/
Conflicted, /**< Conflicts with other transaction or mempool **/
Abandoned, /**< Abandoned from the wallet **/
/// Generated (mined) transactions
Immature, /**< Mined but waiting for maturity */
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;
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;
bool needsUpdate;
};
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)
{
}
2016-09-09 13:43:29 +02:00
TransactionRecord(uint256 _hash, qint64 _time):
hash(_hash), time(_time), type(Other), address(""), debit(0),
credit(0), idx(0)
{
}
2016-09-09 13:43:29 +02:00
TransactionRecord(uint256 _hash, qint64 _time,
Type _type, const std::string &_address,
const CAmount& _debit, const CAmount& _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();
static QList<TransactionRecord> decomposeTransaction(const interfaces::WalletTx& wtx);
2011-11-13 13:19:52 +01:00
/** @name Immutable transaction attributes
@{*/
uint256 hash;
qint64 time;
Type type;
std::string address;
2014-04-23 00:46:19 +02:00
CAmount debit;
CAmount 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 getTxHash() const;
/** Return the output index of the subtransaction */
int getOutputIndex() const;
2011-11-13 13:19:52 +01:00
/** Update status from core wallet tx.
*/
void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks);
2011-11-13 13:19:52 +01:00
/** Return whether a status update is needed.
*/
bool statusUpdateNeeded(int numBlocks) const;
};
2014-11-03 16:16:40 +01:00
#endif // BITCOIN_QT_TRANSACTIONRECORD_H