18 #include "validation.h" 31 static int column_alignments[] = {
32 Qt::AlignLeft|Qt::AlignVCenter,
33 Qt::AlignLeft|Qt::AlignVCenter,
34 Qt::AlignLeft|Qt::AlignVCenter,
35 Qt::AlignLeft|Qt::AlignVCenter,
36 Qt::AlignLeft|Qt::AlignVCenter,
37 Qt::AlignRight|Qt::AlignVCenter,
38 Qt::AlignLeft|Qt::AlignVCenter
81 qDebug() <<
"TransactionTablePriv::refreshWallet";
85 for(std::map<uint256, CWalletTx>::iterator it = wallet->
mapWallet.begin(); it != wallet->
mapWallet.end(); ++it)
100 qDebug() <<
"TransactionTablePriv::updateWallet: " + QString::fromStdString(hash.
ToString()) +
" " + QString::number(status);
103 QList<TransactionRecord>::iterator lower = qLowerBound(
104 cachedWallet.begin(), cachedWallet.end(), hash,
TxLessThan());
105 QList<TransactionRecord>::iterator upper = qUpperBound(
106 cachedWallet.begin(), cachedWallet.end(), hash,
TxLessThan());
107 int lowerIndex = (lower - cachedWallet.begin());
108 int upperIndex = (upper - cachedWallet.begin());
109 bool inModel = (lower != upper);
113 if(showTransaction && !inModel)
115 if(!showTransaction && inModel)
119 qDebug() <<
" inModel=" + QString::number(inModel) +
120 " Index=" + QString::number(lowerIndex) +
"-" + QString::number(upperIndex) +
121 " showTransaction=" + QString::number(showTransaction) +
" derivedStatus=" + QString::number(status);
128 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
135 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(hash);
138 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
142 QList<TransactionRecord> toInsert =
144 if(!toInsert.isEmpty())
146 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
147 int insert_idx = lowerIndex;
150 cachedWallet.insert(insert_idx, rec);
153 parent->endInsertRows();
160 qWarning() <<
"TransactionTablePriv::updateWallet: Warning: Got CT_DELETED, but transaction is not in model";
164 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
165 cachedWallet.erase(lower, upper);
166 parent->endRemoveRows();
171 for (
int i = lowerIndex; i < upperIndex; i++) {
181 return cachedWallet.size();
186 if(idx >= 0 && idx < cachedWallet.size())
203 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(rec->
hash);
220 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(rec->
hash);
232 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(rec->
hash);
235 std::string strHex =
EncodeHexTx(static_cast<CTransaction>(mi->second));
236 return QString::fromStdString(strHex);
243 QAbstractTableModel(parent),
247 fProcessingQueuedTransactions(false),
248 platformStyle(_platformStyle)
250 columns << QString() << QString() << tr(
"Date") << tr(
"Type") << tr(
"Label") << tr(
"Amount") << tr(
"Asset");
275 updated.
SetHex(hash.toStdString());
315 status = tr(
"Offline");
318 status = tr(
"Unconfirmed");
321 status = tr(
"Abandoned");
327 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
330 status = tr(
"Conflicted");
336 status = tr(
"This block was not received by any other nodes and will probably not be accepted!");
339 status = tr(
"Generated but not accepted");
364 description += label;
366 if(label.isEmpty() || tooltip)
368 description += QString(
" (") + QString::fromStdString(address) + QString(
")");
378 return tr(
"Received with");
380 return tr(
"Received from");
383 return tr(
"Sent to");
385 return tr(
"Payment to yourself");
389 return tr(
"Asset Issued");
391 return tr(
"Asset Reissued");
393 return tr(
"Assets Received");
395 return tr(
"Assets Sent");
406 return QIcon(
":/icons/tx_mined");
409 return QIcon(
":/icons/tx_input");
412 return QIcon(
":/icons/tx_output");
416 return QIcon(
":/icons/tx_asset_input");
418 return QIcon(
":/icons/tx_asset_output");
420 return QIcon(
":/icons/tx_inout");
426 QString watchAddress;
429 watchAddress = wtx->
involvesWatchAddress ? QString(
" (") + tr(
"watch-only") + QString(
")") :
"";
438 return QString::fromStdString(wtx->
address) + watchAddress;
440 return QString::fromStdString(wtx->
address) + watchAddress;
446 return QString::fromStdString(wtx->
address) + watchAddress;
449 return tr(
"(n/a)") + watchAddress;
491 if (showUnconfirmed) {
493 str = QString(
"[") + str + QString(
"]");
509 return QIcon(
":/icons/transaction_0");
511 return QIcon(
":/icons/transaction_abandoned");
515 case 1:
return QIcon(
":/icons/transaction_1");
516 case 2:
return QIcon(
":/icons/transaction_2");
517 case 3:
return QIcon(
":/icons/transaction_3");
518 case 4:
return QIcon(
":/icons/transaction_4");
519 default:
return QIcon(
":/icons/transaction_5");
522 return QIcon(
":/icons/transaction_confirmed");
524 return QIcon(
":/icons/transaction_conflicted");
528 return QIcon(QString(
":/icons/transaction_%1").arg(part));
532 return QIcon(
":/icons/transaction_0");
541 return QIcon(
":/icons/eye");
566 switch(index.column())
575 return QString::fromStdString(rec->
assetName);
578 case Qt::DecorationRole:
583 case Qt::DisplayRole:
584 switch(index.column())
595 return QString::fromStdString(rec->
assetName);
600 switch(index.column())
615 return QString::fromStdString(rec->
assetName);
618 case Qt::ToolTipRole:
620 case Qt::TextAlignmentRole:
621 return column_alignments[index.column()];
622 case Qt::ForegroundRole:
645 return QDateTime::fromTime_t(static_cast<uint>(rec->
time));
653 return QString::fromStdString(rec->
address);
667 QDateTime date = QDateTime::fromTime_t(static_cast<uint>(rec->
time));
670 details.append(date.toString(
"M/d/yy HH:mm"));
673 details.append(
". ");
679 if(txLabel.isEmpty())
680 details.append(tr(
"(no label)") +
" ");
683 details.append(txLabel);
684 details.append(
") ");
686 details.append(QString::fromStdString(rec->
address));
700 assetName.append(QString::fromStdString(rec->
assetName));
711 if(orientation == Qt::Horizontal)
713 if(role == Qt::DisplayRole)
717 else if (role == Qt::TextAlignmentRole)
719 return column_alignments[section];
720 }
else if (role == Qt::ToolTipRole)
725 return tr(
"Transaction status. Hover over this field to show number of confirmations.");
727 return tr(
"Date and time that the transaction was received.");
729 return tr(
"Type of transaction.");
731 return tr(
"Whether or not a watch-only address is involved in this transaction.");
733 return tr(
"User-defined intent/purpose of the transaction.");
735 return tr(
"Amount removed from or added to balance.");
737 return tr(
"The asset (or RVN) removed or added to balance.");
750 return createIndex(row, column,
priv->
index(row));
752 return QModelIndex();
768 hash(_hash), status(_status), showTransaction(_showTransaction) {}
772 QString strHash = QString::fromStdString(hash.GetHex());
773 qDebug() <<
"NotifyTransactionChanged: " + strHash +
" status= " + QString::number(status);
774 QMetaObject::invokeMethod(ttm,
"updateTransaction", Qt::QueuedConnection,
775 Q_ARG(QString, strHash),
777 Q_ARG(
bool, showTransaction));
785 static bool fQueueNotifications =
false;
786 static std::vector< TransactionNotification > vQueueNotifications;
791 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(hash);
793 bool inWallet = mi != wallet->
mapWallet.end();
798 if (fQueueNotifications)
800 vQueueNotifications.push_back(notification);
809 fQueueNotifications =
true;
811 if (nProgress == 100)
813 fQueueNotifications =
false;
814 if (vQueueNotifications.size() > 10)
815 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
true));
816 for (
unsigned int i = 0; i < vQueueNotifications.size(); ++i)
818 if (vQueueNotifications.size() - i <= 10)
819 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
false));
821 vQueueNotifications[i].invoke(ttm);
823 std::vector<TransactionNotification >().swap(vQueueNotifications);
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
QString describe(TransactionRecord *rec, int unit)
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard, const int nAssetUnit=MIN_ASSET_UNITS - 1)
Format as string.
Confirmed, but waiting for the recommended number of confirmations.
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const
Transaction not yet final, waiting for block.
Transaction status (TransactionRecord::Status)
#define TRY_LOCK(cs, name)
Not sent to any other nodes.
CCriticalSection cs_wallet
Generated (mined) transactions.
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)
CCriticalSection cs_main
Global state.
QString dateTimeStr(const QDateTime &date)
void unsubscribeFromCoreSignals()
QVariant txStatusDecoration(const TransactionRecord *wtx) const
TransactionRecord * index(int idx)
bool operator()(const TransactionRecord &a, const TransactionRecord &b) const
Not yet mined into a block.
#define COLOR_TX_STATUS_OFFLINE
static bool showTransaction(const CWalletTx &wtx)
Decompose CWallet transaction to model transaction records.
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */...
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, RavenUnits::SeparatorStyle separators=RavenUnits::separatorStandard) const
AddressTableModel * getAddressTableModel()
Transaction data, hex-encoded.
TransactionTableModel * parent
TransactionTableModel(const PlatformStyle *platformStyle, CWallet *wallet, WalletModel *parent=0)
void updateWallet(const uint256 &hash, int status, bool showTransaction)
Long description (HTML format)
TransactionTablePriv * priv
int getDisplayUnit() const
bool operator()(const uint256 &a, const TransactionRecord &b) const
QList< TransactionRecord > cachedWallet
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
bool operator()(const TransactionRecord &a, const uint256 &b) const
UI model for a transaction.
TransactionStatus status
Status: can change with block chain update.
QString formatTxType(const TransactionRecord *wtx) const
TransactionTablePriv(CWallet *_wallet, TransactionTableModel *_parent)
TransactionNotification()
Whole transaction as plain text.
static QList< TransactionRecord > decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
ChangeType
General change type (added, updated, removed).
QString getTxID() const
Return the unique identifier for this transaction (part)
#define COLOR_TX_STATUS_DANGER
QString labelForAddress(const QString &address) const
Is transaction confirmed?
TransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction)
bool countsForBalance
Transaction counts towards available balance.
void updateStatus(const CWalletTx &wtx)
Update status from core wallet tx.
bool statusUpdateNeeded() const
Return whether a status update is needed.
std::string ValueFromAmountString(const CAmount &amount, const int8_t units)
QString getTxHex(TransactionRecord *rec)
Date and time this transaction was created.
std::string ToString() const
UI model for the transaction table of a wallet.
#define COLOR_UNCONFIRMED
Normal (sent/received) transactions.
QString lookupAddress(const std::string &address, bool tooltip) const
void subscribeToCoreSignals()
QVariant data(const QModelIndex &index, int role) const
Net amount of transaction.
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
Conflicts with other transaction or mempool.
Interface to Raven wallet from Qt view code.
int columnCount(const QModelIndex &parent) const
int rowCount(const QModelIndex &parent) const
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
QVariant headerData(int section, Qt::Orientation orientation, int role) const
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
std::string EncodeHexTx(const CTransaction &tx, const int serializeFlags=0)
Label of address related to transaction.
std::map< uint256, CWalletTx > mapWallet
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
QString formatTxStatus(const TransactionRecord *wtx) const
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
Formatted amount, without brackets when unconfirmed.
void updateConfirmations()
void SetHex(const char *psz)
static QString toHTML(CWallet *wallet, CWalletTx &wtx, TransactionRecord *rec, int unit)
Abandoned from the wallet.
#define COLOR_BAREADDRESS
const PlatformStyle * platformStyle
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a transaction.
Transaction will likely not mature because no nodes have confirmed.
OptionsModel * getOptionsModel()
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
QString formatTxDate(const TransactionRecord *wtx) const