Skip to content

Commit a9b56df

Browse files
committed
src/qt/mempooltxtables.cpp:inital impl
1 parent 4c20cf1 commit a9b56df

File tree

7 files changed

+242
-1
lines changed

7 files changed

+242
-1
lines changed

src/qt/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ add_library(bitcoinqt STATIC EXCLUDE_FROM_ALL
9595
mempooldetail.cpp
9696
mempoolfeetables.cpp
9797
mempoolfeetables.h
98+
mempooltxtables.cpp
99+
mempooltxtables.h
98100
mempoolstats.h
99101
mempoolstats.cpp
100102
modaloverlay.cpp

src/qt/clientmodel.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include <netaddress.h>
1818
#include <interfaces/node.h>
19+
#include <interfaces/wallet.h> // New: Include for interfaces::WalletTx
1920

2021
class BanTableModel;
2122
class CBlockIndex;
@@ -63,6 +64,10 @@ class ClientModel : public QObject
6364
explicit ClientModel(interfaces::Node& node, OptionsModel *optionsModel, QObject *parent = nullptr);
6465
~ClientModel();
6566

67+
// Delete copy constructor and assignment operator to prevent implicit copying
68+
ClientModel(const ClientModel&) = delete;
69+
ClientModel& operator=(const ClientModel&) = delete;
70+
6671
void stop();
6772

6873
interfaces::Node& node() const { return m_node; }
@@ -108,6 +113,8 @@ class ClientModel : public QObject
108113
std::vector<mempool_feehist_sample> m_mempool_feehist;
109114
std::atomic<int64_t> m_mempool_feehist_last_sample_timestamp{0};
110115

116+
std::set<interfaces::WalletTx> m_wallet_transactions; // New: Stores active wallet's mempool transactions
117+
111118
private:
112119
interfaces::Node& m_node;
113120
std::unique_ptr<interfaces::Handler> m_handler_show_progress;
@@ -140,6 +147,7 @@ class ClientModel : public QObject
140147
void networkActiveChanged(bool networkActive);
141148
void alertsChanged(const QString &warnings);
142149
void bytesChanged(quint64 totalBytesIn, quint64 totalBytesOut);
150+
void walletTxChanged(); // New: Signal emitted when wallet transactions in mempool change
143151

144152
//! Fired when a message should be reported to the user
145153
void message(const QString &title, const QString &message, unsigned int style);

src/qt/mempooldetail.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <qt/mempoolconstants.h>
1414
#include <qt/mempooldetail.h>
1515
#include <qt/platformstyle.h>
16+
#include <qt/mempooltxtables.h>
1617

1718

1819
const QSize FONT_RANGE(8, 24);
@@ -64,6 +65,7 @@ void MempoolDetail::setPlatformStyle(const PlatformStyle* platform_style)
6465
m_top_layout->addStretch();
6566
m_top_layout->addWidget(m_temp_widget);
6667

68+
// Mempool Fee Table
6769
m_fee_table_model = new MempoolFeeTableModel(this);
6870

6971
m_fee_table = new QTableView(this);
@@ -87,9 +89,31 @@ void MempoolDetail::setPlatformStyle(const PlatformStyle* platform_style)
8789
m_fee_table_header->resizeSection(MempoolFeeTableModel::TotalSize, 55);
8890
m_fee_table_header->resizeSection(MempoolFeeTableModel::TotalWeight, 50);
8991

92+
// Mempool Transaction Table
93+
m_tx_table_model = new MempoolTxTableModel(this);
94+
m_tx_table = new QTableView(this);
95+
m_tx_table->setModel(m_tx_table_model);
96+
m_tx_table->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
97+
m_tx_table->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
98+
m_tx_table->setEditTriggers(QAbstractItemView::NoEditTriggers);
99+
m_tx_table->setSelectionBehavior(QAbstractItemView::SelectRows);
100+
m_tx_table->setSelectionMode(QAbstractItemView::SingleSelection);
101+
m_tx_table->setAlternatingRowColors(true);
102+
m_tx_table->setStyleSheet("QTableView { background-color: transparent; border: 1px solid gray; border-radius: 5px; }");
103+
m_tx_table->setSortingEnabled(false); // Sorting not implemented for this model yet
104+
m_tx_table->verticalHeader()->setVisible(false);
105+
m_tx_table->horizontalHeader()->setStretchLastSection(true);
106+
107+
QHeaderView* m_tx_table_header = m_tx_table->horizontalHeader();
108+
m_tx_table_header->resizeSection(MempoolTxTableModel::TxID, 200);
109+
m_tx_table_header->resizeSection(MempoolTxTableModel::Amount, 100);
110+
m_tx_table_header->resizeSection(MempoolTxTableModel::Fee, 80);
111+
m_tx_table_header->resizeSection(MempoolTxTableModel::Status, 80);
112+
90113
QVBoxLayout* main_layout = new QVBoxLayout(this);
91114
main_layout->addLayout(m_top_layout);
92-
main_layout->addWidget(m_fee_table);
115+
main_layout->addWidget(m_tx_table); // Add transaction table first
116+
main_layout->addWidget(m_fee_table); // Then add fee table
93117
setLayout(main_layout);
94118

95119
connect(m_fee_table->selectionModel(), &QItemSelectionModel::currentRowChanged, this, [this](const QModelIndex& current, const QModelIndex& previous) {
@@ -113,7 +137,9 @@ void MempoolDetail::setClientModel(ClientModel* model)
113137
connect(model, &ClientModel::mempoolFeeHistChanged, this, &MempoolDetail::updateFeeTable);
114138
connect(model, &ClientModel::numBlocksChanged, this, &MempoolDetail::updateFeeTable);
115139
connect(model, &ClientModel::mempoolRangeSelected, this, &MempoolDetail::onRangeSelected);
140+
connect(model, &ClientModel::walletTxChanged, this, &MempoolDetail::updateTxTable); // Connect new signal
116141
MempoolDetail::updateFeeTable();
142+
MempoolDetail::updateTxTable(); // Initial update for transaction table
117143
}
118144
}
119145

@@ -132,6 +158,18 @@ void MempoolDetail::updateFeeTable()
132158
}
133159
}
134160

