Skip to content

Commit

Permalink
Merge pull request #3286 from chromatic/payment-server-no-datadir
Browse files Browse the repository at this point in the history
Allow PaymentServer a parametric server name
  • Loading branch information
patricklodder committed Jun 30, 2023
2 parents 502a8a9 + 1c0cab7 commit f3f087a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
33 changes: 23 additions & 10 deletions src/qt/paymentserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,13 +298,7 @@ bool PaymentServer::ipcSendCommandLine()
return fResult;
}

PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
QObject(parent),
saveURIs(true),
uriServer(0),
netManager(0),
optionsModel(0)
{
void PaymentServer::initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer) {
// Verify that the version of the library that we linked against is
// compatible with the version of the headers we compiled against.
GOOGLE_PROTOBUF_VERIFY_VERSION;
Expand All @@ -315,13 +309,11 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
if (parent)
parent->installEventFilter(this);

QString name = ipcServerName();

if (startLocalServer)
{
uriServer = new QLocalServer(this);

if (!uriServer->listen(name)) {
if (!uriServer->listen(ipcServerName)) {
// constructor is called early in init, so don't use "Q_EMIT message()" here
QMessageBox::critical(0, tr("Payment request error"),
tr("Cannot start dogecoin: click-to-pay handler"));
Expand All @@ -333,6 +325,27 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
}
}

PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
QObject(parent),
saveURIs(true),
uriServer(0),
netManager(0),
optionsModel(0)
{
this->initializeServer(parent, ipcServerName(), startLocalServer);
}


PaymentServer::PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer) :
QObject(parent),
saveURIs(true),
uriServer(0),
netManager(0),
optionsModel(0)
{
this->initializeServer(parent, ipcServerName, startLocalServer);
}

PaymentServer::~PaymentServer()
{
google::protobuf::ShutdownProtobufLibrary();
Expand Down
3 changes: 3 additions & 0 deletions src/qt/paymentserver.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class PaymentServer : public QObject

// parent should be QApplication object
PaymentServer(QObject* parent, bool startLocalServer = true);
PaymentServer(QObject* parent, QString ipcServerName, bool startLocalServer = true);
~PaymentServer();

// Load root certificate authorities. Pass NULL (default)
Expand Down Expand Up @@ -138,6 +139,8 @@ private Q_SLOTS:
void initNetManager();

bool saveURIs; // true during startup

void initializeServer(QObject* parent, QString ipcServerName, bool startLocalServer);
QLocalServer* uriServer;

QNetworkAccessManager* netManager; // Used to fetch payment requests
Expand Down
2 changes: 1 addition & 1 deletion src/qt/test/paymentservertests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void PaymentServerTests::paymentServerTests()
{
SelectParams(CBaseChainParams::MAIN);
OptionsModel optionsModel;
PaymentServer* server = new PaymentServer(NULL, false);
PaymentServer* server = new PaymentServer(NULL, QString("testIPCServer"), false);
X509_STORE* caStore = X509_STORE_new();
X509_STORE_add_cert(caStore, parse_b64der_cert(caCert1_BASE64));
PaymentServer::LoadRootCAs(caStore);
Expand Down

0 comments on commit f3f087a

Please sign in to comment.