13 #include <validation.h> 26 static int column_alignments[] = {
27 Qt::AlignLeft|Qt::AlignVCenter,
28 Qt::AlignLeft|Qt::AlignVCenter,
29 Qt::AlignLeft|Qt::AlignVCenter,
30 Qt::AlignLeft|Qt::AlignVCenter,
31 Qt::AlignLeft|Qt::AlignVCenter,
32 Qt::AlignRight|Qt::AlignVCenter
75 qDebug() <<
"TokenTransactionTablePriv::refreshWallet";
79 for(std::map<uint256, CTokenTx>::iterator it = wallet->
mapTokenTx.begin(); it != wallet->
mapTokenTx.end(); ++it)
103 qDebug() <<
"TokenTransactionTablePriv::updateWallet: " + QString::fromStdString(hash.
ToString()) +
" " + QString::number(status);
106 QList<TokenTransactionRecord>::iterator lower = qLowerBound(
108 QList<TokenTransactionRecord>::iterator upper = qUpperBound(
110 int lowerIndex = (lower - cachedWallet.begin());
111 int upperIndex = (upper - cachedWallet.begin());
112 bool inModel = (lower != upper);
116 if(showTransaction && !inModel)
118 if(!showTransaction && inModel)
122 qDebug() <<
" inModel=" + QString::number(inModel) +
123 " Index=" + QString::number(lowerIndex) +
"-" + QString::number(upperIndex) +
124 " showTransaction=" + QString::number(showTransaction) +
" derivedStatus=" + QString::number(status);
131 qWarning() <<
"TokenTransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is already in model";
138 std::map<uint256, CTokenTx>::iterator mi = wallet->
mapTokenTx.find(hash);
141 qWarning() <<
"TokenTransactionTablePriv::updateWallet: Warning: Got CT_NEW, but transaction is not in wallet";
145 QList<TokenTransactionRecord> toInsert =
147 if(!toInsert.isEmpty())
149 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex+toInsert.size()-1);
150 int insert_idx = lowerIndex;
153 cachedWallet.insert(insert_idx, rec);
156 parent->endInsertRows();
163 qWarning() <<
"TokenTransactionTablePriv::updateWallet: Warning: Got CT_DELETED, but transaction is not in model";
167 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex-1);
168 cachedWallet.erase(lower, upper);
169 parent->endRemoveRows();
174 qWarning() <<
"TokenTransactionTablePriv::updateWallet: Warning: Got CT_UPDATED, but entry is not in model";
181 std::map<uint256, CTokenTx>::iterator mi = wallet->
mapTokenTx.find(hash);
184 qWarning() <<
"TokenTransactionTablePriv::updateWallet: Warning: Got CT_UPDATED, but transaction is not in wallet";
188 QList<TokenTransactionRecord> toUpdate =
190 if(!toUpdate.isEmpty())
192 int update_idx = lowerIndex;
195 cachedWallet[update_idx] = rec;
207 return cachedWallet.size();
212 if(idx >= 0 && idx < cachedWallet.size())
229 std::map<uint256, CTokenTx>::iterator mi = wallet->
mapTokenTx.find(rec->
hash);
247 std::map<uint256, CTokenTx>::iterator mi = wallet->
mapTokenTx.find(rec->
hash);
259 std::map<uint256, CWalletTx>::iterator mi = wallet->
mapWallet.find(rec->
txid);
262 std::string strHex =
EncodeHexTx(static_cast<CTransaction>(mi->second));
263 return QString::fromStdString(strHex);
270 QAbstractTableModel(parent),
274 fProcessingQueuedTransactions(false),
275 platformStyle(_platformStyle)
277 columns << QString() << tr(
"Date") << tr(
"Type") << tr(
"Label") << tr(
"Name") << tr(
"Amount");
292 updated.
SetHex(hash.toStdString());
326 status = tr(
"Offline");
329 status = tr(
"Unconfirmed");
335 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
356 QString label = QString::fromStdString(_label);
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");
411 return QString::fromStdString(wtx->
address);
416 return QString::fromStdString(wtx->
address);
455 str = QString(
"[") + str + QString(
"]");
463 QString unit = QString::fromStdString(wtx->
tokenSymbol);
508 switch(index.column())
516 case Qt::DecorationRole:
520 case Qt::DisplayRole:
521 switch(index.column())
537 switch(index.column())
550 return QString::fromStdString((rec->
credit + rec->
debit).str());
553 case Qt::ToolTipRole:
555 case Qt::TextAlignmentRole:
556 return column_alignments[index.column()];
557 case Qt::ForegroundRole:
575 return QDateTime::fromTime_t(static_cast<uint>(rec->
time));
581 return QString::fromStdString(rec->
address);
585 return QString::fromStdString((rec->
credit + rec->
debit).str());
593 QDateTime date = QDateTime::fromTime_t(static_cast<uint>(rec->
time));
595 QString symbol = QString::fromStdString(rec->
tokenSymbol);
597 details.append(date.toString(
"M/d/yy HH:mm"));
600 details.append(
". ");
606 if(txLabel.isEmpty())
607 details.append(tr(
"(no label)") +
" ");
610 details.append(txLabel);
611 details.append(
") ");
613 details.append(QString::fromStdString(rec->
address));
617 details.append(
" " + symbol);
635 if(orientation == Qt::Horizontal)
637 if(role == Qt::DisplayRole)
641 else if (role == Qt::TextAlignmentRole)
643 return column_alignments[section];
644 }
else if (role == Qt::ToolTipRole)
649 return tr(
"Transaction status. Hover over this field to show number of confirmations.");
651 return tr(
"Date and time that the transaction was received.");
653 return tr(
"Type of transaction.");
655 return tr(
"User-defined intent/purpose of the transaction.");
657 return tr(
"Token name.");
659 return tr(
"Amount removed from or added to balance.");
672 return createIndex(row, column,
priv->
index(row));
674 return QModelIndex();
679 Q_EMIT dataChanged(
index(idx, 0, QModelIndex()),
index(idx,
columns.length()-1, QModelIndex()));
688 hash(_hash), status(_status), showTransaction(_showTransaction) {}
692 QString strHash = QString::fromStdString(hash.GetHex());
693 qDebug() <<
"NotifyTokenTransactionChanged: " + strHash +
" status= " + QString::number(status);
694 QMetaObject::invokeMethod(ttm,
"updateTransaction", Qt::QueuedConnection,
695 Q_ARG(QString, strHash),
697 Q_ARG(
bool, showTransaction));
705 static bool fQueueNotifications =
false;
706 static std::vector< TokenTransactionNotification > vQueueNotifications;
711 std::map<uint256, CTokenTx>::iterator mi = wallet->
mapTokenTx.find(hash);
713 bool showTransaction = mi != wallet->
mapTokenTx.end();
721 if (fQueueNotifications)
723 vQueueNotifications.push_back(notification);
732 fQueueNotifications =
true;
734 if (nProgress == 100)
736 fQueueNotifications =
false;
737 if (vQueueNotifications.size() > 10)
738 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
true));
739 for (
unsigned int i = 0; i < vQueueNotifications.size(); ++i)
741 if (vQueueNotifications.size() - i <= 10)
742 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
false));
744 vQueueNotifications[i].invoke(ttm);
746 std::vector<TokenTransactionNotification >().
swap(vQueueNotifications);
void updateStatus(const CWallet *wallet, const CTokenTx &wtx)
Update status from core wallet tx.
void subscribeToCoreSignals()
Date and time this transaction was created.
QString formatTxStatus(const TokenTransactionRecord *wtx) const
std::map< uint256, CTokenTx > mapTokenTx
#define TRY_LOCK(cs, name)
TokenTransactionNotification(uint256 _hash, ChangeType _status, bool _showTransaction)
void swap(dev::eth::Watch &_a, dev::eth::Watch &_b)
Transaction status (TokenTransactionRecord::Status)
CCriticalSection cs_wallet
Formatted amount, with unit.
QString lookupAddress(const std::string &address, const std::string &label, bool tooltip) const
WalletModel * walletModel
QString dateTimeStr(const QDateTime &date)
static QString formatTokenWithUnit(const QString unit, int decimals, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
QVariant data(const QModelIndex &index, int role) const
UI model for a token transaction.
QString formatTxToAddress(const TokenTransactionRecord *wtx, bool tooltip) const
bool operator()(const TokenTransactionRecord &a, const TokenTransactionRecord &b) const
Transaction data, hex-encoded.
#define COLOR_TX_STATUS_OFFLINE
Confirmed, but waiting for the recommended number of confirmations.
QVariant addressColor(const TokenTransactionRecord *wtx) const
QList< TokenTransactionRecord > cachedWallet
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTokenTransactionChanged
Wallet token transaction added, removed or updated.
TokenTransactionTablePriv(CWallet *_wallet, TokenTransactionTableModel *_parent)
AddressTableModel * getAddressTableModel()
QString getTxHex(TokenTransactionRecord *rec)
void updateWallet(const uint256 &hash, int status, bool showTransaction)
std::string sortKey
Sorting key based on status.
std::string ToString() const
Not yet mined into a block.
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
bool IsTokenTxMine(const CTokenTx &wtx) const
bool countsForBalance
Token transaction counts towards available balance.
QString describe(TokenTransactionRecord *rec)
Net amount of transaction.
static QList< TokenTransactionRecord > decomposeTransaction(const CWallet *wallet, const CTokenTx &wtx)
Decompose Token transaction into a record.
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
ChangeType
General change type (added, updated, removed).
int rowCount(const QModelIndex &parent) const
Is transaction confirmed?
QString formatTxDate(const TokenTransactionRecord *wtx) const
TokenTransactionRecord * index(int idx)
UI model for the transaction table of a wallet.
int columnCount(const QModelIndex &parent) const
static QString toHTML(CWallet *wallet, CTokenTx &wtx, TokenTransactionRecord *rec)
QString formatTxTokenSymbol(const TokenTransactionRecord *wtx) const
void unsubscribeFromCoreSignals()
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
QString formatTxType(const TokenTransactionRecord *wtx) const
bool operator()(const uint256 &a, const TokenTransactionRecord &b) const
QVariant txAddressDecoration(const TokenTransactionRecord *wtx) const
TokenTransactionNotification()
#define COLOR_UNCONFIRMED
TokenTransactionTableModel * parent
Formatted amount, without brackets when unconfirmed.
static QString formatToken(int decimal_units, const int256_t &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format token as string.
Whole transaction as plain text.
QString labelForAddress(const QString &address) const
void updateTransaction(const QString &hash, int status, bool showTransaction)
The block chain is a tree shaped structure starting with the genesis block at the root...
Normal (sent/received) token transactions.
Interface to Fabcoin wallet from Qt view code.
QString formatTxAmount(const TokenTransactionRecord *wtx, bool showUnconfirmed=true, FabcoinUnits::SeparatorStyle separators=FabcoinUnits::separatorStandard) const
TokenTransactionTableModel(const PlatformStyle *platformStyle, CWallet *wallet, WalletModel *parent=0)
void emitDataChanged(int index)
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)
Long description (HTML format)
QVariant txStatusDecoration(const TokenTransactionRecord *wtx) const
std::map< uint256, CWalletTx > mapWallet
const PlatformStyle * platformStyle
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Label of address related to transaction.
bool operator()(const TokenTransactionRecord &a, const uint256 &b) const
TokenTransactionStatus status
Status: can change with block chain update.
struct evm_uint160be address(struct evm_env *env)
void invoke(QObject *ttm)
QString formatTooltip(const TokenTransactionRecord *rec) const
int64_t GetBlockTime() const
void SetHex(const char *psz)
~TokenTransactionTableModel()
#define COLOR_BAREADDRESS
bool statusUpdateNeeded()
Return whether a status update is needed.
QString formatTxAmountWithUnit(const TokenTransactionRecord *wtx, bool showUnconfirmed=true, FabcoinUnits::SeparatorStyle separators=FabcoinUnits::separatorStandard) const
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a token transaction.
bool AddTokenTxEntry(const CTokenTx &tokenTx, bool fFlushOnClose=true)
void updateConfirmations()
TokenTransactionTablePriv * priv