2018-01-02 18:12:05 +01:00
|
|
|
// Copyright (c) 2011-2017 The Bitcoin Core developers
|
2014-12-05 09:40:58 +01:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
2013-11-04 16:20:43 +01:00
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#ifndef BITCOIN_QT_PAYMENTSERVER_H
|
|
|
|
#define BITCOIN_QT_PAYMENTSERVER_H
|
|
|
|
|
2013-02-12 00:52:30 +01:00
|
|
|
// This class handles payment requests from clicking on
|
|
|
|
// bitcoin: URIs
|
|
|
|
//
|
|
|
|
// This is somewhat tricky, because we have to deal with
|
|
|
|
// the situation where the user clicks on a link during
|
|
|
|
// startup/initialization, when the splash-screen is up
|
|
|
|
// but the main window (and the Send Coins tab) is not.
|
|
|
|
//
|
|
|
|
// So, the strategy is:
|
|
|
|
//
|
|
|
|
// Create the server, and register the event handler,
|
|
|
|
// when the application is created. Save any URIs
|
|
|
|
// received at or during startup in a list.
|
|
|
|
//
|
|
|
|
// When startup is finished and the main window is
|
2013-08-24 15:07:17 +02:00
|
|
|
// shown, a signal is sent to slot uiReady(), which
|
2017-01-18 16:15:37 +01:00
|
|
|
// emits a receivedURI() signal for any payment
|
2013-02-12 00:52:30 +01:00
|
|
|
// requests that happened during startup.
|
|
|
|
//
|
2017-01-18 16:15:37 +01:00
|
|
|
// After startup, receivedURI() happens as usual.
|
2013-02-12 00:52:30 +01:00
|
|
|
//
|
|
|
|
// This class has one more feature: a static
|
|
|
|
// method that finds URIs passed in the command line
|
|
|
|
// and, if a server is running in another process,
|
|
|
|
// sends them to the server.
|
|
|
|
//
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <qt/paymentrequestplus.h>
|
|
|
|
#include <qt/walletmodel.h>
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2013-04-13 07:13:08 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QString>
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
class OptionsModel;
|
2013-08-31 01:11:12 +02:00
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2013-02-12 00:52:30 +01:00
|
|
|
class QApplication;
|
2013-07-22 08:50:39 +02:00
|
|
|
class QByteArray;
|
2013-02-12 00:52:30 +01:00
|
|
|
class QLocalServer;
|
2013-07-22 08:50:39 +02:00
|
|
|
class QNetworkAccessManager;
|
|
|
|
class QNetworkReply;
|
|
|
|
class QSslError;
|
|
|
|
class QUrl;
|
2013-08-31 01:11:12 +02:00
|
|
|
QT_END_NAMESPACE
|
2013-02-12 00:52:30 +01:00
|
|
|
|
2014-12-05 09:39:23 +01:00
|
|
|
// BIP70 max payment request size in bytes (DoS protection)
|
2017-02-17 20:54:32 +01:00
|
|
|
static const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE = 50000;
|
2014-12-05 09:39:23 +01:00
|
|
|
|
2013-02-12 00:52:30 +01:00
|
|
|
class PaymentServer : public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
2013-04-04 11:30:55 +02:00
|
|
|
|
2013-02-12 00:52:30 +01:00
|
|
|
public:
|
2014-01-05 12:37:51 +01:00
|
|
|
// Parse URIs on command line
|
|
|
|
// Returns false on error
|
2018-03-23 22:14:39 +01:00
|
|
|
static void ipcParseCommandLine(interface::Node& node, int argc, char *argv[]);
|
2014-01-05 12:37:51 +01:00
|
|
|
|
2013-02-12 00:52:30 +01:00
|
|
|
// Returns true if there were URIs on the command line
|
|
|
|
// which were successfully sent to an already-running
|
|
|
|
// process.
|
2013-07-22 08:50:39 +02:00
|
|
|
// Note: if a payment request is given, SelectParams(MAIN/TESTNET)
|
|
|
|
// will be called so we startup in the right mode.
|
2014-01-05 12:37:51 +01:00
|
|
|
static bool ipcSendCommandLine();
|
2013-02-12 00:52:30 +01:00
|
|
|
|
2013-08-31 01:11:12 +02:00
|
|
|
// parent should be QApplication object
|
2017-08-01 12:22:41 +02:00
|
|
|
explicit PaymentServer(QObject* parent, bool startLocalServer = true);
|
2013-07-22 08:50:39 +02:00
|
|
|
~PaymentServer();
|
2013-02-12 00:52:30 +01:00
|
|
|
|
2017-08-07 07:36:37 +02:00
|
|
|
// Load root certificate authorities. Pass nullptr (default)
|
2013-07-22 08:50:39 +02:00
|
|
|
// to read from the file specified in the -rootcertificates setting,
|
|
|
|
// or, if that's not set, to use the system default root certificates.
|
|
|
|
// If you pass in a store, you should not X509_STORE_free it: it will be
|
|
|
|
// freed either at exit or when another set of CAs are loaded.
|
2017-08-07 07:36:37 +02:00
|
|
|
static void LoadRootCAs(X509_STORE* store = nullptr);
|
2013-07-22 08:50:39 +02:00
|
|
|
|
|
|
|
// Return certificate store
|
2016-11-19 16:12:23 +01:00
|
|
|
static X509_STORE* getCertStore();
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2013-08-24 15:07:17 +02:00
|
|
|
// OptionsModel is used for getting proxy settings and display unit
|
|
|
|
void setOptionsModel(OptionsModel *optionsModel);
|
|
|
|
|
2015-01-12 08:43:08 +01:00
|
|
|
// Verify that the payment request network matches the client network
|
2018-03-23 22:14:39 +01:00
|
|
|
static bool verifyNetwork(interface::Node& node, const payments::PaymentDetails& requestDetails);
|
2015-01-08 14:42:04 +01:00
|
|
|
// Verify if the payment request is expired
|
|
|
|
static bool verifyExpired(const payments::PaymentDetails& requestDetails);
|
2015-01-15 09:13:32 +01:00
|
|
|
// Verify the payment request size is valid as per BIP70
|
|
|
|
static bool verifySize(qint64 requestSize);
|
2015-01-09 14:25:43 +01:00
|
|
|
// Verify the payment request amount is valid
|
|
|
|
static bool verifyAmount(const CAmount& requestAmount);
|
2015-01-12 08:43:08 +01:00
|
|
|
|
2015-07-14 13:59:05 +02:00
|
|
|
Q_SIGNALS:
|
2013-07-22 08:50:39 +02:00
|
|
|
// Fired when a valid payment request is received
|
|
|
|
void receivedPaymentRequest(SendCoinsRecipient);
|
|
|
|
|
|
|
|
// Fired when a valid PaymentACK is received
|
2013-10-22 21:27:24 +02:00
|
|
|
void receivedPaymentACK(const QString &paymentACKMsg);
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2013-10-18 11:44:05 +02:00
|
|
|
// Fired when a message should be reported to the user
|
|
|
|
void message(const QString &title, const QString &message, unsigned int style);
|
2013-02-12 00:52:30 +01:00
|
|
|
|
2015-07-14 13:59:05 +02:00
|
|
|
public Q_SLOTS:
|
2013-02-12 00:52:30 +01:00
|
|
|
// Signal this when the main window's UI is ready
|
|
|
|
// to display payment requests to the user
|
|
|
|
void uiReady();
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
// Submit Payment message to a merchant, get back PaymentACK:
|
2018-03-23 22:14:39 +01:00
|
|
|
void fetchPaymentACK(WalletModel* walletModel, const SendCoinsRecipient& recipient, QByteArray transaction);
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2013-12-09 10:48:14 +01:00
|
|
|
// Handle an incoming URI, URI with local file scheme or file
|
2013-11-06 15:08:56 +01:00
|
|
|
void handleURIOrFile(const QString& s);
|
|
|
|
|
2015-07-14 13:59:05 +02:00
|
|
|
private Q_SLOTS:
|
2013-02-12 00:52:30 +01:00
|
|
|
void handleURIConnection();
|
2013-07-22 08:50:39 +02:00
|
|
|
void netRequestFinished(QNetworkReply*);
|
|
|
|
void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
|
2013-10-22 21:27:24 +02:00
|
|
|
void handlePaymentACK(const QString& paymentACKMsg);
|
2013-07-22 08:50:39 +02:00
|
|
|
|
2013-11-14 19:21:16 +01:00
|
|
|
protected:
|
|
|
|
// Constructor registers this on the parent QApplication to
|
|
|
|
// receive QEvent::FileOpen and QEvent:Drop events
|
|
|
|
bool eventFilter(QObject *object, QEvent *event);
|
|
|
|
|
2013-07-22 08:50:39 +02:00
|
|
|
private:
|
2015-01-15 09:13:32 +01:00
|
|
|
static bool readPaymentRequestFromFile(const QString& filename, PaymentRequestPlus& request);
|
2015-01-12 14:24:01 +01:00
|
|
|
bool processPaymentRequest(const PaymentRequestPlus& request, SendCoinsRecipient& recipient);
|
2013-07-22 08:50:39 +02:00
|
|
|
void fetchRequest(const QUrl& url);
|
|
|
|
|
2013-10-30 11:30:53 +01:00
|
|
|
// Setup networking
|
|
|
|
void initNetManager();
|
|
|
|
|
2013-08-24 15:07:17 +02:00
|
|
|
bool saveURIs; // true during startup
|
2013-07-22 08:50:39 +02:00
|
|
|
QLocalServer* uriServer;
|
2013-08-24 15:07:17 +02:00
|
|
|
|
|
|
|
QNetworkAccessManager* netManager; // Used to fetch payment requests
|
|
|
|
|
|
|
|
OptionsModel *optionsModel;
|
2013-02-12 00:52:30 +01:00
|
|
|
};
|
|
|
|
|
2014-11-03 16:16:40 +01:00
|
|
|
#endif // BITCOIN_QT_PAYMENTSERVER_H
|