LCOV - code coverage report
Current view: top level - src/qt - paymentserver.h (source / functions) Hit Total Coverage
Test: total_coverage.info Lines: 0 2 0.0 %
Date: 2015-10-12 22:39:14 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       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           0 :     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           0 :     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             :     // 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
     102             :     void receivedPaymentRequest(SendCoinsRecipient);
     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, 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             :     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

Generated by: LCOV version 1.11