Remove includes in .cpp files for things the corresponding .h file already included
[bitcoinplatinum.git] / src / qt / paymentserver.h
blob9adef9743d3bb4c25232297d3e3b6dcca2c502c3
1 // Copyright (c) 2011-2016 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_QT_PAYMENTSERVER_H
6 #define BITCOIN_QT_PAYMENTSERVER_H
8 // This class handles payment requests from clicking on
9 // bitcoin: URIs
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.
16 // So, the strategy is:
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.
22 // When startup is finished and the main window is
23 // shown, a signal is sent to slot uiReady(), which
24 // emits a receivedURI() signal for any payment
25 // requests that happened during startup.
27 // After startup, receivedURI() happens as usual.
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.
35 #include <qt/paymentrequestplus.h>
36 #include <qt/walletmodel.h>
38 #include <QObject>
39 #include <QString>
41 class OptionsModel;
43 class CWallet;
45 QT_BEGIN_NAMESPACE
46 class QApplication;
47 class QByteArray;
48 class QLocalServer;
49 class QNetworkAccessManager;
50 class QNetworkReply;
51 class QSslError;
52 class QUrl;
53 QT_END_NAMESPACE
55 // BIP70 max payment request size in bytes (DoS protection)
56 static const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE = 50000;
58 class PaymentServer : public QObject
60 Q_OBJECT
62 public:
63 // Parse URIs on command line
64 // Returns false on error
65 static void ipcParseCommandLine(int argc, char *argv[]);
67 // Returns true if there were URIs on the command line
68 // which were successfully sent to an already-running
69 // process.
70 // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
71 // will be called so we startup in the right mode.
72 static bool ipcSendCommandLine();
74 // parent should be QApplication object
75 explicit PaymentServer(QObject* parent, bool startLocalServer = true);
76 ~PaymentServer();
78 // Load root certificate authorities. Pass nullptr (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.
83 static void LoadRootCAs(X509_STORE* store = nullptr);
85 // Return certificate store
86 static X509_STORE* getCertStore();
88 // OptionsModel is used for getting proxy settings and display unit
89 void setOptionsModel(OptionsModel *optionsModel);
91 // Verify that the payment request network matches the client network
92 static bool verifyNetwork(const payments::PaymentDetails& requestDetails);
93 // Verify if the payment request is expired
94 static bool verifyExpired(const payments::PaymentDetails& requestDetails);
95 // Verify the payment request size is valid as per BIP70
96 static bool verifySize(qint64 requestSize);
97 // Verify the payment request amount is valid
98 static bool verifyAmount(const CAmount& requestAmount);
100 Q_SIGNALS:
101 // Fired when a valid payment request is received
102 void receivedPaymentRequest(SendCoinsRecipient);
104 // Fired when a valid PaymentACK is received
105 void receivedPaymentACK(const QString &paymentACKMsg);
107 // Fired when a message should be reported to the user
108 void message(const QString &title, const QString &message, unsigned int style);
110 public Q_SLOTS:
111 // Signal this when the main window's UI is ready
112 // to display payment requests to the user
113 void uiReady();
115 // Submit Payment message to a merchant, get back PaymentACK:
116 void fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& recipient, QByteArray transaction);
118 // Handle an incoming URI, URI with local file scheme or file
119 void handleURIOrFile(const QString& s);
121 private Q_SLOTS:
122 void handleURIConnection();
123 void netRequestFinished(QNetworkReply*);
124 void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
125 void handlePaymentACK(const QString& paymentACKMsg);
127 protected:
128 // Constructor registers this on the parent QApplication to
129 // receive QEvent::FileOpen and QEvent:Drop events
130 bool eventFilter(QObject *object, QEvent *event);
132 private:
133 static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request);
134 bool processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient);
135 void fetchRequest(const QUrl& url);
137 // Setup networking
138 void initNetManager();
140 bool saveURIs; // true during startup
141 QLocalServer* uriServer;
143 QNetworkAccessManager* netManager; // Used to fetch payment requests
145 OptionsModel *optionsModel;
148 #endif // BITCOIN_QT_PAYMENTSERVER_H