]>
Commit | Line | Data |
---|---|---|
f914f1a7 | 1 | // Copyright (c) 2011-2014 The Bitcoin Core developers |
5ec654b8 | 2 | // Distributed under the MIT software license, see the accompanying |
e592d43f WL |
3 | // file COPYING or http://www.opensource.org/licenses/mit-license.php. |
4 | ||
84738627 PJ |
5 | #ifndef BITCOIN_QT_PAYMENTSERVER_H |
6 | #define BITCOIN_QT_PAYMENTSERVER_H | |
7 | ||
8269a095 GA |
8 | // This class handles payment requests from clicking on |
9 | // bitcoin: URIs | |
10 | // | |
11 | // This is somewhat tricky, because we have to deal with | |
12 | // the situation where the user clicks on a link during | |
13 | // startup/initialization, when the splash-screen is up | |
14 | // but the main window (and the Send Coins tab) is not. | |
15 | // | |
16 | // So, the strategy is: | |
17 | // | |
18 | // Create the server, and register the event handler, | |
19 | // when the application is created. Save any URIs | |
20 | // received at or during startup in a list. | |
21 | // | |
22 | // When startup is finished and the main window is | |
bdd0c59a | 23 | // shown, a signal is sent to slot uiReady(), which |
8269a095 GA |
24 | // emits a receivedURL() signal for any payment |
25 | // requests that happened during startup. | |
26 | // | |
27 | // After startup, receivedURL() happens as usual. | |
28 | // | |
29 | // This class has one more feature: a static | |
30 | // method that finds URIs passed in the command line | |
31 | // and, if a server is running in another process, | |
32 | // sends them to the server. | |
33 | // | |
8269a095 | 34 | |
a41d5fe0 GA |
35 | #include "paymentrequestplus.h" |
36 | #include "walletmodel.h" | |
37 | ||
51ed9ec9 BD |
38 | #include <QObject> |
39 | #include <QString> | |
40 | ||
a41d5fe0 | 41 | class OptionsModel; |
d78900cc | 42 | |
5ec654b8 PK |
43 | class CWallet; |
44 | ||
d78900cc | 45 | QT_BEGIN_NAMESPACE |
8269a095 | 46 | class QApplication; |
a41d5fe0 | 47 | class QByteArray; |
8269a095 | 48 | class QLocalServer; |
a41d5fe0 GA |
49 | class QNetworkAccessManager; |
50 | class QNetworkReply; | |
51 | class QSslError; | |
52 | class QUrl; | |
d78900cc | 53 | QT_END_NAMESPACE |
8269a095 | 54 | |
4333e26c PK |
55 | // BIP70 max payment request size in bytes (DoS protection) |
56 | extern const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE; | |
57 | ||
8269a095 GA |
58 | class PaymentServer : public QObject |
59 | { | |
60 | Q_OBJECT | |
b001c871 | 61 | |
8269a095 | 62 | public: |
2102ab9f WL |
63 | // Parse URIs on command line |
64 | // Returns false on error | |
b82695b8 | 65 | static void ipcParseCommandLine(int argc, char *argv[]); |
2102ab9f | 66 | |
8269a095 GA |
67 | // Returns true if there were URIs on the command line |
68 | // which were successfully sent to an already-running | |
69 | // process. | |
a41d5fe0 GA |
70 | // Note: if a payment request is given, SelectParams(MAIN/TESTNET) |
71 | // will be called so we startup in the right mode. | |
2102ab9f | 72 | static bool ipcSendCommandLine(); |
8269a095 | 73 | |
d78900cc PK |
74 | // parent should be QApplication object |
75 | PaymentServer(QObject* parent, bool startLocalServer = true); | |
a41d5fe0 | 76 | ~PaymentServer(); |
8269a095 | 77 | |
a41d5fe0 GA |
78 | // Load root certificate authorities. Pass NULL (default) |
79 | // to read from the file specified in the -rootcertificates setting, | |
80 | // or, if that's not set, to use the system default root certificates. | |
81 | // If you pass in a store, you should not X509_STORE_free it: it will be | |
82 | // freed either at exit or when another set of CAs are loaded. | |
d78900cc | 83 | static void LoadRootCAs(X509_STORE* store = NULL); |
a41d5fe0 GA |
84 | |
85 | // Return certificate store | |
86 | static X509_STORE* getCertStore() { return certStore; } | |
87 | ||
bdd0c59a PK |
88 | // OptionsModel is used for getting proxy settings and display unit |
89 | void setOptionsModel(OptionsModel *optionsModel); | |
90 | ||
4333e26c PK |
91 | // This is now public, because we use it in paymentservertests.cpp |
92 | static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request); | |
93 | ||
17005bc0 PK |
94 | // Verify that the payment request network matches the client network |
95 | static bool verifyNetwork(const payments::PaymentDetails& requestDetails); | |
6715efb9 PK |
96 | // Verify if the payment request is expired |
97 | static bool verifyExpired(const payments::PaymentDetails& requestDetails); | |
a6516686 PK |
98 | // Verify the payment request amount is valid |
99 | static bool verifyAmount(const CAmount& requestAmount); | |
17005bc0 | 100 | |
e092f229 | 101 | Q_SIGNALS: |
a41d5fe0 GA |
102 | // Fired when a valid payment request is received |
103 | void receivedPaymentRequest(SendCoinsRecipient); | |
104 | ||
105 | // Fired when a valid PaymentACK is received | |
08dd1b7b | 106 | void receivedPaymentACK(const QString &paymentACKMsg); |
a41d5fe0 | 107 | |
95d4a2be PK |
108 | // Fired when a message should be reported to the user |
109 | void message(const QString &title, const QString &message, unsigned int style); | |
8269a095 | 110 | |
e092f229 | 111 | public Q_SLOTS: |
8269a095 GA |
112 | // Signal this when the main window's UI is ready |
113 | // to display payment requests to the user | |
114 | void uiReady(); | |
115 | ||
a41d5fe0 GA |
116 | // Submit Payment message to a merchant, get back PaymentACK: |
117 | void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction); | |
118 | ||
bd70562f | 119 | // Handle an incoming URI, URI with local file scheme or file |
4c603586 WL |
120 | void handleURIOrFile(const QString& s); |
121 | ||
e092f229 | 122 | private Q_SLOTS: |
8269a095 | 123 | void handleURIConnection(); |
a41d5fe0 GA |
124 | void netRequestFinished(QNetworkReply*); |
125 | void reportSslErrors(QNetworkReply*, const QList<QSslError> &); | |
08dd1b7b | 126 | void handlePaymentACK(const QString& paymentACKMsg); |
a41d5fe0 | 127 | |
4cf34110 PK |
128 | protected: |
129 | // Constructor registers this on the parent QApplication to | |
130 | // receive QEvent::FileOpen and QEvent:Drop events | |
131 | bool eventFilter(QObject *object, QEvent *event); | |
132 | ||
a41d5fe0 | 133 | private: |
35d15959 | 134 | bool processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient); |
a41d5fe0 GA |
135 | void fetchRequest(const QUrl& url); |
136 | ||
7634e0d8 PK |
137 | // Setup networking |
138 | void initNetManager(); | |
139 | ||
bdd0c59a | 140 | bool saveURIs; // true during startup |
a41d5fe0 | 141 | QLocalServer* uriServer; |
bdd0c59a PK |
142 | |
143 | static X509_STORE* certStore; // Trusted root certificates | |
a41d5fe0 GA |
144 | static void freeCertStore(); |
145 | ||
bdd0c59a PK |
146 | QNetworkAccessManager* netManager; // Used to fetch payment requests |
147 | ||
148 | OptionsModel *optionsModel; | |
8269a095 GA |
149 | }; |
150 | ||
84738627 | 151 | #endif // BITCOIN_QT_PAYMENTSERVER_H |