Skip to content

Commit a981af4

Browse files
vasildfurszy
andcommitted
gui: use the stored CSubNet entry when unbanning
The previous code visualized the `CSubNet` object as string, then parsed that string back to `CSubNet`. This is sub-optimal given that the original `CSubNet` object can be used directly instead. This avoids calling `LookupSubNet()` from the GUI. Co-authored-by: furszy <[email protected]>
1 parent 40c6c85 commit a981af4

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

src/qt/bantablemodel.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,9 @@ bool BanTableModel::shouldShow()
178178
{
179179
return priv->size() > 0;
180180
}
181+
182+
bool BanTableModel::unban(const QModelIndex& index)
183+
{
184+
CCombinedBan* ban{static_cast<CCombinedBan*>(index.internalPointer())};
185+
return ban != nullptr && m_node.unban(ban->subnet);
186+
}

src/qt/bantablemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ class BanTableModel : public QAbstractTableModel
6868

6969
bool shouldShow();
7070

71+
bool unban(const QModelIndex& index);
72+
7173
public Q_SLOTS:
7274
void refresh();
7375

src/qt/rpcconsole.cpp

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include <chainparams.h>
1313
#include <interfaces/node.h>
14-
#include <netbase.h>
1514
#include <qt/bantablemodel.h>
1615
#include <qt/clientmodel.h>
1716
#include <qt/guiutil.h>
@@ -1308,17 +1307,13 @@ void RPCConsole::unbanSelectedNode()
13081307

13091308
// Get selected ban addresses
13101309
QList<QModelIndex> nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address);
1311-
for(int i = 0; i < nodes.count(); i++)
1312-
{
1313-
// Get currently selected ban address
1314-
QString strNode = nodes.at(i).data().toString();
1315-
CSubNet possibleSubnet;
1316-
1317-
LookupSubNet(strNode.toStdString(), possibleSubnet);
1318-
if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet))
1319-
{
1320-
clientModel->getBanTableModel()->refresh();
1321-
}
1310+
BanTableModel* ban_table_model{clientModel->getBanTableModel()};
1311+
bool unbanned{false};
1312+
for (const auto& node_index : nodes) {
1313+
unbanned |= ban_table_model->unban(node_index);
1314+
}
1315+
if (unbanned) {
1316+
ban_table_model->refresh();
13221317
}
13231318
}
13241319

0 commit comments

Comments
 (0)