]>
Commit | Line | Data |
---|---|---|
e592d43f WL |
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. | |
4 | ||
8269a095 GA |
5 | #ifndef PAYMENTSERVER_H |
6 | #define PAYMENTSERVER_H | |
8269a095 GA |
7 | // This class handles payment requests from clicking on |
8 | // bitcoin: URIs | |
9 | // | |
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. | |
14 | // | |
15 | // So, the strategy is: | |
16 | // | |
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. | |
20 | // | |
21 | // When startup is finished and the main window is | |
bdd0c59a | 22 | // shown, a signal is sent to slot uiReady(), which |
8269a095 GA |
23 | // emits a receivedURL() signal for any payment |
24 | // requests that happened during startup. | |
25 | // | |
26 | // After startup, receivedURL() happens as usual. | |
27 | // | |
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. | |
32 | // | |
8269a095 | 33 | |
a41d5fe0 GA |
34 | #include "paymentrequestplus.h" |
35 | #include "walletmodel.h" | |
36 | ||
51ed9ec9 BD |
37 | #include <QObject> |
38 | #include <QString> | |
39 | ||
a41d5fe0 | 40 | class OptionsModel; |
d78900cc PK |
41 | |
42 | QT_BEGIN_NAMESPACE | |
8269a095 | 43 | class QApplication; |
a41d5fe0 | 44 | class QByteArray; |
8269a095 | 45 | class QLocalServer; |
a41d5fe0 GA |
46 | class QNetworkAccessManager; |
47 | class QNetworkReply; | |
48 | class QSslError; | |
49 | class QUrl; | |
d78900cc | 50 | QT_END_NAMESPACE |
8269a095 | 51 | |
51ed9ec9 BD |
52 | class CWallet; |
53 | ||
8269a095 GA |
54 | class PaymentServer : public QObject |
55 | { | |
56 | Q_OBJECT | |
b001c871 | 57 | |
8269a095 GA |
58 | public: |
59 | // Returns true if there were URIs on the command line | |
60 | // which were successfully sent to an already-running | |
61 | // process. | |
a41d5fe0 GA |
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[]); | |
8269a095 | 65 | |
d78900cc PK |
66 | // parent should be QApplication object |
67 | PaymentServer(QObject* parent, bool startLocalServer = true); | |
a41d5fe0 | 68 | ~PaymentServer(); |
8269a095 | 69 | |
a41d5fe0 GA |
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. | |
d78900cc | 75 | static void LoadRootCAs(X509_STORE* store = NULL); |
a41d5fe0 GA |
76 | |
77 | // Return certificate store | |
78 | static X509_STORE* getCertStore() { return certStore; } | |
79 | ||
bdd0c59a PK |
80 | // Setup networking |
81 | void initNetManager(); | |
a41d5fe0 GA |
82 | |
83 | // Constructor registers this on the parent QApplication to | |
84 | // receive QEvent::FileOpen events | |
8269a095 GA |
85 | bool eventFilter(QObject *object, QEvent *event); |
86 | ||
bdd0c59a PK |
87 | // OptionsModel is used for getting proxy settings and display unit |
88 | void setOptionsModel(OptionsModel *optionsModel); | |
89 | ||
8269a095 | 90 | signals: |
a41d5fe0 GA |
91 | // Fired when a valid payment request is received |
92 | void receivedPaymentRequest(SendCoinsRecipient); | |
93 | ||
94 | // Fired when a valid PaymentACK is received | |
08dd1b7b | 95 | void receivedPaymentACK(const QString &paymentACKMsg); |
a41d5fe0 | 96 | |
95d4a2be PK |
97 | // Fired when a message should be reported to the user |
98 | void message(const QString &title, const QString &message, unsigned int style); | |
8269a095 GA |
99 | |
100 | public slots: | |
101 | // Signal this when the main window's UI is ready | |
102 | // to display payment requests to the user | |
103 | void uiReady(); | |
104 | ||
a41d5fe0 GA |
105 | // Submit Payment message to a merchant, get back PaymentACK: |
106 | void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction); | |
107 | ||
8269a095 GA |
108 | private slots: |
109 | void handleURIConnection(); | |
a41d5fe0 GA |
110 | void netRequestFinished(QNetworkReply*); |
111 | void reportSslErrors(QNetworkReply*, const QList<QSslError> &); | |
08dd1b7b | 112 | void handlePaymentACK(const QString& paymentACKMsg); |
a41d5fe0 GA |
113 | |
114 | private: | |
115 | static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request); | |
952d2cdb | 116 | bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient); |
a41d5fe0 GA |
117 | void handleURIOrFile(const QString& s); |
118 | void fetchRequest(const QUrl& url); | |
119 | ||
bdd0c59a | 120 | bool saveURIs; // true during startup |
a41d5fe0 | 121 | QLocalServer* uriServer; |
bdd0c59a PK |
122 | |
123 | static X509_STORE* certStore; // Trusted root certificates | |
a41d5fe0 GA |
124 | static void freeCertStore(); |
125 | ||
bdd0c59a PK |
126 | QNetworkAccessManager* netManager; // Used to fetch payment requests |
127 | ||
128 | OptionsModel *optionsModel; | |
8269a095 GA |
129 | }; |
130 | ||
131 | #endif // PAYMENTSERVER_H |