1 // Copyright (c) 2011-2013 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef PAYMENTSERVER_H
6 #define PAYMENTSERVER_H
7 // This class handles payment requests from clicking on
10 // This is somewhat tricky, because we have to deal with
11 // the situation where the user clicks on a link during
12 // startup/initialization, when the splash-screen is up
13 // but the main window (and the Send Coins tab) is not.
15 // So, the strategy is:
17 // Create the server, and register the event handler,
18 // when the application is created. Save any URIs
19 // received at or during startup in a list.
21 // When startup is finished and the main window is
22 // shown, a signal is sent to slot uiReady(), which
23 // emits a receivedURL() signal for any payment
24 // requests that happened during startup.
26 // After startup, receivedURL() happens as usual.
28 // This class has one more feature: a static
29 // method that finds URIs passed in the command line
30 // and, if a server is running in another process,
31 // sends them to the server.
34 #include "paymentrequestplus.h"
35 #include "walletmodel.h"
46 class QNetworkAccessManager;
54 class PaymentServer : public QObject
59 // Returns true if there were URIs on the command line
60 // which were successfully sent to an already-running
62 // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
63 // will be called so we startup in the right mode.
64 static bool ipcSendCommandLine(int argc, char *argv[]);
66 // parent should be QApplication object
67 PaymentServer(QObject* parent, bool startLocalServer = true);
70 // Load root certificate authorities. Pass NULL (default)
71 // to read from the file specified in the -rootcertificates setting,
72 // or, if that's not set, to use the system default root certificates.
73 // If you pass in a store, you should not X509_STORE_free it: it will be
74 // freed either at exit or when another set of CAs are loaded.
75 static void LoadRootCAs(X509_STORE* store = NULL);
77 // Return certificate store
78 static X509_STORE* getCertStore() { return certStore; }
81 void initNetManager();
83 // Constructor registers this on the parent QApplication to
84 // receive QEvent::FileOpen events
85 bool eventFilter(QObject *object, QEvent *event);
87 // OptionsModel is used for getting proxy settings and display unit
88 void setOptionsModel(OptionsModel *optionsModel);
91 // Fired when a valid payment request is received
92 void receivedPaymentRequest(SendCoinsRecipient);
94 // Fired when a valid PaymentACK is received
95 void receivedPaymentACK(const QString &paymentACKMsg);
97 // Fired when a message should be reported to the user
98 void message(const QString &title, const QString &message, unsigned int style);
101 // Signal this when the main window's UI is ready
102 // to display payment requests to the user
105 // Submit Payment message to a merchant, get back PaymentACK:
106 void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
109 void handleURIConnection();
110 void netRequestFinished(QNetworkReply*);
111 void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
112 void handlePaymentACK(const QString& paymentACKMsg);
115 static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);
116 bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
117 void handleURIOrFile(const QString& s);
118 void fetchRequest(const QUrl& url);
120 bool saveURIs; // true during startup
121 QLocalServer* uriServer;
123 static X509_STORE* certStore; // Trusted root certificates
124 static void freeCertStore();
126 QNetworkAccessManager* netManager; // Used to fetch payment requests
128 OptionsModel *optionsModel;
131 #endif // PAYMENTSERVER_H