Master Core  v0.0.9 - 2abfd2849db8ba7a83957c64eb976b406713c123
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
paymentserver.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Distributed under the MIT/X11 software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #ifndef PAYMENTSERVER_H
6 #define PAYMENTSERVER_H
7 // This class handles payment requests from clicking on
8 // bitcoin: URIs
9 //
10 // This is somewhat tricky, because we have to deal with
11 // the situation where the user clicks on a link during
12 // startup/initialization, when the splash-screen is up
13 // but the main window (and the Send Coins tab) is not.
14 //
15 // So, the strategy is:
16 //
17 // Create the server, and register the event handler,
18 // when the application is created. Save any URIs
19 // received at or during startup in a list.
20 //
21 // When startup is finished and the main window is
22 // shown, a signal is sent to slot uiReady(), which
23 // emits a receivedURL() signal for any payment
24 // requests that happened during startup.
25 //
26 // After startup, receivedURL() happens as usual.
27 //
28 // This class has one more feature: a static
29 // method that finds URIs passed in the command line
30 // and, if a server is running in another process,
31 // sends them to the server.
32 //
33 
34 #include "paymentrequestplus.h"
35 #include "walletmodel.h"
36 
37 #include <QObject>
38 #include <QString>
39 
40 class OptionsModel;
41 
42 QT_BEGIN_NAMESPACE
43 class QApplication;
44 class QByteArray;
45 class QLocalServer;
46 class QNetworkAccessManager;
47 class QNetworkReply;
48 class QSslError;
49 class QUrl;
50 QT_END_NAMESPACE
51 
52 class CWallet;
53 
54 class PaymentServer : public QObject
55 {
56  Q_OBJECT
57 
58 public:
59  // Parse URIs on command line
60  // Returns false on error
61  static bool ipcParseCommandLine(int argc, char *argv[]);
62 
63  // Returns true if there were URIs on the command line
64  // which were successfully sent to an already-running
65  // process.
66  // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
67  // will be called so we startup in the right mode.
68  static bool ipcSendCommandLine();
69 
70  // parent should be QApplication object
71  PaymentServer(QObject* parent, bool startLocalServer = true);
73 
74  // Load root certificate authorities. Pass NULL (default)
75  // to read from the file specified in the -rootcertificates setting,
76  // or, if that's not set, to use the system default root certificates.
77  // If you pass in a store, you should not X509_STORE_free it: it will be
78  // freed either at exit or when another set of CAs are loaded.
79  static void LoadRootCAs(X509_STORE* store = NULL);
80 
81  // Return certificate store
82  static X509_STORE* getCertStore() { return certStore; }
83 
84  // OptionsModel is used for getting proxy settings and display unit
86 
87 signals:
88  // Fired when a valid payment request is received
90 
91  // Fired when a valid PaymentACK is received
92  void receivedPaymentACK(const QString &paymentACKMsg);
93 
94  // Fired when a message should be reported to the user
95  void message(const QString &title, const QString &message, unsigned int style);
96 
97 public slots:
98  // Signal this when the main window's UI is ready
99  // to display payment requests to the user
100  void uiReady();
101 
102  // Submit Payment message to a merchant, get back PaymentACK:
103  void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
104 
105  // Handle an incoming URI, URI with local file scheme or file
106  void handleURIOrFile(const QString& s);
107 
108 private slots:
109  void handleURIConnection();
110  void netRequestFinished(QNetworkReply*);
111  void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
112  void handlePaymentACK(const QString& paymentACKMsg);
113 
114 protected:
115  // Constructor registers this on the parent QApplication to
116  // receive QEvent::FileOpen and QEvent:Drop events
117  bool eventFilter(QObject *object, QEvent *event);
118 
119 private:
120  static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);
122  void fetchRequest(const QUrl& url);
123 
124  // Setup networking
125  void initNetManager();
126 
127  bool saveURIs; // true during startup
128  QLocalServer* uriServer;
129 
130  static X509_STORE* certStore; // Trusted root certificates
131  static void freeCertStore();
132 
133  QNetworkAccessManager* netManager; // Used to fetch payment requests
134 
136 };
137 
138 #endif // PAYMENTSERVER_H
void message(const QString &title, const QString &message, unsigned int style)
static bool readPaymentRequest(const QString &filename, PaymentRequestPlus &request)
void setOptionsModel(OptionsModel *optionsModel)
bool eventFilter(QObject *object, QEvent *event)
void handlePaymentACK(const QString &paymentACKMsg)
void receivedPaymentACK(const QString &paymentACKMsg)
void receivedPaymentRequest(SendCoinsRecipient)
QLocalServer * uriServer
static X509_STORE * certStore
void handleURIOrFile(const QString &s)
static bool ipcParseCommandLine(int argc, char *argv[])
static void freeCertStore()
static bool ipcSendCommandLine()
static X509_STORE * getCertStore()
Definition: paymentserver.h:82
const char * url
Definition: rpcconsole.cpp:35
void netRequestFinished(QNetworkReply *)
void fetchRequest(const QUrl &url)
PaymentServer(QObject *parent, bool startLocalServer=true)
QNetworkAccessManager * netManager
void reportSslErrors(QNetworkReply *, const QList< QSslError > &)
void fetchPaymentACK(CWallet *wallet, SendCoinsRecipient recipient, QByteArray transaction)
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:20
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:100
void handleURIConnection()
bool processPaymentRequest(PaymentRequestPlus &request, SendCoinsRecipient &recipient)
OptionsModel * optionsModel
static void LoadRootCAs(X509_STORE *store=NULL)