30 Qt::AlignLeft | Qt::AlignVCenter,
31 Qt::AlignLeft | Qt::AlignVCenter,
32 Qt::AlignLeft | Qt::AlignVCenter,
33 Qt::AlignLeft | Qt::AlignVCenter,
34 Qt::AlignLeft | Qt::AlignVCenter,
35 Qt::AlignRight | Qt::AlignVCenter
70 qDebug() <<
"TransactionTablePriv::refreshWallet";
86 bool showTransaction) {
87 qDebug() <<
"TransactionTablePriv::updateWallet: " +
88 QString::fromStdString(txid.
ToString()) +
" " +
89 QString::number(status);
92 QList<TransactionRecord>::iterator lower = std::lower_bound(
93 cachedWallet.begin(), cachedWallet.end(), txid,
TxLessThan());
94 QList<TransactionRecord>::iterator upper = std::upper_bound(
95 cachedWallet.begin(), cachedWallet.end(), txid,
TxLessThan());
96 int lowerIndex = (lower - cachedWallet.begin());
97 int upperIndex = (upper - cachedWallet.begin());
98 bool inModel = (lower != upper);
102 if (showTransaction && !inModel) {
106 if (!showTransaction && inModel) {
111 qDebug() <<
" inModel=" + QString::number(inModel) +
112 " Index=" + QString::number(lowerIndex) +
"-" +
113 QString::number(upperIndex) +
114 " showTransaction=" + QString::number(showTransaction) +
115 " derivedStatus=" + QString::number(status);
120 qWarning() <<
"TransactionTablePriv::updateWallet: " 121 "Warning: Got CT_NEW, but transaction is " 125 if (showTransaction) {
129 qWarning() <<
"TransactionTablePriv::updateWallet: " 130 "Warning: Got CT_NEW, but transaction is " 135 QList<TransactionRecord> toInsert =
138 if (!toInsert.isEmpty()) {
139 parent->beginInsertRows(QModelIndex(), lowerIndex,
140 lowerIndex + toInsert.size() -
142 int insert_idx = lowerIndex;
144 cachedWallet.insert(insert_idx, rec);
147 parent->endInsertRows();
153 qWarning() <<
"TransactionTablePriv::updateWallet: " 154 "Warning: Got CT_DELETED, but transaction is " 159 parent->beginRemoveRows(QModelIndex(), lowerIndex,
161 cachedWallet.erase(lower, upper);
162 parent->endRemoveRows();
172 int size() {
return cachedWallet.size(); }
175 const int cur_num_blocks,
const int idx) {
176 if (idx >= 0 && idx < cachedWallet.size()) {
207 return QString::fromStdString(strHex);
215 : QAbstractTableModel(parent), walletModel(parent),
217 fProcessingQueuedTransactions(false), platformStyle(_platformStyle) {
218 columns << QString() << QString() << tr(
"Date") << tr(
"Type") << tr(
"Label")
239 Q_EMIT headerDataChanged(Qt::Horizontal,
Amount,
Amount);
243 bool showTransaction) {
245 updated.
SetHex(hash.toStdString());
275 status = tr(
"Open for %n more block(s)",
"", wtx->
status.
open_for);
278 status = tr(
"Open until %1")
282 status = tr(
"Unconfirmed");
285 status = tr(
"Abandoned");
288 status = tr(
"Confirming (%1 of %2 recommended confirmations)")
293 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
296 status = tr(
"Conflicted");
300 tr(
"Immature (%1 confirmations, will be available after %2)")
305 status = tr(
"Generated but not accepted");
325 bool tooltip)
const {
327 QString::fromStdString(address));
329 if (!label.isEmpty()) {
330 description += label;
332 if (label.isEmpty() || tooltip) {
334 QString(
" (") + QString::fromStdString(address) + QString(
")");
343 return tr(
"Received with");
345 return tr(
"Received from");
348 return tr(
"Sent to");
350 return tr(
"Payment to yourself");
362 return QIcon(
":/icons/tx_mined");
365 return QIcon(
":/icons/tx_input");
368 return QIcon(
":/icons/tx_output");
370 return QIcon(
":/icons/tx_inout");
375 bool tooltip)
const {
376 QString watchAddress;
381 ? QString(
" (") + tr(
"watch-only") + QString(
")")
387 return QString::fromStdString(wtx->
address) + watchAddress;
393 return QString::fromStdString(wtx->
address) + watchAddress;
397 return tr(
"(n/a)") + watchAddress;
410 QString::fromStdString(wtx->
address));
411 if (label.isEmpty()) {
429 if (showUnconfirmed) {
431 str = QString(
"[") + str + QString(
"]");
444 return QIcon(
":/icons/transaction_0");
446 return QIcon(
":/icons/transaction_abandoned");
450 return QIcon(
":/icons/transaction_1");
452 return QIcon(
":/icons/transaction_2");
454 return QIcon(
":/icons/transaction_3");
456 return QIcon(
":/icons/transaction_4");
458 return QIcon(
":/icons/transaction_5");
461 return QIcon(
":/icons/transaction_confirmed");
463 return QIcon(
":/icons/transaction_conflicted");
467 return QIcon(QString(
":/icons/transaction_%1").arg(part));
470 return QIcon(
":/icons/transaction_0");
479 return QIcon(
":/icons/eye");
498 if (!index.isValid()) {
507 switch (index.column()) {
516 case Qt::DecorationRole: {
520 case Qt::DisplayRole:
521 switch (index.column()) {
535 switch (index.column()) {
550 case Qt::ToolTipRole:
552 case Qt::TextAlignmentRole:
554 case Qt::ForegroundRole:
564 if (index.column() ==
Amount &&
575 return QDateTime::fromTime_t(static_cast<uint>(rec->
time));
585 return QString::fromStdString(rec->
address);
588 QString::fromStdString(rec->
address));
600 QDateTime::fromTime_t(static_cast<uint>(rec->
time));
603 QString::fromStdString(rec->
address));
605 details.append(date.toString(
"M/d/yy HH:mm"));
608 details.append(
". ");
614 if (txLabel.isEmpty()) {
615 details.append(tr(
"(no label)") +
" ");
618 details.append(txLabel);
619 details.append(
") ");
621 details.append(QString::fromStdString(rec->
address));
640 Qt::Orientation orientation,
642 if (orientation == Qt::Horizontal) {
643 if (role == Qt::DisplayRole) {
645 }
else if (role == Qt::TextAlignmentRole) {
647 }
else if (role == Qt::ToolTipRole) {
650 return tr(
"Transaction status. Hover over this field to " 651 "show number of confirmations.");
654 "Date and time that the transaction was received.");
656 return tr(
"Type of transaction.");
658 return tr(
"Whether or not a watch-only address is involved " 659 "in this transaction.");
662 "User-defined intent/purpose of the transaction.");
664 return tr(
"Amount removed from or added to balance.");
672 const QModelIndex &parent)
const {
677 return createIndex(row, column, data);
679 return QModelIndex();
693 bool _showTransaction)
694 : txid(_txid), status(_status), showTransaction(_showTransaction) {}
697 QString strHash = QString::fromStdString(txid.GetHex());
698 qDebug() <<
"NotifyTransactionChanged: " + strHash +
699 " status= " + QString::number(status);
700 bool invoked = QMetaObject::invokeMethod(
701 ttm,
"updateTransaction", Qt::QueuedConnection,
702 Q_ARG(QString, strHash), Q_ARG(
int, status),
703 Q_ARG(
bool, showTransaction));
734 if (nProgress == 0) {
738 if (nProgress == 100) {
742 bool invoked = QMetaObject::invokeMethod(
743 ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection,
750 bool invoked = QMetaObject::invokeMethod(
751 ttm,
"setProcessingQueuedTransactions",
752 Qt::QueuedConnection, Q_ARG(
bool,
false));
769 std::placeholders::_2));
772 ShowProgress,
this, std::placeholders::_1, std::placeholders::_2));
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
bool statusUpdateNeeded(int numBlocks) const
Return whether a status update is needed.
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
Confirmed, but waiting for the recommended number of confirmations.
interfaces::Wallet & wallet() const
static constexpr Amount zero()
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const
Transaction not yet final, waiting for block.
Transaction status (TransactionRecord::Status)
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::separatorStandard) const
Generated (mined) transactions.
static int column_alignments[]
QString formatTooltip(const TransactionRecord *rec) const
WalletModel * walletModel
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
std::string sortKey
Sorting key based on status.
void updateTransaction(const QString &hash, int status, bool showTransaction)
New transaction, or transaction changed status.
QString describe(interfaces::Node &node, interfaces::Wallet &wallet, TransactionRecord *rec, int unit)
QString dateTimeStr(const QDateTime &date)
TransactionTablePriv(TransactionTableModel *_parent)
static QList< TransactionRecord > decomposeTransaction(const interfaces::WalletTx &wtx)
Decompose CWallet transaction to model transaction records.
bool operator()(const TxId &a, const TransactionRecord &b) const
void unsubscribeFromCoreSignals()
static std::vector< TransactionNotification > vQueueNotifications
QVariant txStatusDecoration(const TransactionRecord *wtx) const
bool operator()(const TransactionRecord &a, const TransactionRecord &b) const
Not yet mined into a block.
static QString toHTML(interfaces::Node &node, interfaces::Wallet &wallet, TransactionRecord *rec, int unit)
static constexpr Amount SATOSHI
int columnCount(const QModelIndex &parent) const override
AddressTableModel * getAddressTableModel()
Transaction data, hex-encoded.
TransactionTableModel * parent
int rowCount(const QModelIndex &parent) const override
Long description (HTML format)
TransactionTablePriv * priv
void updateWallet(interfaces::Wallet &wallet, const TxId &txid, int status, bool showTransaction)
Update our model of the wallet incrementally, to synchronize our model of the wallet with that of the...
int getDisplayUnit() const
*static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available...
QList< TransactionRecord > cachedWallet
virtual std::unique_ptr< Handler > handleTransactionChanged(TransactionChangedFn fn)=0
UI model for a transaction.
TransactionStatus status
Status: can change with block chain update.
QString formatTxType(const TransactionRecord *wtx) const
virtual std::unique_ptr< Handler > handleShowProgress(ShowProgressFn fn)=0
TransactionNotification()
Whole transaction as plain text.
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
virtual CTransactionRef getTx(const TxId &txid)=0
Get a transaction.
static void ShowProgress(TransactionTableModel *ttm, const std::string &title, int nProgress)
QString getTxID() const
Return the unique identifier for this transaction (part)
#define COLOR_TX_STATUS_DANGER
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
Interface for accessing a wallet.
Is transaction confirmed?
bool countsForBalance
Transaction counts towards available balance.
TransactionTableModel(const PlatformStyle *platformStyle, WalletModel *parent=nullptr)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
virtual bool tryGetTxStatus(const TxId &txid, WalletTxStatus &tx_status, int &num_blocks, int64_t &block_time)=0
Try to get updated status for a particular transaction, if possible without blocking.
Date and time this transaction was created.
std::string ToString() const
bool operator()(const TransactionRecord &a, const TxId &b) const
static void NotifyTransactionChanged(TransactionTableModel *ttm, const TxId &txid, ChangeType status)
interfaces::Node & node() const
void displayUnitChanged(int unit)
UI model for the transaction table of a wallet.
#define COLOR_UNCONFIRMED
virtual WalletTx getWalletTx(const TxId &txid)=0
Get transaction information.
void refreshWallet(interfaces::Wallet &wallet)
Query entire wallet anew from core.
Normal (sent/received) transactions.
static QString format(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
QString lookupAddress(const std::string &address, bool tooltip) const
Look up address in address book, if found return label (address) otherwise just return (address) ...
void subscribeToCoreSignals()
std::unique_ptr< interfaces::Handler > m_handler_show_progress
static bool showTransaction()
Decompose CWallet transaction to model transaction records.
Net amount of transaction.
TransactionNotification(TxId _txid, ChangeType _status, bool _showTransaction)
virtual std::vector< WalletTx > getWalletTxs()=0
Get list of all wallet transactions.
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
void updateStatus(const interfaces::WalletTxStatus &wtx, int numBlocks, int64_t block_time)
Update status from core wallet tx.
Conflicts with other transaction or mempool.
Interface to Bitcoin wallet from Qt view code.
A TxId is the identifier of a transaction.
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
QString getTxHex(interfaces::Wallet &wallet, TransactionRecord *rec)
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
Label of address related to transaction.
QString formatTxStatus(const TransactionRecord *wtx) const
static bool fQueueNotifications
QVariant addressColor(const TransactionRecord *wtx) const
void invoke(QObject *ttm)
#define COLOR_TX_STATUS_OPENUNTILDATE
qint64 open_for
Timestamp if status==OpenUntilDate, otherwise number of additional blocks that need to be mined befor...
QVariant txAddressDecoration(const TransactionRecord *wtx) const
TransactionRecord * index(interfaces::Wallet &wallet, const int cur_num_blocks, const int idx)
Formatted amount, without brackets when unconfirmed.
QVariant data(const QModelIndex &index, int role) const override
ChangeType
General change type (added, updated, removed).
void updateConfirmations()
void SetHex(const char *psz)
Abandoned from the wallet.
#define COLOR_BAREADDRESS
Top-level interface for a bitcoin node (bitcoind process).
const PlatformStyle * platformStyle
Updated transaction status.
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a transaction.
OptionsModel * getOptionsModel()
ClientModel & clientModel() const
QString formatTxDate(const TransactionRecord *wtx) const