diff --git a/src/qt/bantablemodel.cpp b/src/qt/bantablemodel.cpp index 4f57cd4457..4592d29abc 100644 --- a/src/qt/bantablemodel.cpp +++ b/src/qt/bantablemodel.cpp @@ -43,7 +43,7 @@ public: /** Order (ascending or descending) to sort nodes by */ Qt::SortOrder sortOrder; - /** Pull a full list of banned nodes from CNode into our cache */ + /** Pull a full list of banned nodes from interfaces::Node into our cache */ void refreshBanlist(interfaces::Node& node) { banmap_t banMap; @@ -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..adb97ad1c0 100644 --- a/src/qt/bantablemodel.h +++ b/src/qt/bantablemodel.h @@ -37,7 +37,7 @@ private: }; /** - Qt model providing information about connected peers, similar to the + Qt model providing information about banned peers, similar to the "getpeerinfo" RPC call. Used by the rpc console UI. */ class BanTableModel : public QAbstractTableModel @@ -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(); } }