]> Git Repo - VerusCoin.git/blob - src/qt/paymentserver.h
Merge pull request #5360
[VerusCoin.git] / src / qt / paymentserver.h
1 // Copyright (c) 2011-2014 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.
4
5 #ifndef BITCOIN_QT_PAYMENTSERVER_H
6 #define BITCOIN_QT_PAYMENTSERVER_H
7
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
23 // shown, a signal is sent to slot uiReady(), which
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 //
34
35 #include "paymentrequestplus.h"
36 #include "walletmodel.h"
37
38 #include <QObject>
39 #include <QString>
40
41 class OptionsModel;
42
43 class CWallet;
44
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
54
55 // BIP70 max payment request size in bytes (DoS protection)
56 extern const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE;
57
58 class PaymentServer : public QObject
59 {
60     Q_OBJECT
61
62 public:
63     // Parse URIs on command line
64     // Returns false on error
65     static void ipcParseCommandLine(int argc, char *argv[]);
66
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();
73
74     // parent should be QApplication object
75     PaymentServer(QObject* parent, bool startLocalServer = true);
76     ~PaymentServer();
77
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.
83     static void LoadRootCAs(X509_STORE* store = NULL);
84
85     // Return certificate store
86     static X509_STORE* getCertStore() { return certStore; }
87
88     // OptionsModel is used for getting proxy settings and display unit
89     void setOptionsModel(OptionsModel *optionsModel);
90
91     // This is now public, because we use it in paymentservertests.cpp
92     static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request);
93
94     // Verify that the payment request network matches the client network
95     static bool verifyNetwork(const payments::PaymentDetails& requestDetails);
96     // Verify if the payment request is expired
97     static bool verifyExpired(const payments::PaymentDetails& requestDetails);
98     // Verify the payment request amount is valid
99     static bool verifyAmount(const CAmount& requestAmount);
100
101 signals:
102     // Fired when a valid payment request is received
103     void receivedPaymentRequest(SendCoinsRecipient);
104
105     // Fired when a valid PaymentACK is received
106     void receivedPaymentACK(const QString &paymentACKMsg);
107
108     // Fired when a message should be reported to the user
109     void message(const QString &title, const QString &message, unsigned int style);
110
111 public slots:
112     // Signal this when the main window's UI is ready
113     // to display payment requests to the user
114     void uiReady();
115
116     // Submit Payment message to a merchant, get back PaymentACK:
117     void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
118
119     // Handle an incoming URI, URI with local file scheme or file
120     void handleURIOrFile(const QString& s);
121
122 private slots:
123     void handleURIConnection();
124     void netRequestFinished(QNetworkReply*);
125     void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
126     void handlePaymentACK(const QString& paymentACKMsg);
127
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
133 private:
134     bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
135     void fetchRequest(const QUrl& url);
136
137     // Setup networking
138     void initNetManager();
139
140     bool saveURIs;                      // true during startup
141     QLocalServer* uriServer;
142
143     static X509_STORE* certStore;       // Trusted root certificates
144     static void freeCertStore();
145
146     QNetworkAccessManager* netManager;  // Used to fetch payment requests
147
148     OptionsModel *optionsModel;
149 };
150
151 #endif // BITCOIN_QT_PAYMENTSERVER_H
This page took 0.032684 seconds and 4 git commands to generate.