161+
void MempoolDetail::updateTxTable()
162+
{
163+
if (m_clientmodel) {
164+
QMutexLocker locker(&m_clientmodel->m_mempool_locker);
165+
// Assuming m_wallet_transactions in ClientModel is updated via MempoolStats::onWalletTxChanged
166+
// and ClientModel::walletTxChanged signal is emitted.
167+
// For now, we'll pass the raw set of wallet transactions.
168+
// Further filtering for 'in mempool' status can be done in MempoolTxTableModel if needed.
169+
m_tx_table_model->updateModel(m_clientmodel->m_wallet_transactions);
170+
}
171+
}
172+
135173
void MempoolDetail::setFontSize(qreal newSize)
136174
{
137175
if (newSize < FONT_RANGE.width() || newSize > FONT_RANGE.height())

src/qt/mempooldetail.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include <policy/fees.h>
1515

1616
#include <qt/mempoolfeetables.h>
17+
#include <qt/mempooltxtables.h>
1718
#include <interfaces/wallet.h>
1819

1920
class ClientModel;
@@ -31,6 +32,7 @@ class MempoolDetail : public QWidget
3132
public Q_SLOTS:
3233
void onRangeSelected(int range);
3334
void updateFeeTable();
35+
void updateTxTable();
3436

3537
void mousePressEvent(QMouseEvent *event) override;
3638
void mouseReleaseEvent(QMouseEvent *event) override;
@@ -53,6 +55,9 @@ public Q_SLOTS:
5355
QTableView *m_fee_table{nullptr};
5456
MempoolFeeTableModel *m_fee_table_model{nullptr};
5557

58+
QTableView *m_tx_table{nullptr};
59+
MempoolTxTableModel *m_tx_table_model{nullptr};
60+
5661
virtual void enterEvent(QEnterEvent *event) override;
5762
virtual void leaveEvent(QEvent *event) override;
5863
void changeEvent(QEvent* e) override;

src/qt/mempoolstats.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ void MempoolStats::setClientModel(ClientModel *model)
309309
connect(model, &ClientModel::mempoolRangeSelected, this, &MempoolStats::onMempoolRangeSelected);
310310
if (m_mempool_detail) {
311311
connect(model, &ClientModel::mempoolFeeHistChanged, m_mempool_detail, &MempoolDetail::updateFeeTable);
312+
connect(model, &ClientModel::walletTxChanged, m_mempool_detail, &MempoolDetail::updateTxTable); // Connect new signal
312313
}
313314

314315
// Connect to wallet transaction changes

src/qt/mempooltxtables.cpp

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
2+
// Copyright (c) 2023 The Bitcoin Core developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#include <qt/mempooltxtables.h>
7+
8+
#include <qt/guiutil.h>
9+
#include <qt/bitcoinunits.h> // New include for BitcoinUnits
10+
#include <QApplication>
11+
#include <QDebug>
12+
13+
MempoolTxTableModel::MempoolTxTableModel(QObject* parent)
14+
: QAbstractTableModel(parent)
15+
{
16+
}
17+
18+
MempoolTxTableModel::~MempoolTxTableModel() = default;
19+
20+
int MempoolTxTableModel::rowCount(const QModelIndex& parent) const
21+
{
22+
if (parent.isValid()) {
23+
return 0;
24+
}
25+
return m_tx_data.size();
26+
}
27+
28+
int MempoolTxTableModel::columnCount(const QModelIndex& parent) const
29+
{
30+
if (parent.isValid()) {
31+
return 0;
32+
}
33+
return columns.length();
34+
}
35+
36+
QVariant MempoolTxTableModel::data(const QModelIndex& index, int role) const
37+
{
38+
if(!index.isValid())
39+
return QVariant();
40+
41+
const interfaces::WalletTx* wtx = static_cast<const interfaces::WalletTx*>(index.internalPointer());
42+
43+
const auto column = static_cast<ColumnIndex>(index.column());
44+
if (role == Qt::DisplayRole) {
45+
switch (column) {
46+
case TxID:
47+
return QString::fromStdString(wtx->tx->GetHash().ToString());
48+
case Amount:
49+
return BitcoinUnits::formatWithUnit(BitcoinUnits::Unit::BTC, wtx->credit - wtx->debit, false, BitcoinUnits::SeparatorStyle::ALWAYS);
50+
case Fee:
51+
{
52+
CAmount fee = wtx->debit - wtx->credit - wtx->change;
53+
return BitcoinUnits::formatWithUnit(BitcoinUnits::Unit::BTC, fee, false, BitcoinUnits::SeparatorStyle::ALWAYS);
54+
}
55+
case Status:
56+
// For now, we'll just indicate if it's in the mempool. More detailed status can be added later.
57+
return tr("In Mempool");
58+
default:
59+
return QVariant();
60+
}
61+
} else if (role == OriginalIndexRole) {
62+
// We don't have a simple integer index for WalletTx, so we can return the TXID hash as a string
63+
return QString::fromStdString(wtx->tx->GetHash().ToString());
64+
} else if (role == Qt::TextAlignmentRole) {
65+
switch (column) {
66+
case TxID:
67+
return QVariant(Qt::AlignLeft | Qt::AlignVCenter);
68+
case Amount:
69+
case Fee:
70+
return QVariant(Qt::AlignRight | Qt::AlignVCenter);
71+
case Status:
72+
return QVariant(Qt::AlignCenter | Qt::AlignVCenter);
73+
default:
74+
return QVariant();
75+
}
76+
}
77+
return QVariant();
78+
}
79+
80+
QVariant MempoolTxTableModel::headerData(int section, Qt::Orientation orientation, int role) const
81+
{
82+
if(orientation == Qt::Horizontal)
83+
{
84+
if(role == Qt::DisplayRole && section < columns.size())
85+
{
86+
return columns[section];
87+
}
88+
}
89+
return QVariant();
90+
}
91+
92+
Qt::ItemFlags MempoolTxTableModel::flags(const QModelIndex &index) const
93+
{
94+
if (!index.isValid()) return Qt::NoItemFlags;
95+
96+
Qt::ItemFlags retval = Qt::ItemIsSelectable | Qt::ItemIsEnabled;
97+
return retval;
98+
}
99+
100+
QModelIndex MempoolTxTableModel::index(int row, int column, const QModelIndex& parent) const
101+
{
102+
Q_UNUSED(parent);
103+
104+
if (0 <= row && row < rowCount() && 0 <= column && column < columnCount()) {
105+
return createIndex(row, column, const_cast<interfaces::WalletTx*>(&m_tx_data[row]));
106+
}
107+
108+
return QModelIndex();
109+
}
110+
111+
void MempoolTxTableModel::updateModel(const std::set<interfaces::WalletTx>& wallet_transactions)
112+
{
113+
beginResetModel();
114+
m_tx_data.clear();
115+
for (const auto& wtx : wallet_transactions) {
116+
// Only add transactions that are currently in the mempool
117+
// This logic might need to be more sophisticated if we want to show other statuses
118+
// For now, we assume the set only contains mempool transactions or we filter here.
119+
// The `drawWalletTxIndicators` in MempoolStats already checks for in_mempool status.
120+
// We'll rely on that for now, or add a similar check here if needed.
121+
m_tx_data.append(wtx);
122+
}
123+
endResetModel();
124+
}

src/qt/mempooltxtables.h

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
2+
// Copyright (c) 2023 The Bitcoin Core developers
3+
// Distributed under the MIT software license, see the accompanying
4+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
#ifndef BITCOIN_QT_MEMPOOLTXTABLES_H
7+
#define BITCOIN_QT_MEMPOOLTXTABLES_H
8+
9+
#include <QAbstractTableModel>
10+
#include <QList>
11+
#include <QModelIndex>
12+
#include <QStringList>
13+
#include <QVariant>
14+
15+
#include <interfaces/wallet.h>
16+
17+
/**
18+
Qt model providing information about mempool transactions from the active wallet.
19+
*/
20+
class MempoolTxTableModel : public QAbstractTableModel
21+
{
22+
Q_OBJECT
23+
24+
public:
25+
explicit MempoolTxTableModel(QObject* parent = nullptr);
26+
~MempoolTxTableModel();
27+
28+
enum ColumnIndex {
29+
TxID = 0,
30+
Amount,
31+
Fee,
32+
Status,
33+
OriginalIndexRole = Qt::UserRole
34+
};
35+
36+
/** @name Methods overridden from QAbstractTableModel
37+
@{*/
38+
int rowCount(const QModelIndex& parent = QModelIndex()) const override;
39+
int columnCount(const QModelIndex& parent = QModelIndex()) const override;
40+
QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override;
41+
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
42+
QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override;
43+
Qt::ItemFlags flags(const QModelIndex &index) const override;
44+
/*@}*/
45+
46+
public Q_SLOTS:
47+
void updateModel(const std::set<interfaces::WalletTx>& wallet_transactions);
48+
49+
private:
50+
QList<interfaces::WalletTx> m_tx_data;
51+
const QStringList columns{
52+
/*: Title of Mempool Tx Table column which contains the transaction ID. */
53+
tr("TXID"),
54+
/*: Title of Mempool Tx Table column which contains the amount. */
55+
tr("Amount"),
56+
/*: Title of Mempool Tx Table column which contains the fee. */
57+
tr("Fee"),
58+
/*: Title of Mempool Tx Table column which contains the status. */
59+
tr("Status")
60+
};
61+
};
62+
63+
#endif // BITCOIN_QT_MEMPOOLTXTABLES_H

0 commit comments

Comments
 (0)