22// Distributed under the MIT software license, see the accompanying
33// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44
5+ #if defined(HAVE_CONFIG_H)
6+ #include < config/bitcoin-config.h>
7+ #endif
8+
59#include < qt/paymentserver.h>
610
711#include < qt/bitcoinunits.h>
4549
4650const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000 ; // milliseconds
4751const QString BITCOIN_IPC_PREFIX (" bitcoin:" );
52+ #ifdef ENABLE_BIP70
4853// BIP70 payment protocol messages
4954const char * BIP70_MESSAGE_PAYMENTACK = " PaymentACK" ;
5055const char * BIP70_MESSAGE_PAYMENTREQUEST = " PaymentRequest" ;
@@ -67,6 +72,7 @@ namespace // Anon namespace
6772{
6873 std::unique_ptr<X509_STORE, X509StoreDeleter> certStore;
6974}
75+ #endif
7076
7177//
7278// Create a name that is unique for:
@@ -93,6 +99,7 @@ static QString ipcServerName()
9399
94100static QList<QString> savedPaymentRequests;
95101
102+ #ifdef ENABLE_BIP70
96103static void ReportInvalidCertificate (const QSslCertificate& cert)
97104{
98105 qDebug () << QString (" %1: Payment server found an invalid certificate: " ).arg (__func__) << cert.serialNumber () << cert.subjectInfo (QSslCertificate::CommonName) << cert.subjectInfo (QSslCertificate::DistinguishedNameQualifier) << cert.subjectInfo (QSslCertificate::OrganizationalUnitName);
@@ -180,6 +187,7 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
180187 // or use Qt's blacklist?
181188 // "certificate stapling" with server-side caching is more efficient
182189}
190+ #endif
183191
184192//
185193// Sending to the server is done synchronously, at startup.
@@ -221,6 +229,7 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
221229 }
222230 }
223231 }
232+ #ifdef ENABLE_BIP70
224233 else if (QFile::exists (arg)) // Filename
225234 {
226235 savedPaymentRequests.append (arg);
@@ -244,6 +253,7 @@ void PaymentServer::ipcParseCommandLine(interfaces::Node& node, int argc, char*
244253 // GUI hasn't started yet so we can't pop up a message box.
245254 qWarning () << " PaymentServer::ipcSendCommandLine: Payment request file does not exist: " << arg;
246255 }
256+ #endif
247257 }
248258}
249259
@@ -290,12 +300,16 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
290300 QObject(parent),
291301 saveURIs(true ),
292302 uriServer(0 ),
303+ #ifdef ENABLE_BIP70
293304 netManager (0 ),
305+ #endif
294306 optionsModel (0 )
295307{
308+ #ifdef ENABLE_BIP70
296309 // Verify that the version of the library that we linked against is
297310 // compatible with the version of the headers we compiled against.
298311 GOOGLE_PROTOBUF_VERIFY_VERSION;
312+ #endif
299313
300314 // Install global event filter to catch QFileOpenEvents
301315 // on Mac: sent when you click bitcoin: links
@@ -319,14 +333,18 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
319333 }
320334 else {
321335 connect (uriServer, &QLocalServer::newConnection, this , &PaymentServer::handleURIConnection);
336+ #ifdef ENABLE_BIP70
322337 connect (this , &PaymentServer::receivedPaymentACK, this , &PaymentServer::handlePaymentACK);
338+ #endif
323339 }
324340 }
325341}
326342
327343PaymentServer::~PaymentServer ()
328344{
345+ #ifdef ENABLE_BIP70
329346 google::protobuf::ShutdownProtobufLibrary ();
347+ #endif
330348}
331349
332350//
@@ -349,6 +367,7 @@ bool PaymentServer::eventFilter(QObject *object, QEvent *event)
349367 return QObject::eventFilter (object, event);
350368}
351369
370+ #ifdef ENABLE_BIP70
352371void PaymentServer::initNetManager ()
353372{
354373 if (!optionsModel)
@@ -372,10 +391,13 @@ void PaymentServer::initNetManager()
372391 connect (netManager, &QNetworkAccessManager::finished, this , &PaymentServer::netRequestFinished);
373392 connect (netManager, &QNetworkAccessManager::sslErrors, this , &PaymentServer::reportSslErrors);
374393}
394+ #endif
375395
376396void PaymentServer::uiReady ()
377397{
398+ #ifdef ENABLE_BIP70
378399 initNetManager ();
400+ #endif
379401
380402 saveURIs = false ;
381403 for (const QString& s : savedPaymentRequests)
@@ -403,6 +425,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
403425 QUrlQuery uri ((QUrl (s)));
404426 if (uri.hasQueryItem (" r" )) // payment request URI
405427 {
428+ #ifdef ENABLE_BIP70
406429 QByteArray temp;
407430 temp.append (uri.queryItemValue (" r" ));
408431 QString decoded = QUrl::fromPercentEncoding (temp);
@@ -420,7 +443,11 @@ void PaymentServer::handleURIOrFile(const QString& s)
420443 tr (" Payment request fetch URL is invalid: %1" ).arg (fetchUrl.toString ()),
421444 CClientUIInterface::ICON_WARNING);
422445 }
423-
446+ #else
447+ Q_EMIT message (tr (" URI handling" ),
448+ tr (" Cannot process payment request because BIP70 support was not compiled in." ),
449+ CClientUIInterface::ICON_WARNING);
450+ #endif
424451 return ;
425452 }
426453 else // normal URI
@@ -444,6 +471,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
444471 }
445472 }
446473
474+ #ifdef ENABLE_BIP70
447475 if (QFile::exists (s)) // payment request file
448476 {
449477 PaymentRequestPlus request;
@@ -459,6 +487,7 @@ void PaymentServer::handleURIOrFile(const QString& s)
459487
460488 return ;
461489 }
490+ #endif
462491}
463492
464493void PaymentServer::handleURIConnection ()
@@ -481,6 +510,7 @@ void PaymentServer::handleURIConnection()
481510 handleURIOrFile (msg);
482511}
483512
513+ #ifdef ENABLE_BIP70
484514//
485515// Warning: readPaymentRequestFromFile() is used in ipcSendCommandLine()
486516// so don't use "Q_EMIT message()", but "QMessageBox::"!
@@ -730,12 +760,14 @@ void PaymentServer::reportSslErrors(QNetworkReply* reply, const QList<QSslError>
730760 }
731761 Q_EMIT message (tr (" Network request error" ), errString, CClientUIInterface::MSG_ERROR);
732762}
763+ #endif
733764
734765void PaymentServer::setOptionsModel (OptionsModel *_optionsModel)
735766{
736767 this ->optionsModel = _optionsModel;
737768}
738769
770+ #ifdef ENABLE_BIP70
739771void PaymentServer::handlePaymentACK (const QString& paymentACKMsg)
740772{
741773 // currently we don't further process or store the paymentACK message
@@ -794,3 +826,4 @@ X509_STORE* PaymentServer::getCertStore()
794826{
795827 return certStore.get ();
796828}
829+ #endif
0 commit comments