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
|
2013-11-04 16:20:43 +01:00
|
|
|
// 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
|
2011-05-27 19:48:42 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <amount.h>
|
|
|
|
#include <uint256.h>
|
2011-05-27 19:48:42 +02:00
|
|
|
|
|
|
|
#include <QList>
|
2013-09-05 12:23:08 +02:00
|
|
|
#include <QString>
|
2011-05-27 19:48:42 +02:00
|
|
|
|
2018-04-07 09:42:02 +02:00
|
|
|
namespace interfaces {
|
2017-04-18 22:42:30 +02:00
|
|
|
class Node;
|
|
|
|
class Wallet;
|
|
|
|
struct WalletTx;
|
|
|
|
struct WalletTxStatus;
|
|
|
|
}
|
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():
|
2014-07-17 14:08:07 +02:00
|
|
|
countsForBalance(false), sortKey(""),
|
2018-07-10 02:06:39 +02:00
|
|
|
matures_in(0), status(Unconfirmed), depth(0), open_for(0), cur_num_blocks(-1)
|
2014-07-17 14:08:07 +02:00
|
|
|
{ }
|
2011-05-27 19:48:42 +02:00
|
|
|
|
|
|
|
enum Status {
|
2014-02-20 14:09:09 +01:00
|
|
|
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 **/
|
2016-03-17 17:54:54 +01:00
|
|
|
Abandoned, /**< Abandoned from the wallet **/
|
2014-02-20 14:09:09 +01:00
|
|
|
/// Generated (mined) transactions
|
|
|
|
Immature, /**< Mined but waiting for maturity */
|
|
|
|
NotAccepted /**< Mined but not accepted */
|
2011-05-27 19:48:42 +02:00
|
|
|
};
|
|
|
|
|
2014-02-20 14:09:09 +01:00
|
|
|
/// Transaction counts towards available balance
|
|
|
|
bool countsForBalance;
|
|
|
|
/// Sorting key based on status
|
2011-05-27 19:48:42 +02:00
|
|
|
std::string sortKey;
|
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** @name Generated (mined) transactions
|
|
|
|
@{*/
|
2011-05-27 19:48:42 +02:00
|
|
|
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;
|
2013-04-13 07:13:08 +02:00
|
|
|
qint64 depth;
|
|
|
|
qint64 open_for; /**< Timestamp if status==OpenUntilDate, otherwise number
|
2013-01-09 09:14:48 +01:00
|
|
|
of additional blocks that need to be mined before
|
|
|
|
finalization */
|
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;
|
2017-05-24 17:09:01 +02:00
|
|
|
|
|
|
|
bool needsUpdate;
|
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,
|
2011-12-28 11:14:05 +01:00
|
|
|
SendToOther,
|
2011-05-28 22:31:27 +02:00
|
|
|
RecvWithAddress,
|
2011-12-28 11:14:05 +01:00
|
|
|
RecvFromOther,
|
2011-05-27 19:48:42 +02:00
|
|
|
SendToSelf
|
|
|
|
};
|
|
|
|
|
2014-02-20 14:09:09 +01:00
|
|
|
/** Number of confirmation recommended for accepting a transaction */
|
|
|
|
static const int RecommendedNumConfirmations = 6;
|
2011-06-20 21:31:06 +02:00
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-09-09 13:43:29 +02:00
|
|
|
TransactionRecord(uint256 _hash, qint64 _time):
|
|
|
|
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
|
|
|
{
|
|
|
|
}
|
|
|
|
|
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),
|
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
|
|
|
*/
|
2017-04-18 22:42:30 +02:00
|
|
|
static bool showTransaction();
|
2018-04-07 09:42:02 +02:00
|
|
|
static QList<TransactionRecord> decomposeTransaction(const interfaces::WalletTx& 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;
|
2013-04-13 07:13:08 +02:00
|
|
|
qint64 time;
|
2011-05-27 19:48:42 +02:00
|
|
|
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-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
|
|
|
|
2014-04-05 21:36:48 +02:00
|
|
|
/** 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) */
|
2018-03-06 21:22:50 +01:00
|
|
|
QString getTxHash() const;
|
2013-09-05 12:23:08 +02:00
|
|
|
|
2016-03-29 11:17:47 +02:00
|
|
|
/** Return the output index of the subtransaction */
|
|
|
|
int getOutputIndex() const;
|
2011-07-07 14:27:16 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Update status from core wallet tx.
|
2011-06-04 21:41:31 +02:00
|
|
|
*/
|
2018-10-23 16:36:46 +02:00
|
|
|
void updateStatus(const interfaces::WalletTxStatus& wtx, int numBlocks);
|
2011-06-04 21:41:31 +02:00
|
|
|
|
2011-11-13 13:19:52 +01:00
|
|
|
/** Return whether a status update is needed.
|
2011-06-04 21:41:31 +02:00
|
|
|
*/
|
2017-04-18 22:42:30 +02:00
|
|
|
bool statusUpdateNeeded(int numBlocks) const;
|
2011-05-27 19:48:42 +02:00
|
|
|
};
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_QT_TRANSACTIONRECORD_H
|