Bitcoin ABC 0.26.3
P2P Digital Currency
Loading...
Searching...
No Matches
paymentserver.h
Go to the documentation of this file.
1// Copyright (c) 2011-2016 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// bitcoincash: URIs
10//
11// This is somewhat tricky, because we have to deal with the situation where the
12// user clicks on a link during startup/initialization, when the splash-screen
13// is up 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, when the application is
18// created. Save any URIs received at or during startup in a list.
19//
20// When startup is finished and the main window is shown, a signal is sent to
21// slot uiReady(), which emits a receivedURI() signal for any payment requests
22// that happened during startup.
23//
24// After startup, receivedURI() happens as usual.
25//
26// This class has one more feature: a static method that finds URIs passed in
27// the command line and, if a server is running in another process, sends them
28// to the server.
29//
30
31#if defined(HAVE_CONFIG_H)
32#include <config/bitcoin-config.h>
33#endif
34
35#ifdef ENABLE_BIP70
37#endif
38#include <interfaces/wallet.h>
40
41#include <QObject>
42#include <QString>
43
44class OptionsModel;
45
46namespace interfaces {
47class Node;
48} // namespace interfaces
49
51class QApplication;
52class QByteArray;
53class QLocalServer;
55class QNetworkReply;
56class QSslError;
57class QUrl;
59
60// BIP70 max payment request size in bytes (DoS protection)
62
63class PaymentServer : public QObject {
65
66public:
67 // Parse URIs on command line
68 // Returns false on error
69 static void ipcParseCommandLine(int argc, char *argv[]);
70
71 // Returns true if there were URIs on the command line which were
72 // successfully sent to an already-running process.
73 // Note: if a payment request is given, SelectParams(MAIN/TESTNET) will be
74 // called so we startup in the right mode.
75 static bool ipcSendCommandLine();
76
77 // parent should be QApplication object
78 explicit PaymentServer(QObject *parent, bool startLocalServer = true);
80
81 // OptionsModel is used for getting proxy settings and display unit
83
84#ifdef ENABLE_BIP70
85 // Load root certificate authorities. Pass nullptr (default) to read from
86 // the file specified in the -rootcertificates setting, or, if that's not
87 // set, to use the system default root certificates. If you pass in a store,
88 // you should not X509_STORE_free it: it will be freed either at exit or
89 // when another set of CAs are loaded.
90 static void LoadRootCAs(X509_STORE *store = nullptr);
91
92 // Return certificate store
93 static X509_STORE *getCertStore();
94
95 // Verify that the payment request network matches the client network
97 const payments::PaymentDetails &requestDetails);
98 // Verify if the payment request is expired
99 static bool verifyExpired(const payments::PaymentDetails &requestDetails);
100 // Verify the payment request size is valid as per BIP70
101 static bool verifySize(qint64 requestSize);
102 // Verify the payment request amount is valid
103 static bool verifyAmount(const Amount requestAmount);
104#endif
105
107 // Fired when a valid payment request is received
109
110 // Fired when a message should be reported to the user
111 void message(const QString &title, const QString &message,
112 unsigned int style);
113
114#ifdef ENABLE_BIP70
115 // Fired when a valid PaymentACK is received
117#endif
118
119public Q_SLOTS:
120 // Signal this when the main window's UI is ready to display payment
121 // requests to the user
122 void uiReady();
123
124 // Handle an incoming URI, URI with local file scheme or file
125 void handleURIOrFile(const QString &s);
126
127#ifdef ENABLE_BIP70
128 // Submit Payment message to a merchant, get back PaymentACK:
130 const SendCoinsRecipient &recipient,
132#endif
133
134private Q_SLOTS:
135 void handleURIConnection();
136#ifdef ENABLE_BIP70
140 void dataDownloaded();
141#endif
142
143protected:
144 // Constructor registers this on the parent QApplication to receive
145 // QEvent::FileOpen and QEvent:Drop events
146 bool eventFilter(QObject *object, QEvent *event) override;
147
148private:
149 // true during startup
153
154 bool handleURI(const CChainParams &params, const QString &s);
155
156#ifdef ENABLE_BIP70
157 static bool readPaymentRequestFromFile(const QString &filename,
158 PaymentRequestPlus &request);
159 bool processPaymentRequest(const PaymentRequestPlus &request,
160 SendCoinsRecipient &recipient);
161 void fetchRequest(const QUrl &url);
162
163 // Setup networking
164 void initNetManager();
165
166 // Used to fetch payment requests
169#endif
170};
171
172#endif // BITCOIN_QT_PAYMENTSERVER_H
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition chainparams.h:80
Interface from Qt to configuration data structure for Bitcoin client.
static bool ipcSendCommandLine()
void setOptionsModel(OptionsModel *optionsModel)
void message(const QString &title, const QString &message, unsigned int style)
void handleURIConnection()
static void ipcParseCommandLine(int argc, char *argv[])
QLocalServer * uriServer
void receivedPaymentRequest(SendCoinsRecipient)
bool eventFilter(QObject *object, QEvent *event) override
void handleURIOrFile(const QString &s)
bool handleURI(const CChainParams &params, const QString &s)
OptionsModel * optionsModel
Top-level interface for a bitcoin node (bitcoind process).
Definition node.h:59
Interface for accessing a wallet.
Definition wallet.h:59
Definition init.h:28
static QT_END_NAMESPACE const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85
const char * url