17 #include "validation.h"
29 #include <boost/bind/bind.hpp>
30 #include <boost/foreach.hpp>
33 static int column_alignments[] = {
34 Qt::AlignLeft|Qt::AlignVCenter,
35 Qt::AlignLeft|Qt::AlignVCenter,
36 Qt::AlignLeft|Qt::AlignVCenter,
37 Qt::AlignLeft|Qt::AlignVCenter,
38 Qt::AlignLeft|Qt::AlignVCenter,
39 Qt::AlignRight|Qt::AlignVCenter
82 qDebug() <<
"TransactionTablePriv::refreshWallet";
101 qDebug() <<
"TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.
ToString()) +
" " + QString::number(status);
104 QList<TransactionRecord>::iterator lower = qLowerBound(
106 QList<TransactionRecord>::iterator upper = qUpperBound(
110 bool inModel = (lower != upper);
114 if(showTransaction && !inModel)
116 if(!showTransaction && inModel)
120 qDebug() <<
" inModel=" + QString::number(inModel) +
121 " Index=" + QString::number(lowerIndex) +
"-" + QString::number(upperIndex) +
122 " showTransaction=" + QString::number(showTransaction) +
" derivedStatus=" + QString::number(status);
129 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
136 std::map<uint256, CWalletTx>::iterator mi =
wallet->
mapWallet.find(hash);
139 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
143 QList<TransactionRecord> toInsert =
145 if(!toInsert.isEmpty())
147 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
148 int insert_idx = lowerIndex;
161 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_DELETED, but transaction is not in model";
165 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
233 return QString::fromStdString(strHex);
240 QAbstractTableModel(parent),
244 fProcessingQueuedTransactions(false),
245 platformStyle(_platformStyle)
271 updated.
SetHex(hash.toStdString());
311 status = tr(
"Offline");
314 status = tr(
"Unconfirmed");
317 status = tr(
"Abandoned");
323 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
326 status = tr(
"Conflicted");
332 status = tr(
"This block was not received by any other nodes and will probably not be accepted!");
335 status = tr(
"Generated but not accepted");
360 description += label;
362 if(label.isEmpty() || tooltip)
364 description += QString(
" (") + QString::fromStdString(address) + QString(
")");
374 return tr(
"Received with");
376 return tr(
"Received from");
379 return tr(
"Sent to");
381 return tr(
"Payment to yourself");
394 return QIcon(
":/icons/tx_mined");
397 return QIcon(
":/icons/tx_input");
400 return QIcon(
":/icons/tx_output");
402 return QIcon(
":/icons/tx_inout");
408 QString watchAddress;
411 watchAddress = wtx->
involvesWatchAddress ? QString(
" (") + tr(
"watch-only") + QString(
")") :
"";
417 return QString::fromStdString(wtx->
address) + watchAddress;
423 return QString::fromStdString(wtx->
address) + watchAddress;
426 return tr(
"(n/a)") + watchAddress;
458 str = QString(
"[") + str + QString(
"]");
474 return QIcon(
":/icons/transaction_0");
476 return QIcon(
":/icons/transaction_abandoned");
480 case 1:
return QIcon(
":/icons/transaction_1");
481 case 2:
return QIcon(
":/icons/transaction_2");
482 case 3:
return QIcon(
":/icons/transaction_3");
483 case 4:
return QIcon(
":/icons/transaction_4");
484 default:
return QIcon(
":/icons/transaction_5");
487 return QIcon(
":/icons/transaction_confirmed");
489 return QIcon(
":/icons/transaction_conflicted");
493 return QIcon(QString(
":/icons/transaction_%1").arg(part));
497 return QIcon(
":/icons/transaction_0");
506 return QIcon(
":/icons/eye");
531 switch(
index.column())
541 case Qt::DecorationRole:
546 case Qt::DisplayRole:
547 switch(
index.column())
561 switch(
index.column())
577 case Qt::ToolTipRole:
579 case Qt::TextAlignmentRole:
580 return column_alignments[
index.column()];
581 case Qt::ForegroundRole:
604 return QDateTime::fromTime_t(
static_cast<uint
>(rec->
time));
612 return QString::fromStdString(rec->
address);
626 QDateTime date = QDateTime::fromTime_t(
static_cast<uint
>(rec->
time));
629 details.append(date.toString(
"M/d/yy HH:mm"));
632 details.append(
". ");
638 if(txLabel.isEmpty())
639 details.append(tr(
"(no label)") +
" ");
642 details.append(txLabel);
643 details.append(
") ");
645 details.append(QString::fromStdString(rec->
address));
664 if(orientation == Qt::Horizontal)
666 if(role == Qt::DisplayRole)
670 else if (role == Qt::TextAlignmentRole)
672 return column_alignments[section];
673 }
else if (role == Qt::ToolTipRole)
678 return tr(
"Transaction status. Hover over this field to show number of confirmations.");
680 return tr(
"Date and time that the transaction was received.");
682 return tr(
"Type of transaction.");
684 return tr(
"Whether or not a watch-only address is involved in this transaction.");
686 return tr(
"User-defined intent/purpose of the transaction.");
688 return tr(
"Amount removed from or added to balance.");
701 return createIndex(row, column,
priv->
index(row));
703 return QModelIndex();
723 QString strHash = QString::fromStdString(
hash.
GetHex());
724 qDebug() <<
"NotifyTransactionChanged: " + strHash +
" status= " + QString::number(
status);
725 QMetaObject::invokeMethod(ttm,
"updateTransaction", Qt::QueuedConnection,
726 Q_ARG(QString, strHash),
736 static bool fQueueNotifications =
false;
737 static std::vector< TransactionNotification > vQueueNotifications;
742 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(hash);
744 bool inWallet = mi != wallet->
mapWallet.end();
749 if (fQueueNotifications)
751 vQueueNotifications.push_back(notification);
760 fQueueNotifications =
true;
762 if (nProgress == 100)
764 fQueueNotifications =
false;
765 if (vQueueNotifications.size() > 10)
766 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
true));
767 for (
unsigned int i = 0; i < vQueueNotifications.size(); ++i)
769 if (vQueueNotifications.size() - i <= 10)
770 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
false));
772 vQueueNotifications[i].invoke(ttm);
774 std::vector<TransactionNotification >().swap(vQueueNotifications);
782 boost::placeholders::_1,
783 boost::placeholders::_2,
784 boost::placeholders::_3));
786 boost::placeholders::_1,
787 boost::placeholders::_2));
794 boost::placeholders::_1,
795 boost::placeholders::_2,
796 boost::placeholders::_3));
798 boost::placeholders::_1,
799 boost::placeholders::_2));
QString labelForAddress(const QString &address) const
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */.
The basic transaction that is broadcasted on the network and contained in blocks.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
std::map< uint256, CWalletTx > mapWallet
CCriticalSection cs_wallet
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
static QString toHTML(CWallet *wallet, CWalletTx &wtx, TransactionRecord *rec, int unit)
UI model for a transaction.
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a transaction.
TransactionStatus status
Status: can change with block chain update.
static bool showTransaction(const CWalletTx &wtx)
Decompose CWallet transaction to model transaction records.
QString getTxID() const
Return the unique identifier for this transaction (part)
void updateStatus(const CWalletTx &wtx)
Update status from core wallet tx.
static QList< TransactionRecord > decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
bool statusUpdateNeeded()
Return whether a status update is needed.
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
bool countsForBalance
Transaction counts towards available balance.
qint64 open_for
Timestamp if status==OpenUntilDate, otherwise number of additional blocks that need to be mined befor...
@ MaturesWarning
Transaction will likely not mature because no nodes have confirmed.
@ Confirmed
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
@ OpenUntilDate
Normal (sent/received) transactions.
@ Unconfirmed
Not yet mined into a block.
@ Immature
Generated (mined) transactions.
@ Confirming
Confirmed, but waiting for the recommended number of confirmations.
@ NotAccepted
Mined but not accepted.
@ OpenUntilBlock
Transaction not yet final, waiting for block.
@ Conflicted
Conflicts with other transaction or mempool.
@ Abandoned
Abandoned from the wallet.
@ Offline
Not sent to any other nodes.
std::string sortKey
Sorting key based on status.
UI model for the transaction table of a wallet.
QVariant data(const QModelIndex &index, int role) const
QVariant txStatusDecoration(const TransactionRecord *wtx) const
int rowCount(const QModelIndex &parent) 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 formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::separatorStandard) const
QString formatTooltip(const TransactionRecord *rec) const
void updateConfirmations()
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const
void updateTransaction(const QString &hash, int status, bool showTransaction)
QString formatTxStatus(const TransactionRecord *wtx) const
WalletModel * walletModel
TransactionTableModel(const PlatformStyle *platformStyle, CWallet *wallet, WalletModel *parent=0)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
int columnCount(const QModelIndex &parent) const
const PlatformStyle * platformStyle
QString formatTxType(const TransactionRecord *wtx) const
QString lookupAddress(const std::string &address, bool tooltip) const
QVariant txAddressDecoration(const TransactionRecord *wtx) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QString formatTxDate(const TransactionRecord *wtx) const
TransactionTableModel * parent
QList< TransactionRecord > cachedWallet
void updateWallet(const uint256 &hash, int status, bool showTransaction)
QString getTxHex(TransactionRecord *rec)
TransactionTablePriv(CWallet *_wallet, TransactionTableModel *_parent)
QString describe(TransactionRecord *rec, int unit)
TransactionRecord * index(int idx)
Interface to Bitcoin wallet from Qt view code.
AddressTableModel * getAddressTableModel()
OptionsModel * getOptionsModel()
void SetHex(const char *psz)
std::string ToString() const
std::string GetHex() const
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
#define COLOR_TX_STATUS_DANGER
#define COLOR_UNCONFIRMED
#define COLOR_TX_STATUS_OPENUNTILDATE
#define COLOR_TX_STATUS_OFFLINE
#define COLOR_BAREADDRESS
QString dateTimeStr(const QDateTime &date)
void invoke(QObject *ttm)
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction)
TransactionNotification()
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
#define TRY_LOCK(cs, name)
ChangeType
General change type (added, updated, removed).
CCriticalSection cs_main
Global state.