Skip to content

Commit e0e235b

Browse files
committed
nodemodel: copy ProxyAddress methods into qml/
See #430 This code was merged into bitcoin/src in the gui-qml repository but should have been either been merged upstream into Bitcoin Core or just implemented in the GUI, which is what we do in this commit.
1 parent 4de5fd6 commit e0e235b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

qml/models/nodemodel.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,24 @@ void NodeModel::ConnectToNumConnectionsChangedSignal()
169169

170170
bool NodeModel::validateProxyAddress(QString address_port)
171171
{
172-
return m_node.validateProxyAddress(address_port.toStdString());
172+
uint16_t port{0};
173+
std::string addr_port{address_port.toStdString()};
174+
std::string hostname;
175+
// First, attempt to split the input address into hostname and port components.
176+
// We call SplitHostPort to validate that a port is provided in addr_port.
177+
// If either splitting fails or port is zero (not specified), return false.
178+
if (!SplitHostPort(addr_port, port, hostname) || !port) return false;
179+
180+
// Create a service endpoint (CService) from the address and port.
181+
// If port is missing in addr_port, DEFAULT_PROXY_PORT is used as the fallback.
182+
CService serv(LookupNumeric(addr_port, DEFAULT_PROXY_PORT));
183+
184+
// Construct the Proxy with the service endpoint and return if it's valid
185+
Proxy addrProxy = Proxy(serv, true);
186+
return addrProxy.IsValid();
173187
}
174188

175189
QString NodeModel::defaultProxyAddress()
176190
{
177-
return QString::fromStdString(m_node.defaultProxyAddress());
191+
return QString::fromStdString(std::string(DEFAULT_PROXY_HOST) + ":" + util::ToString(DEFAULT_PROXY_PORT));
178192
}

qml/models/nodemodel.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
#include <QObject>
1515
#include <QString>
1616

17+
const char DEFAULT_PROXY_HOST[] = "127.0.0.1";
18+
constexpr uint16_t DEFAULT_PROXY_PORT = 9050;
19+
1720
QT_BEGIN_NAMESPACE
1821
class QTimerEvent;
1922
QT_END_NAMESPACE

0 commit comments

Comments
 (0)