Dash Core Source Documentation (0.16.0.1)

Find detailed information regarding the Dash Core source code.

paymentserver.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2015 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 // dash: 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 #include <qt/paymentrequestplus.h>
36 #include <qt/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 static const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE = 50000;
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  explicit PaymentServer(QObject* parent, bool startLocalServer = true);
77 
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);
84 
85  // Return certificate store
86  static X509_STORE* getCertStore();
87 
88  // OptionsModel is used for getting proxy settings and display unit
90 
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);
99 
100 Q_SIGNALS:
101  // Fired when a valid payment request is received
103 
104  // Fired when a valid PaymentACK is received
105  void receivedPaymentACK(const QString &paymentACKMsg);
106 
107  // Fired when a message should be reported to the user
108  void message(const QString &title, const QString &message, unsigned int style);
109 
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();
114 
115  // Submit Payment message to a merchant, get back PaymentACK:
116  void fetchPaymentACK(CWallet* wallet, const SendCoinsRecipient& recipient, QByteArray transaction);
117 
118  // Handle an incoming URI, URI with local file scheme or file
119  void handleURIOrFile(const QString& s);
120 
121 private Q_SLOTS:
122  void handleURIConnection();
123  void netRequestFinished(QNetworkReply*);
124  void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
125  void handlePaymentACK(const QString& paymentACKMsg);
126 
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);
131 
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);
136 
137  // Setup networking
138  void initNetManager();
139 
140  bool saveURIs; // true during startup
141  QLocalServer* uriServer;
142 
143  QNetworkAccessManager* netManager; // Used to fetch payment requests
144 
146 };
147 
148 #endif // BITCOIN_QT_PAYMENTSERVER_H
static void LoadRootCAs(X509_STORE *store=nullptr)
static bool verifyAmount(const CAmount &requestAmount)
void message(const QString &title, const QString &message, unsigned int style)
static bool verifyNetwork(const payments::PaymentDetails &requestDetails)
void setOptionsModel(OptionsModel *optionsModel)
bool processPaymentRequest(const PaymentRequestPlus &request, SendCoinsRecipient &recipient)
bool eventFilter(QObject *object, QEvent *event)
void handlePaymentACK(const QString &paymentACKMsg)
void receivedPaymentACK(const QString &paymentACKMsg)
void receivedPaymentRequest(SendCoinsRecipient)
static void ipcParseCommandLine(int argc, char *argv[])
QLocalServer * uriServer
static QT_END_NAMESPACE const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE
Definition: paymentserver.h:56
void handleURIOrFile(const QString &s)
static bool ipcSendCommandLine()
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void netRequestFinished(QNetworkReply *)
static bool readPaymentRequestFromFile(const QString &filename, PaymentRequestPlus &request)
void fetchRequest(const QUrl &url)
static bool verifyExpired(const payments::PaymentDetails &requestDetails)
PaymentServer(QObject *parent, bool startLocalServer=true)
static X509_STORE * getCertStore()
QNetworkAccessManager * netManager
void fetchPaymentACK(CWallet *wallet, const SendCoinsRecipient &recipient, QByteArray transaction)
void reportSslErrors(QNetworkReply *, const QList< QSslError > &)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:25
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:715
void handleURIConnection()
static bool verifySize(qint64 requestSize)
OptionsModel * optionsModel
Released under the MIT license