31 Qt::AlignLeft | Qt::AlignVCenter,
32 Qt::AlignLeft | Qt::AlignVCenter,
33 Qt::AlignLeft | Qt::AlignVCenter,
34 Qt::AlignLeft | Qt::AlignVCenter,
35 Qt::AlignLeft | Qt::AlignVCenter,
36 Qt::AlignRight | Qt::AlignVCenter
58 bool _showTransaction)
62 QString strHash = QString::fromStdString(
txid.
GetHex());
63 qDebug() <<
"NotifyTransactionChanged: " + strHash +
64 " status= " + QString::number(
status);
65 bool invoked = QMetaObject::invokeMethod(
66 ttm,
"updateTransaction", Qt::QueuedConnection,
67 Q_ARG(QString, strHash), Q_ARG(
int,
status),
96 void ShowProgress(
const std::string &title,
int nProgress);
102 qDebug() <<
"TransactionTablePriv::refreshWallet";
104 for (
const auto &wtx :
wallet.getWalletTxs()) {
118 bool showTransaction) {
119 qDebug() <<
"TransactionTablePriv::updateWallet: " +
120 QString::fromStdString(txid.
ToString()) +
" " +
121 QString::number(status);
124 QList<TransactionRecord>::iterator lower = std::lower_bound(
126 QList<TransactionRecord>::iterator upper = std::upper_bound(
130 bool inModel = (lower != upper);
134 if (showTransaction && !inModel) {
138 if (!showTransaction && inModel) {
143 qDebug() <<
" inModel=" + QString::number(inModel) +
144 " Index=" + QString::number(lowerIndex) +
"-" +
145 QString::number(upperIndex) +
146 " showTransaction=" + QString::number(showTransaction) +
147 " derivedStatus=" + QString::number(status);
152 qWarning() <<
"TransactionTablePriv::updateWallet: "
153 "Warning: Got CT_NEW, but transaction is "
157 if (showTransaction) {
161 qWarning() <<
"TransactionTablePriv::updateWallet: "
162 "Warning: Got CT_NEW, but transaction is "
167 QList<TransactionRecord> toInsert =
170 if (!toInsert.isEmpty()) {
171 parent->beginInsertRows(QModelIndex(), lowerIndex,
172 lowerIndex + toInsert.size() -
174 int insert_idx = lowerIndex;
185 qWarning() <<
"TransactionTablePriv::updateWallet: "
186 "Warning: Got CT_DELETED, but transaction is "
191 parent->beginRemoveRows(QModelIndex(), lowerIndex,
207 const BlockHash &cur_block_hash,
const int idx) {
217 if (!cur_block_hash.
IsNull() &&
219 wallet.tryGetTxStatus(rec->
txid, wtx, numBlocks, block_time)) {
220 rec->
updateStatus(wtx, cur_block_hash, numBlocks, block_time);
236 return QString::fromStdString(strHex);
244 : QAbstractTableModel(parent), walletModel(parent),
246 fProcessingQueuedTransactions(false), platformStyle(_platformStyle) {
247 columns << QString() << QString() << tr(
"Date") << tr(
"Type") << tr(
"Label")
268 Q_EMIT headerDataChanged(Qt::Horizontal,
Amount,
Amount);
272 bool showTransaction) {
274 updated.
SetHex(hash.toStdString());
304 status = tr(
"Unconfirmed");
307 status = tr(
"Abandoned");
310 status = tr(
"Confirming (%1 of %2 recommended confirmations)")
315 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
318 status = tr(
"Conflicted");
322 tr(
"Immature (%1 confirmations, will be available after %2)")
327 status = tr(
"Generated but not accepted");
347 bool tooltip)
const {
349 QString::fromStdString(address));
351 if (!label.isEmpty()) {
352 description += label;
354 if (label.isEmpty() || tooltip) {
356 QString(
" (") + QString::fromStdString(address) + QString(
")");
365 return tr(
"Received with");
367 return tr(
"Received from");
370 return tr(
"Sent to");
372 return tr(
"Payment to yourself");
384 return QIcon(
":/icons/tx_mined");
387 return QIcon(
":/icons/tx_input");
390 return QIcon(
":/icons/tx_output");
392 return QIcon(
":/icons/tx_inout");
397 bool tooltip)
const {
398 QString watchAddress;
403 ? QString(
" (") + tr(
"watch-only") + QString(
")")
409 return QString::fromStdString(wtx->
address) + watchAddress;
415 return QString::fromStdString(wtx->
address) + watchAddress;
419 return tr(
"(n/a)") + watchAddress;
432 QString::fromStdString(wtx->
address));
433 if (label.isEmpty()) {
451 if (showUnconfirmed) {
453 str = QString(
"[") + str + QString(
"]");
463 return QIcon(
":/icons/transaction_0");
465 return QIcon(
":/icons/transaction_abandoned");
469 return QIcon(
":/icons/transaction_1");
471 return QIcon(
":/icons/transaction_2");
473 return QIcon(
":/icons/transaction_3");
475 return QIcon(
":/icons/transaction_4");
477 return QIcon(
":/icons/transaction_5");
480 return QIcon(
":/icons/transaction_confirmed");
482 return QIcon(
":/icons/transaction_conflicted");
486 return QIcon(QString(
":/icons/transaction_%1").arg(part));
489 return QIcon(
":/icons/transaction_0");
498 return QIcon(
":/icons/eye");
517 if (!
index.isValid()) {
526 switch (
index.column()) {
535 case Qt::DecorationRole: {
539 case Qt::DisplayRole:
540 switch (
index.column()) {
554 switch (
index.column()) {
569 case Qt::ToolTipRole:
571 case Qt::TextAlignmentRole:
573 case Qt::ForegroundRole:
594 return QDateTime::fromTime_t(
static_cast<uint
>(rec->
time));
604 return QString::fromStdString(rec->
address);
607 QString::fromStdString(rec->
address));
619 QDateTime::fromTime_t(
static_cast<uint
>(rec->
time));
622 QString::fromStdString(rec->
address));
624 details.append(date.toString(
"M/d/yy HH:mm"));
627 details.append(
". ");
633 if (txLabel.isEmpty()) {
634 details.append(tr(
"(no label)") +
" ");
637 details.append(txLabel);
638 details.append(
") ");
640 details.append(QString::fromStdString(rec->
address));
649 TransactionStatus::Status::Confirming ||
650 rec->
status.
status == TransactionStatus::Status::Confirmed;
662 Qt::Orientation orientation,
664 if (orientation == Qt::Horizontal) {
665 if (role == Qt::DisplayRole) {
667 }
else if (role == Qt::TextAlignmentRole) {
669 }
else if (role == Qt::ToolTipRole) {
672 return tr(
"Transaction status. Hover over this field to "
673 "show number of confirmations.");
676 "Date and time that the transaction was received.");
678 return tr(
"Type of transaction.");
680 return tr(
"Whether or not a watch-only address is involved "
681 "in this transaction.");
684 "User-defined intent/purpose of the transaction.");
686 return tr(
"Amount removed from or added to balance.");
694 const QModelIndex &parent)
const {
699 return createIndex(row, column,
data);
701 return QModelIndex();
728 if (nProgress == 0) {
732 if (nProgress == 100) {
736 bool invoked = QMetaObject::invokeMethod(
737 parent,
"setProcessingQueuedTransactions", Qt::QueuedConnection,
744 bool invoked = QMetaObject::invokeMethod(
745 parent,
"setProcessingQueuedTransactions",
746 Qt::QueuedConnection, Q_ARG(
bool,
false));
761 std::placeholders::_1, std::placeholders::_2));
764 std::placeholders::_1, std::placeholders::_2));
static constexpr Amount SATOSHI
QString labelForAddress(const QString &address) const
Look up label for address in address book, if not found return empty string.
static QString format(int unit, const Amount amount, bool plussign=false, SeparatorStyle separators=SeparatorStyle::STANDARD, bool justify=false)
Format as string.
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */.
int getDisplayUnit() const
void displayUnitChanged(int unit)
static QString toHTML(interfaces::Node &node, interfaces::Wallet &wallet, TransactionRecord *rec, int unit)
UI model for a transaction.
static QList< TransactionRecord > decomposeTransaction(const interfaces::WalletTx &wtx)
Decompose CWallet transaction to model transaction records.
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.
void updateStatus(const interfaces::WalletTxStatus &wtx, const BlockHash &block_hash, int numBlocks, int64_t block_time)
Update status from core wallet tx.
bool statusUpdateNeeded(const BlockHash &block_hash) const
Return whether a status update is needed.
QString getTxID() const
Return the unique identifier for this transaction (part)
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
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.
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.
@ TxIDRole
Unique identifier.
@ 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)
New transaction, or transaction changed status.
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
Look up address in address book, if found return label (address) otherwise just return (address)
QVariant txAddressDecoration(const TransactionRecord *wtx) const
QString formatTxDate(const TransactionRecord *wtx) const
QString getTxHex(interfaces::Wallet &wallet, TransactionRecord *rec)
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...
TransactionTablePriv(TransactionTableModel *_parent)
TransactionTableModel * parent
QList< TransactionRecord > cachedWallet
std::vector< TransactionNotification > vQueueNotifications
void refreshWallet(interfaces::Wallet &wallet)
Query entire wallet anew from core.
QString describe(interfaces::Node &node, interfaces::Wallet &wallet, TransactionRecord *rec, int unit)
void ShowProgress(const std::string &title, int nProgress)
void NotifyTransactionChanged(const TxId &txidc, ChangeType status)
TransactionRecord * index(interfaces::Wallet &wallet, const BlockHash &cur_block_hash, const int idx)
Interface to Bitcoin wallet from Qt view code.
interfaces::Node & node() const
BlockHash getLastBlockProcessed() const
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
interfaces::Wallet & wallet() 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)
static constexpr Amount zero() noexcept
A BlockHash is a unqiue identifier for a block.
TransactionNotification(TxId _txid, ChangeType _status, bool _showTransaction)
void invoke(QObject *ttm)
TransactionNotification()
A TxId is the identifier of a transaction.
bool operator()(const TransactionRecord &a, const TxId &b) const
bool operator()(const TransactionRecord &a, const TransactionRecord &b) const
bool operator()(const TxId &a, const TransactionRecord &b) const
Updated transaction status.
static int column_alignments[]
ChangeType
General change type (added, updated, removed).