Anoncoin  0.9.4
P2P Digital Currency
paymentserver.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2014 The Bitcoin developers
2 // Copyright (c) 2013-2014 The Anoncoin Core developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef PAYMENTSERVER_H
7 #define PAYMENTSERVER_H
8 // This class handles payment requests from clicking on
9 // anoncoin: 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 QT_BEGIN_NAMESPACE
44 class QApplication;
45 class QByteArray;
46 class QLocalServer;
47 class QNetworkAccessManager;
48 class QNetworkReply;
49 class QSslError;
50 class QUrl;
51 QT_END_NAMESPACE
52 
53 class CWallet;
54 
55 class PaymentServer : public QObject
56 {
57  Q_OBJECT
58 
59 public:
60  // Parse URIs on command line
61  // Returns false on error
62  static bool ipcParseCommandLine(int argc, char *argv[]);
63 
64  // Returns true if there were URIs on the command line
65  // which were successfully sent to an already-running
66  // process.
67  // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
68  // will be called so we startup in the right mode.
69  static bool ipcSendCommandLine();
70 
71  // parent should be QApplication object
72  PaymentServer(QObject* parent, bool startLocalServer = true);
74 
75  // Load root certificate authorities. Pass NULL (default)
76  // to read from the file specified in the -rootcertificates setting,
77  // or, if that's not set, to use the system default root certificates.
78  // If you pass in a store, you should not X509_STORE_free it: it will be
79  // freed either at exit or when another set of CAs are loaded.
80  static void LoadRootCAs(X509_STORE* store = NULL);
81 
82  // Return certificate store
83  static X509_STORE* getCertStore() { return certStore; }
84 
85  // OptionsModel is used for getting proxy settings and display unit
87 
88 signals:
89  // Fired when a valid payment request is received
91 
92  // Fired when a valid PaymentACK is received
93  void receivedPaymentACK(const QString &paymentACKMsg);
94 
95  // Fired when a message should be reported to the user
96  void message(const QString &title, const QString &message, unsigned int style);
97 
98 public slots:
99  // Signal this when the main window's UI is ready
100  // to display payment requests to the user
101  void uiReady();
102 
103  // Submit Payment message to a merchant, get back PaymentACK:
104  void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
105 
106  // Handle an incoming URI, URI with local file scheme or file
107  void handleURIOrFile(const QString& s);
108 
109 private slots:
110  void handleURIConnection();
111  void netRequestFinished(QNetworkReply*);
112  void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
113  void handlePaymentACK(const QString& paymentACKMsg);
114 
115 protected:
116  // Constructor registers this on the parent QApplication to
117  // receive QEvent::FileOpen and QEvent:Drop events
118  bool eventFilter(QObject *object, QEvent *event);
119 
120 private:
121  static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);
123  void fetchRequest(const QUrl& url);
124 
125  // Setup networking
126  void initNetManager();
127 
128  bool saveURIs; // true during startup
129  QLocalServer* uriServer;
130 
131  static X509_STORE* certStore; // Trusted root certificates
132  static void freeCertStore();
133 
134  QNetworkAccessManager* netManager; // Used to fetch payment requests
135 
137 };
138 
139 #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:83
const char * url
Definition: rpcconsole.cpp:51
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 Anoncoin client.
Definition: optionsmodel.h:27
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:101
void handleURIConnection()
bool processPaymentRequest(PaymentRequestPlus &request, SendCoinsRecipient &recipient)
OptionsModel * optionsModel
static void LoadRootCAs(X509_STORE *store=NULL)