31#include <QLatin1String>
37 Qt::AlignLeft|Qt::AlignVCenter,
38 Qt::AlignLeft|Qt::AlignVCenter,
39 Qt::AlignLeft|Qt::AlignVCenter,
40 Qt::AlignLeft|Qt::AlignVCenter,
41 Qt::AlignRight|Qt::AlignVCenter
71 QString strHash = QString::fromStdString(
hash.
GetHex());
72 qDebug() <<
"NotifyTransactionChanged: " + strHash +
" status= " + QString::number(
status);
73 bool invoked = QMetaObject::invokeMethod(ttm,
"updateTransaction", Qt::QueuedConnection,
74 Q_ARG(QString, strHash),
114 for (
const auto& wtx :
wallet.getWalletTxs()) {
131 qDebug() <<
"TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.
ToString()) +
" " + QString::number(status);
134 QList<TransactionRecord>::iterator lower = std::lower_bound(
136 QList<TransactionRecord>::iterator upper = std::upper_bound(
140 bool inModel = (lower != upper);
144 if(showTransaction && !inModel)
146 if(!showTransaction && inModel)
150 qDebug() <<
" inModel=" + QString::number(inModel) +
151 " Index=" + QString::number(lowerIndex) +
"-" + QString::number(upperIndex) +
152 " showTransaction=" + QString::number(showTransaction) +
" derivedStatus=" + QString::number(status);
159 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
168 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
172 QList<TransactionRecord> toInsert =
174 if(!toInsert.isEmpty())
176 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
177 int insert_idx = lowerIndex;
190 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_DELETED, but transaction is not in model";
194 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
201 for (
int i = lowerIndex; i < upperIndex; i++) {
226 rec->
updateStatus(wtx, cur_block_hash, numBlocks, block_time);
243 return QString::fromStdString(strHex);
250 QAbstractTableModel(parent),
253 platformStyle(_platformStyle)
295 if (parent.isValid()) {
303 if (parent.isValid()) {
316 status = tr(
"Unconfirmed");
319 status = tr(
"Abandoned");
325 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
328 status = tr(
"Conflicted");
334 status = tr(
"Generated but not accepted");
359 description += label;
361 if(label.isEmpty() || tooltip)
363 description += QString(
" (") + QString::fromStdString(address) + QString(
")");
373 return tr(
"Received with");
375 return tr(
"Received from");
378 return tr(
"Sent to");
391 return QIcon(
":/icons/tx_mined");
394 return QIcon(
":/icons/tx_input");
397 return QIcon(
":/icons/tx_output");
399 return QIcon(
":/icons/tx_inout");
408 return QString::fromStdString(wtx->
address);
414 return QString::fromStdString(wtx->
address);
446 str = QString(
"[") + str + QString(
"]");
457 return QIcon(
":/icons/transaction_0");
459 return QIcon(
":/icons/transaction_abandoned");
463 case 1:
return QIcon(
":/icons/transaction_1");
464 case 2:
return QIcon(
":/icons/transaction_2");
465 case 3:
return QIcon(
":/icons/transaction_3");
466 case 4:
return QIcon(
":/icons/transaction_4");
467 default:
return QIcon(
":/icons/transaction_5");
470 return QIcon(
":/icons/transaction_confirmed");
472 return QIcon(
":/icons/transaction_conflicted");
476 return QIcon(QString(
":/icons/transaction_%1").arg(part));
479 return QIcon(
":/icons/transaction_0");
508 case Date:
return {};
509 case Type:
return {};
515 case Qt::DecorationRole:
520 case Qt::DisplayRole:
548 case Qt::ToolTipRole:
550 case Qt::TextAlignmentRole:
552 case Qt::ForegroundRole:
575 return QDateTime::fromSecsSinceEpoch(rec->
time);
579 return QString::fromStdString(rec->
address);
591 QDateTime date = QDateTime::fromSecsSinceEpoch(rec->
time);
594 details.append(date.toString(
"M/d/yy HH:mm"));
597 details.append(
". ");
603 if(txLabel.isEmpty())
604 details.append(tr(
"(no label)") +
" ");
607 details.append(txLabel);
608 details.append(
") ");
610 details.append(QString::fromStdString(rec->
address));
617 return rec->
status.
status == TransactionStatus::Status::Confirming || rec->
status.
status == TransactionStatus::Status::Confirmed;
629 if(orientation == Qt::Horizontal)
631 if(role == Qt::DisplayRole)
635 else if (role == Qt::TextAlignmentRole)
638 }
else if (role == Qt::ToolTipRole)
643 return tr(
"Transaction status. Hover over this field to show number of confirmations.");
645 return tr(
"Date and time that the transaction was received.");
647 return tr(
"Type of transaction.");
649 return tr(
"User-defined intent/purpose of the transaction.");
651 return tr(
"Amount removed from or added to balance.");
664 return createIndex(row, column,
data);
666 return QModelIndex();
697 bool invoked = QMetaObject::invokeMethod(
parent,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
true));
703 bool invoked = QMetaObject::invokeMethod(
parent,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
false));
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
static QString format(Unit unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static QString getAmountColumnTitle(Unit unit)
Gets title for amount column including current display unit if optionsModel reference available */.
void displayUnitChanged(BitcoinUnit unit)
BitcoinUnit getDisplayUnit() const
static QString toHTML(interfaces::Node &node, interfaces::Wallet &wallet, TransactionRecord *rec, BitcoinUnit unit)
UI model for a transaction.
static QList< TransactionRecord > decomposeTransaction(const interfaces::WalletTx &wtx)
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a transaction.
static bool showTransaction()
Decompose CWallet transaction to model transaction records.
TransactionStatus status
Status: can change with block chain update.
QString getTxHash() const
Return the unique identifier for this transaction (part)
bool statusUpdateNeeded(const uint256 &block_hash) const
Return whether a status update is needed.
void updateStatus(const interfaces::WalletTxStatus &wtx, const uint256 &block_hash, int numBlocks, int64_t block_time)
Update status from core wallet tx.
UI model for the transaction table of a wallet.
QVariant txStatusDecoration(const TransactionRecord *wtx) const
void subscribeToCoreSignals()
TransactionTablePriv * priv
void unsubscribeFromCoreSignals()
QVariant addressColor(const TransactionRecord *wtx) const
@ TxPlainTextRole
Whole transaction as plain text.
@ LabelRole
Label of address related to transaction.
@ LongDescriptionRole
Long description (HTML format)
@ TypeRole
Type of transaction.
@ StatusRole
Transaction status (TransactionRecord::Status)
@ DateRole
Date and time this transaction was created.
@ TxHashRole
Transaction hash.
@ TxHexRole
Transaction data, hex-encoded.
@ RawDecorationRole
Unprocessed icon.
@ AddressRole
Address of transaction.
@ AmountRole
Net amount of transaction.
@ ConfirmedRole
Is transaction confirmed?
@ FormattedAmountRole
Formatted amount, without brackets when unconfirmed.
QString formatTooltip(const TransactionRecord *rec) const
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::SeparatorStyle::STANDARD) const
void updateConfirmations()
QVariant data(const QModelIndex &index, int role) const override
void updateTransaction(const QString &hash, int status, bool showTransaction)
QString formatTxStatus(const TransactionRecord *wtx) const
WalletModel * walletModel
std::unique_ptr< interfaces::Handler > m_handler_transaction_changed
int columnCount(const QModelIndex &parent) const override
std::unique_ptr< interfaces::Handler > m_handler_show_progress
TransactionTableModel(const PlatformStyle *platformStyle, WalletModel *parent=nullptr)
int rowCount(const QModelIndex &parent) const override
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
QVariant headerData(int section, Qt::Orientation orientation, int role) const override
const PlatformStyle * platformStyle
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
QString formatTxType(const TransactionRecord *wtx) const
QString lookupAddress(const std::string &address, bool tooltip) const
QVariant txAddressDecoration(const TransactionRecord *wtx) const
QString formatTxDate(const TransactionRecord *wtx) const
QString getTxHex(interfaces::Wallet &wallet, TransactionRecord *rec)
TransactionTablePriv(TransactionTableModel *_parent)
TransactionTableModel * parent
void DispatchNotifications()
QList< TransactionRecord > cachedWallet
Local cache of wallet sorted by transaction hash.
void refreshWallet(interfaces::Wallet &wallet)
bool m_loading
True when transactions are being notified, for instance when scanning.
void NotifyTransactionChanged(const Txid &hash, ChangeType status)
void updateWallet(interfaces::Wallet &wallet, const Txid &hash, int status, bool showTransaction)
TransactionRecord * index(interfaces::Wallet &wallet, const uint256 &cur_block_hash, const int idx)
std::vector< TransactionNotification > vQueueNotifications
QString describe(interfaces::Node &node, interfaces::Wallet &wallet, TransactionRecord *rec, BitcoinUnit unit)
bool m_loaded
True when model finishes loading all wallet transactions on start.
Interface to Bitcoin wallet from Qt view code.
interfaces::Node & node() const
AddressTableModel * getAddressTableModel() const
interfaces::Wallet & wallet() const
OptionsModel * getOptionsModel() const
uint256 getLastBlockProcessed() const
constexpr bool IsNull() const
Top-level interface for a bitcoin node (bitcoind process).
Interface for accessing a wallet.
virtual std::unique_ptr< Handler > handleShowProgress(ShowProgressFn fn)=0
virtual std::unique_ptr< Handler > handleTransactionChanged(TransactionChangedFn fn)=0
std::string ToString() const
std::string GetHex() const
static std::optional< transaction_identifier > FromHex(std::string_view hex)
std::string EncodeHexTx(const CTransaction &tx)
#define COLOR_TX_STATUS_DANGER
#define COLOR_UNCONFIRMED
#define COLOR_BAREADDRESS
QString dateTimeStr(const QDateTime &date)
TransactionNotification()=default
TransactionNotification(Txid _hash, ChangeType _status, bool _showTransaction)
void invoke(QObject *ttm)
bool countsForBalance
Transaction counts towards available balance.
@ Confirmed
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
@ Unconfirmed
Normal (sent/received) transactions.
@ Immature
Generated (mined) transactions.
@ Confirming
Confirmed, but waiting for the recommended number of confirmations.
@ NotAccepted
Mined but not accepted.
@ Conflicted
Conflicts with other transaction or mempool.
@ Abandoned
Abandoned from the wallet.
std::string sortKey
Sorting key based on status.
bool operator()(const TransactionRecord &a, const TransactionRecord &b) const
bool operator()(const Txid &a, const TransactionRecord &b) const
bool operator()(const TransactionRecord &a, const Txid &b) const
Updated transaction status.
static int column_alignments[]
ChangeType
General change type (added, updated, removed).