29 #include <QLatin1Char>
30 #include <QLatin1String>
36 Qt::AlignLeft|Qt::AlignVCenter,
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),
117 for (
const auto& wtx :
wallet.getWalletTxs()) {
134 qDebug() <<
"TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.
ToString()) +
" " + QString::number(status);
137 QList<TransactionRecord>::iterator lower = std::lower_bound(
139 QList<TransactionRecord>::iterator upper = std::upper_bound(
143 bool inModel = (lower != upper);
147 if(showTransaction && !inModel)
149 if(!showTransaction && inModel)
153 qDebug() <<
" inModel=" + QString::number(inModel) +
154 " Index=" + QString::number(lowerIndex) +
"-" + QString::number(upperIndex) +
155 " showTransaction=" + QString::number(showTransaction) +
" derivedStatus=" + QString::number(status);
162 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
171 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
175 QList<TransactionRecord> toInsert =
177 if(!toInsert.isEmpty())
179 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
180 int insert_idx = lowerIndex;
193 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_DELETED, but transaction is not in model";
197 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
204 for (
int i = lowerIndex; i < upperIndex; i++) {
229 rec->
updateStatus(wtx, cur_block_hash, numBlocks, block_time);
246 return QString::fromStdString(strHex);
253 QAbstractTableModel(parent),
256 platformStyle(_platformStyle)
282 updated.
SetHex(hash.toStdString());
299 if (parent.isValid()) {
307 if (parent.isValid()) {
320 status = tr(
"Unconfirmed");
323 status = tr(
"Abandoned");
329 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
332 status = tr(
"Conflicted");
338 status = tr(
"Generated but not accepted");
363 description += label;
365 if(label.isEmpty() || tooltip)
367 description += QString(
" (") + QString::fromStdString(address) + QString(
")");
377 return tr(
"Received with");
379 return tr(
"Received from");
382 return tr(
"Sent to");
384 return tr(
"Payment to yourself");
397 return QIcon(
":/icons/tx_mined");
400 return QIcon(
":/icons/tx_input");
403 return QIcon(
":/icons/tx_output");
405 return QIcon(
":/icons/tx_inout");
411 QString watchAddress;
414 watchAddress = QLatin1String(
" (") + tr(
"watch-only") + QLatin1Char(
')');
420 return QString::fromStdString(wtx->
address) + watchAddress;
426 return QString::fromStdString(wtx->
address) + watchAddress;
430 return tr(
"(n/a)") + watchAddress;
462 str = QString(
"[") + str + QString(
"]");
473 return QIcon(
":/icons/transaction_0");
475 return QIcon(
":/icons/transaction_abandoned");
479 case 1:
return QIcon(
":/icons/transaction_1");
480 case 2:
return QIcon(
":/icons/transaction_2");
481 case 3:
return QIcon(
":/icons/transaction_3");
482 case 4:
return QIcon(
":/icons/transaction_4");
483 default:
return QIcon(
":/icons/transaction_5");
486 return QIcon(
":/icons/transaction_confirmed");
488 return QIcon(
":/icons/transaction_conflicted");
492 return QIcon(QString(
":/icons/transaction_%1").arg(part));
495 return QIcon(
":/icons/transaction_0");
504 return QIcon(
":/icons/eye");
534 case Date:
return {};
535 case Type:
return {};
541 case Qt::DecorationRole:
546 case Qt::DisplayRole:
577 case Qt::ToolTipRole:
579 case Qt::TextAlignmentRole:
581 case Qt::ForegroundRole:
604 return QDateTime::fromSecsSinceEpoch(rec->
time);
612 return QString::fromStdString(rec->
address);
624 QDateTime date = QDateTime::fromSecsSinceEpoch(rec->
time);
627 details.append(date.toString(
"M/d/yy HH:mm"));
630 details.append(
". ");
636 if(txLabel.isEmpty())
637 details.append(tr(
"(no label)") +
" ");
640 details.append(txLabel);
641 details.append(
") ");
643 details.append(QString::fromStdString(rec->
address));
650 return rec->
status.
status == TransactionStatus::Status::Confirming || rec->
status.
status == TransactionStatus::Status::Confirmed;
662 if(orientation == Qt::Horizontal)
664 if(role == Qt::DisplayRole)
668 else if (role == Qt::TextAlignmentRole)
671 }
else if (role == Qt::ToolTipRole)
676 return tr(
"Transaction status. Hover over this field to show number of confirmations.");
678 return tr(
"Date and time that the transaction was received.");
680 return tr(
"Type of transaction.");
682 return tr(
"Whether or not a watch-only address is involved in this transaction.");
684 return tr(
"User-defined intent/purpose of the transaction.");
686 return tr(
"Amount removed from or added to balance.");
699 return createIndex(row, column,
data);
701 return QModelIndex();
732 bool invoked = QMetaObject::invokeMethod(
parent,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
true));
738 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.
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
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.
@ WatchonlyDecorationRole
Watch-only icon.
@ WatchonlyRole
Watch-only boolean.
@ 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
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const
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)
TransactionRecord * index(interfaces::Wallet &wallet, const uint256 &cur_block_hash, const int idx)
TransactionTablePriv(TransactionTableModel *_parent)
TransactionTableModel * parent
void DispatchNotifications()
QList< TransactionRecord > cachedWallet
void refreshWallet(interfaces::Wallet &wallet)
bool m_loading
True when transactions are being notified, for instance when scanning.
void NotifyTransactionChanged(const uint256 &hash, ChangeType status)
void updateWallet(interfaces::Wallet &wallet, const uint256 &hash, int status, bool showTransaction)
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.
AddressTableModel * getAddressTableModel() const
interfaces::Wallet & wallet() const
OptionsModel * getOptionsModel() const
uint256 getLastBlockProcessed() const
interfaces::Node & node() const
void SetHex(const char *psz)
std::string ToString() const
std::string GetHex() 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 EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
#define COLOR_TX_STATUS_DANGER
#define COLOR_UNCONFIRMED
#define COLOR_BAREADDRESS
QString dateTimeStr(const QDateTime &date)
TransactionNotification()=default
void invoke(QObject *ttm)
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction)
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 TransactionRecord &a, const uint256 &b) const
bool operator()(const uint256 &a, const TransactionRecord &b) const
Updated transaction status.
static int column_alignments[]
ChangeType
General change type (added, updated, removed).