You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

paymentserver.h 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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. #ifndef PAYMENTSERVER_H
  5. #define PAYMENTSERVER_H
  6. // This class handles payment requests from clicking on
  7. // bitcoin: URIs
  8. //
  9. // This is somewhat tricky, because we have to deal with
  10. // the situation where the user clicks on a link during
  11. // startup/initialization, when the splash-screen is up
  12. // but the main window (and the Send Coins tab) is not.
  13. //
  14. // So, the strategy is:
  15. //
  16. // Create the server, and register the event handler,
  17. // when the application is created. Save any URIs
  18. // received at or during startup in a list.
  19. //
  20. // When startup is finished and the main window is
  21. // shown, a signal is sent to slot uiReady(), which
  22. // emits a receivedURL() signal for any payment
  23. // requests that happened during startup.
  24. //
  25. // After startup, receivedURL() happens as usual.
  26. //
  27. // This class has one more feature: a static
  28. // method that finds URIs passed in the command line
  29. // and, if a server is running in another process,
  30. // sends them to the server.
  31. //
  32. #include "paymentrequestplus.h"
  33. #include "walletmodel.h"
  34. #include <QObject>
  35. #include <QString>
  36. class OptionsModel;
  37. QT_BEGIN_NAMESPACE
  38. class QApplication;
  39. class QByteArray;
  40. class QLocalServer;
  41. class QNetworkAccessManager;
  42. class QNetworkReply;
  43. class QSslError;
  44. class QUrl;
  45. QT_END_NAMESPACE
  46. class CWallet;
  47. class PaymentServer : public QObject
  48. {
  49. Q_OBJECT
  50. public:
  51. // Parse URIs on command line
  52. // Returns false on error
  53. static bool ipcParseCommandLine(int argc, char *argv[]);
  54. // Returns true if there were URIs on the command line
  55. // which were successfully sent to an already-running
  56. // process.
  57. // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
  58. // will be called so we startup in the right mode.
  59. static bool ipcSendCommandLine();
  60. // parent should be QApplication object
  61. PaymentServer(QObject* parent, bool startLocalServer = true);
  62. ~PaymentServer();
  63. // Load root certificate authorities. Pass NULL (default)
  64. // to read from the file specified in the -rootcertificates setting,
  65. // or, if that's not set, to use the system default root certificates.
  66. // If you pass in a store, you should not X509_STORE_free it: it will be
  67. // freed either at exit or when another set of CAs are loaded.
  68. static void LoadRootCAs(X509_STORE* store = NULL);
  69. // Return certificate store
  70. static X509_STORE* getCertStore() { return certStore; }
  71. // OptionsModel is used for getting proxy settings and display unit
  72. void setOptionsModel(OptionsModel *optionsModel);
  73. signals:
  74. // Fired when a valid payment request is received
  75. void receivedPaymentRequest(SendCoinsRecipient);
  76. // Fired when a valid PaymentACK is received
  77. void receivedPaymentACK(const QString &paymentACKMsg);
  78. // Fired when a message should be reported to the user
  79. void message(const QString &title, const QString &message, unsigned int style);
  80. public slots:
  81. // Signal this when the main window's UI is ready
  82. // to display payment requests to the user
  83. void uiReady();
  84. // Submit Payment message to a merchant, get back PaymentACK:
  85. void fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipient, QByteArray transaction);
  86. // Handle an incoming URI, URI with local file scheme or file
  87. void handleURIOrFile(const QString& s);
  88. private slots:
  89. void handleURIConnection();
  90. void netRequestFinished(QNetworkReply*);
  91. void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
  92. void handlePaymentACK(const QString& paymentACKMsg);
  93. protected:
  94. // Constructor registers this on the parent QApplication to
  95. // receive QEvent::FileOpen and QEvent:Drop events
  96. bool eventFilter(QObject *object, QEvent *event);
  97. private:
  98. static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);
  99. bool processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient);
  100. void fetchRequest(const QUrl& url);
  101. // Setup networking
  102. void initNetManager();
  103. bool saveURIs; // true during startup
  104. QLocalServer* uriServer;
  105. static X509_STORE* certStore; // Trusted root certificates
  106. static void freeCertStore();
  107. QNetworkAccessManager* netManager; // Used to fetch payment requests
  108. OptionsModel *optionsModel;
  109. };
  110. #endif // PAYMENTSERVER_H