From a981af4e6fd0047bc3e96468db48dd7820dac808 Mon Sep 17 00:00:00 2001 From: Vasil Dimov Date: Mon, 6 Mar 2023 12:49:39 +0100 Subject: [PATCH] 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 --- src/qt/bantablemodel.cpp | 6 ++++++ src/qt/bantablemodel.h | 2 ++ src/qt/rpcconsole.cpp | 19 +++++++------------ 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 4f57cd4457..d68ca1e2ea 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -178,3 +178,9 @@ bool BanTableModel::shouldShow() { return priv->size() > 0; } + +bool BanTableModel::unban(const QModelIndex& index) +{ + CCombinedBan* ban{static_cast(index.internalPointer())}; + return ban != nullptr && m_node.unban(ban->subnet); +} diff --git a/src/qt/bantablemodel.h b/src/qt/bantablemodel.h index 0a30905172..51f925bfa8 100644 --- a/src/qt/bantablemodel.h +++ b/src/qt/bantablemodel.h @@ -68,6 +68,8 @@ public: bool shouldShow(); + bool unban(const QModelIndex& index); + public Q_SLOTS: void refresh(); diff --git a/src/qt/rpcconsole.cpp b/src/qt/rpcconsole.cpp index b46a3c039b..0e712062af 100644 --- a/src/qt/rpcconsole.cpp +++ b/src/qt/rpcconsole.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -1308,17 +1307,13 @@ void RPCConsole::unbanSelectedNode() // Get selected ban addresses QList nodes = GUIUtil::getEntryData(ui->banlistWidget, BanTableModel::Address); - for(int i = 0; i < nodes.count(); i++) - { - // Get currently selected ban address - QString strNode = nodes.at(i).data().toString(); - CSubNet possibleSubnet; - - LookupSubNet(strNode.toStdString(), possibleSubnet); - if (possibleSubnet.IsValid() && m_node.unban(possibleSubnet)) - { - clientModel->getBanTableModel()->refresh(); - } + BanTableModel* ban_table_model{clientModel->getBanTableModel()}; + bool unbanned{false}; + for (const auto& node_index : nodes) { + unbanned |= ban_table_model->unban(node_index); + } + if (unbanned) { + ban_table_model->refresh(); } }