 |
PRCYCoin
2.0.0.7rc1
P2P Digital Currency
|
Go to the documentation of this file.
28 #include <QtConcurrent/QtConcurrent>
31 #define SINGLE_THREAD_MAX_TXES_SIZE 4000
36 #define MAX_AMOUNT_LOADED_RECORDS 20000
39 static int column_alignments[] = {
40 Qt::AlignLeft | Qt::AlignVCenter,
41 Qt::AlignLeft | Qt::AlignVCenter,
42 Qt::AlignLeft | Qt::AlignVCenter,
43 Qt::AlignLeft | Qt::AlignVCenter,
44 Qt::AlignLeft | Qt::AlignVCenter,
45 Qt::AlignRight | Qt::AlignVCenter
52 return a.
hash <
b.hash;
92 customThreadLimit =
GetArg(
"-txthreadinglimit", 4000);
93 maxTXUIlLimit =
GetArg(
"-maxtxuilimit", 20000);
98 std::size_t txesSize = walletTxes.size();
99 if (txesSize > customThreadLimit &&
GetBoolArg(
"-txthreading",
true)) {
101 if (txesSize > maxTXUIlLimit) {
105 sort(walletTxes.begin(), walletTxes.end(),
107 return a.GetComputedTxTime() > b.GetComputedTxTime();
112 txesSize = walletTxes.size();
116 std::size_t threadsCount = (QThreadPool::globalInstance()->maxThreadCount() / 2 ) + 1;
119 std::size_t
const subsetSize = txesSize / (threadsCount + 1);
120 std::size_t totalSumSize = 0;
121 QList<QFuture<QList<TransactionRecord>>> tasks;
124 for (std::size_t i = 0; i < threadsCount; ++i) {
130 std::vector<CWalletTx>(walletTxes.begin() + totalSumSize, walletTxes.begin() + totalSumSize + subsetSize)
133 totalSumSize += subsetSize;
137 std::size_t
const remainingSize = txesSize - totalSumSize;
139 std::vector<CWalletTx>(walletTxes.end() - remainingSize, walletTxes.end())
142 for (QFuture<QList<TransactionRecord>> &future : tasks) {
143 future.waitForFinished();
154 for (
const auto &tx : walletTxes) {
169 qDebug() <<
"TransactionTablePriv::updateWallet : " + QString::fromStdString(hash.
ToString()) +
" " + QString::number(status);
172 QList<TransactionRecord>::iterator lower = std::lower_bound(
174 QList<TransactionRecord>::iterator upper = std::upper_bound(
178 bool inModel = (lower != upper);
181 if (showTransaction && !inModel)
183 if (!showTransaction && inModel)
187 qDebug() <<
" inModel=" + QString::number(inModel) +
188 " Index=" + QString::number(lowerIndex) +
"-" + QString::number(upperIndex) +
189 " showTransaction=" + QString::number(showTransaction) +
" derivedStatus=" + QString::number(status);
194 qWarning() <<
"TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is already in model";
197 if (showTransaction) {
200 std::map<uint256, CWalletTx>::iterator mi =
wallet->
mapWallet.find(hash);
202 qWarning() <<
"TransactionTablePriv::updateWallet : Warning: Got CT_NEW, but transaction is not in wallet";
207 QList<TransactionRecord> toInsert =
209 if (!toInsert.isEmpty())
211 parent->beginInsertRows(QModelIndex(), lowerIndex, lowerIndex + toInsert.size() - 1);
212 int insert_idx = lowerIndex;
223 qWarning() <<
"TransactionTablePriv::updateWallet : Warning: Got CT_DELETED, but transaction is not in model";
227 parent->beginRemoveRows(QModelIndex(), lowerIndex, upperIndex - 1);
288 fProcessingQueuedTransactions(false)
308 Q_EMIT headerDataChanged(Qt::Horizontal,
Amount,
Amount);
314 updated.
SetHex(hash.toStdString());
348 status = tr(
"Open for %n more block(s)",
"", wtx->
status.
open_for);
354 status = tr(
"Offline");
357 status = tr(
"Unconfirmed");
363 status = tr(
"Confirmed (%1 confirmations)").arg(wtx->
status.
depth);
366 status = tr(
"Conflicted");
372 status = tr(
"This block was not received by any other nodes and will probably not be accepted!");
375 status = tr(
"Orphan Block - Generated but not accepted. This does not impact your holdings.");
397 if (!label.isEmpty()) {
398 description += label;
400 if (label.isEmpty() || tooltip) {
401 description += QString(
" (") + QString::fromStdString(address) + QString(
")");
410 return tr(
"Received with");
412 return tr(
"Masternode Reward");
414 return tr(
"Received from");
417 return tr(
"Sent to");
419 return tr(
"Payment to yourself");
440 return QIcon(
":/icons/tx_mined");
443 return QIcon(
":/icons/tx_input");
446 return QIcon(
":/icons/tx_output");
448 return QIcon(
":/icons/tx_inout");
454 QString watchAddress;
457 watchAddress = wtx->
involvesWatchAddress ? QString(
" (") + tr(
"watch-only") + QString(
")") :
"";
462 return QString::fromStdString(wtx->
address) + watchAddress;
470 return QString::fromStdString(wtx->
address) + watchAddress;
472 return QString::fromStdString(wtx->
address) + watchAddress;
474 return tr(
"(n/a)") + watchAddress;
501 if (showUnconfirmed) {
503 str = QString(
"[") + str + QString(
"]");
518 return QIcon(
":/icons/transaction_0");
522 return QIcon(
":/icons/transaction_1");
524 return QIcon(
":/icons/transaction_2");
526 return QIcon(
":/icons/transaction_3");
528 return QIcon(
":/icons/transaction_4");
530 return QIcon(
":/icons/transaction_5");
533 return QIcon(
":/icons/transaction_confirmed");
535 return QIcon(
":/icons/transaction_conflicted");
539 return QIcon(QString(
":/icons/transaction_%1").arg(part));
543 return QIcon(
":/icons/transaction_0");
552 return QIcon(
":/icons/eye");
569 if (!
index.isValid())
574 case Qt::DecorationRole:
575 switch (
index.column()) {
584 case Qt::DisplayRole:
585 switch (
index.column()) {
600 switch (
index.column()) {
617 case Qt::ToolTipRole:
619 case Qt::TextAlignmentRole:
620 return column_alignments[
index.column()];
621 case Qt::ForegroundRole:
650 return QDateTime::fromTime_t(
static_cast<uint
>(rec->
time));
658 return QString::fromStdString(rec->
address);
680 if (orientation == Qt::Horizontal) {
681 if (role == Qt::DisplayRole) {
683 }
else if (role == Qt::TextAlignmentRole) {
684 return column_alignments[section];
685 }
else if (role == Qt::ToolTipRole) {
688 return tr(
"Transaction status. Hover over this field to show number of confirmations.");
690 return tr(
"Date and time that the transaction was received.");
692 return tr(
"Type of transaction.");
694 return tr(
"Whether or not a watch-only address is involved in this transaction.");
696 return tr(
"Destination address of transaction.");
698 return tr(
"Amount removed from or added to balance.");
700 return tr(
"Confirmed Count.");
712 return createIndex(row, column,
data);
714 return QModelIndex();
732 QString strHash = QString::fromStdString(
hash.
GetHex());
733 qDebug() <<
"NotifyTransactionChanged : " + strHash +
" status= " + QString::number(
status);
734 QMetaObject::invokeMethod(ttm,
"updateTransaction", Qt::QueuedConnection,
735 Q_ARG(QString, strHash),
745 static bool fQueueNotifications =
false;
746 static std::vector<TransactionNotification> vQueueNotifications;
753 if (fQueueNotifications)
755 vQueueNotifications.push_back(notification);
764 fQueueNotifications =
true;
766 if (nProgress == 100) {
767 fQueueNotifications =
false;
768 if (vQueueNotifications.size() > 10)
769 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
true));
770 for (
unsigned int i = 0; i < vQueueNotifications.size(); ++i) {
771 if (vQueueNotifications.size() - i <= 10)
772 QMetaObject::invokeMethod(ttm,
"setProcessingQueuedTransactions", Qt::QueuedConnection, Q_ARG(
bool,
false));
774 vQueueNotifications[i].invoke(ttm);
776 std::vector<TransactionNotification>().swap(vQueueNotifications);
OptionsModel * getOptionsModel()
QVariant txAddressDecoration(const TransactionRecord *wtx) const
QString formatTxStatus(const TransactionRecord *wtx) const
bool statusUpdateNeeded()
Return whether a status update is needed.
void updateConfirmations()
QVariant txStatusDecoration(const TransactionRecord *wtx) const
std::string sortKey
Sorting key based on status.
@ OpenUntilDate
Normal (sent/received) transactions.
std::map< uint256, CWalletTx > mapWallet
QString describe(TransactionRecord *rec, int unit)
Interface to Bitcoin wallet from Qt view code.
@ AddressRole
Address of transaction.
void invoke(QObject *ttm)
std::string GetHex() const
TransactionStatus status
Status: can change with block chain update.
QString formatTxDate(const TransactionRecord *wtx) const
AddressTableModel * getAddressTableModel()
@ WatchonlyRole
Watch-only boolean.
QString labelForAddress(const QString &address) const
@ Conflicted
Conflicts with other transaction or mempool.
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const
std::vector< CWalletTx > getWalletTxs()
TransactionTableModel * parent
#define TRY_LOCK(cs, name)
TransactionRecord * index(int idx)
void updateStatus(const CWalletTx &wtx)
Update status from core wallet tx.
QVariant txWatchonlyDecoration(const TransactionRecord *wtx) const
#define COLOR_BAREADDRESS
static const int RecommendedNumConfirmations
Number of confirmation recommended for accepting a transaction.
TransactionNotification(uint256 hash, ChangeType status)
UI model for a transaction.
@ MaturesWarning
Transaction will likely not mature because no nodes have confirmed.
@ TxIDRole
Unique identifier.
QString formatTxAmount(const TransactionRecord *wtx, bool showUnconfirmed=true, BitcoinUnits::SeparatorStyle separators=BitcoinUnits::separatorStandard) const
void updateTransaction(const QString &hash, int status, bool showTransaction)
QString formatTxConfirmations(const TransactionRecord *wtx) const
RecursiveMutex cs_main
Global state.
void updateWallet(const uint256 &hash, int status, bool showTransaction)
@ AmountRole
Net amount of transaction.
void subscribeToCoreSignals()
qint64 open_for
Timestamp if status==OpenUntilDate, otherwise number of additional blocks that need to be mined befor...
void unsubscribeFromCoreSignals()
QList< TransactionRecord > cachedWallet
#define SINGLE_THREAD_MAX_TXES_SIZE
QString formatTxToAddress(const TransactionRecord *wtx, bool tooltip) const
bool involvesWatchAddress
Whether the transaction was sent/received with a watch-only address.
#define MAX_AMOUNT_LOADED_RECORDS
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
TransactionTablePriv * priv
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
int rowCount(const QModelIndex &parent) const
@ StatusRole
Transaction status (TransactionRecord::Status)
#define COLOR_TX_STATUS_OFFLINE
int columnCount(const QModelIndex &parent) const
256-bit unsigned big integer.
void SetHex(const char *psz)
QVariant headerData(int section, Qt::Orientation orientation, int role) const
QVariant data(const QModelIndex &index, int role) const
@ Immature
Generated (mined) transactions.
bool operator()(const TransactionRecord &a, const TransactionRecord &b) const
#define COLOR_TX_STATUS_OPENUNTILDATE
static QList< TransactionRecord > convertTxToRecords(TransactionTablePriv *tablePriv, const CWallet *wallet, const std::vector< CWalletTx > &walletTxes)
@ OpenUntilBlock
Transaction not yet final, waiting for block.
@ FormattedAmountRole
Formatted amount, without brackets when unconfirmed.
static QString format(int unit, const CAmount &amount, bool plussign=false, SeparatorStyle separators=separatorStandard)
Format as string.
@ Confirmed
Have 6 or more confirmations (normal tx) or fully mature (mined tx)
@ LongDescriptionRole
Long description (HTML format)
ChangeType
General change type (added, updated, removed).
QVariant addressColor(const TransactionRecord *wtx) const
UI model for the transaction table of a wallet.
@ Confirming
Confirmed, but waiting for the recommended number of confirmations.
QString formatTxType(const TransactionRecord *wtx) const
static QList< TransactionRecord > decomposeTransaction(const CWallet *wallet, const CWalletTx &wtx)
Decompose CWallet transaction to model transaction records.
@ WatchonlyDecorationRole
Watch-only icon.
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances,...
static QString getAmountColumnTitle(int unit)
Gets title for amount column including current display unit if optionsModel reference available */.
A transaction with a bunch of additional info that only the owner cares about.
boost::signals2::signal< void(CWallet *wallet, const uint256 &hashTx, ChangeType status)> NotifyTransactionChanged
Wallet transaction added, removed or updated.
bool operator()(const uint256 &a, const TransactionRecord &b) const
@ Offline
Not sent to any other nodes.
QString lookupAddress(const std::string &address, bool tooltip) const
bool operator()(const TransactionRecord &a, const uint256 &b) const
TransactionTablePriv(CWallet *wallet, TransactionTableModel *parent)
TransactionNotification()
@ TxHashRole
Transaction hash.
QString dateTimeStr(const QDateTime &date)
@ DateRole
Date and time this transaction was created.
@ NotAccepted
Mined but not accepted.
static QString toHTML(CWallet *wallet, CWalletTx &wtx, TransactionRecord *rec, int unit)
bool countsForBalance
Transaction counts towards available balance.
@ Unconfirmed
Not yet mined into a block.
TransactionTableModel(CWallet *wallet, WalletModel *parent=0)
@ TypeRole
Type of transaction.
QString getTxID() const
Return the unique identifier for this transaction (part)
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
void updateAmountColumnTitle()
Updates the column title to "Amount (DisplayUnit)" and emits headerDataChanged() signal for table hea...
@ LabelRole
Label of address related to transaction.
QString formatTooltip(const TransactionRecord *rec) const
WalletModel * walletModel
#define COLOR_UNCONFIRMED
@ ConfirmedRole
Is transaction confirmed?
std::string ToString() const