BSHA3  0.17.99
P2P Blockchain, based on Bitcoin
paymentserver.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2018 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 receivedURI() signal for any payment
25 // requests that happened during startup.
26 //
27 // After startup, receivedURI() 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 #if defined(HAVE_CONFIG_H)
36 #include <config/bitcoin-config.h>
37 #endif
38 
39 #ifdef ENABLE_BIP70
40 #include <qt/paymentrequestplus.h>
41 #endif
42 #include <qt/walletmodel.h>
43 
44 #include <QObject>
45 #include <QString>
46 
47 class OptionsModel;
48 
49 QT_BEGIN_NAMESPACE
50 class QApplication;
51 class QByteArray;
52 class QLocalServer;
53 class QNetworkAccessManager;
54 class QNetworkReply;
55 class QSslError;
56 class QUrl;
57 QT_END_NAMESPACE
58 
59 // BIP70 max payment request size in bytes (DoS protection)
60 static const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE = 50000;
61 
62 class PaymentServer : public QObject
63 {
64  Q_OBJECT
65 
66 public:
67  // Parse URIs on command line
68  // Returns false on error
69  static void ipcParseCommandLine(interfaces::Node& node, int argc, char *argv[]);
70 
71  // Returns true if there were URIs on the command line
72  // which were successfully sent to an already-running
73  // process.
74  // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
75  // will be called so we startup in the right mode.
76  static bool ipcSendCommandLine();
77 
78  // parent should be QApplication object
79  explicit PaymentServer(QObject* parent, bool startLocalServer = true);
81 
82  // OptionsModel is used for getting proxy settings and display unit
84 
85 #ifdef ENABLE_BIP70
86  // Load root certificate authorities. Pass nullptr (default)
87  // to read from the file specified in the -rootcertificates setting,
88  // or, if that's not set, to use the system default root certificates.
89  // If you pass in a store, you should not X509_STORE_free it: it will be
90  // freed either at exit or when another set of CAs are loaded.
91  static void LoadRootCAs(X509_STORE* store = nullptr);
92 
93  // Return certificate store
94  static X509_STORE* getCertStore();
95 
96  // Verify that the payment request network matches the client network
97  static bool verifyNetwork(interfaces::Node& node, const payments::PaymentDetails& requestDetails);
98  // Verify if the payment request is expired
99  static bool verifyExpired(const payments::PaymentDetails& requestDetails);
100  // Verify the payment request size is valid as per BIP70
101  static bool verifySize(qint64 requestSize);
102  // Verify the payment request amount is valid
103  static bool verifyAmount(const CAmount& requestAmount);
104 #endif
105 
106 Q_SIGNALS:
107  // Fired when a valid payment request is received
109 
110  // Fired when a message should be reported to the user
111  void message(const QString &title, const QString &message, unsigned int style);
112 
113 #ifdef ENABLE_BIP70
114  // Fired when a valid PaymentACK is received
115  void receivedPaymentACK(const QString &paymentACKMsg);
116 #endif
117 
118 public Q_SLOTS:
119  // Signal this when the main window's UI is ready
120  // to display payment requests to the user
121  void uiReady();
122 
123  // Handle an incoming URI, URI with local file scheme or file
124  void handleURIOrFile(const QString& s);
125 
126 #ifdef ENABLE_BIP70
127  // Submit Payment message to a merchant, get back PaymentACK:
128  void fetchPaymentACK(WalletModel* walletModel, const SendCoinsRecipient& recipient, QByteArray transaction);
129 #endif
130 
131 private Q_SLOTS:
132  void handleURIConnection();
133 #ifdef ENABLE_BIP70
134  void netRequestFinished(QNetworkReply*);
135  void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
136  void handlePaymentACK(const QString& paymentACKMsg);
137 #endif
138 
139 protected:
140  // Constructor registers this on the parent QApplication to
141  // receive QEvent::FileOpen and QEvent:Drop events
142  bool eventFilter(QObject *object, QEvent *event);
143 
144 private:
145  bool saveURIs; // true during startup
146  QLocalServer* uriServer;
148 
149 #ifdef ENABLE_BIP70
150  static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request);
151  bool processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient);
152  void fetchRequest(const QUrl& url);
153 
154  // Setup networking
155  void initNetManager();
156  QNetworkAccessManager* netManager; // Used to fetch payment requests
157 #endif
158 };
159 
160 #endif // BITCOIN_QT_PAYMENTSERVER_H
void message(const QString &title, const QString &message, unsigned int style)
void setOptionsModel(OptionsModel *optionsModel)
static void ipcParseCommandLine(interfaces::Node &node, int argc, char *argv[])
bool eventFilter(QObject *object, QEvent *event)
void receivedPaymentRequest(SendCoinsRecipient)
QLocalServer * uriServer
void handleURIOrFile(const QString &s)
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
const char * url
Definition: rpcconsole.cpp:53
PaymentServer(QObject *parent, bool startLocalServer=true)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:29
Interface to Bitcoin wallet from Qt view code.
Definition: walletmodel.h:125
void handleURIConnection()
OptionsModel * optionsModel
Top-level interface for a bitcoin node (bsha3d process).
Definition: node.h:35