Bitcoin Core  22.99.0
P2P Digital Currency
paymentserver.h
Go to the documentation of this file.
1 // Copyright (c) 2011-2020 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 receivedURI() signal for any payment
25 // requests that happened during startup.
26 //
27 // After startup, receivedURI() 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 #if defined(HAVE_CONFIG_H)
36 #include <config/bitcoin-config.h>
37 #endif
38 
39 #include <qt/sendcoinsrecipient.h>
40 
41 #include <QObject>
42 #include <QString>
43 
44 class OptionsModel;
45 
46 namespace interfaces {
47 class Node;
48 } // namespace interfaces
49 
50 QT_BEGIN_NAMESPACE
51 class QApplication;
52 class QByteArray;
53 class QLocalServer;
54 class QUrl;
55 QT_END_NAMESPACE
56 
57 class PaymentServer : public QObject
58 {
59  Q_OBJECT
60 
61 public:
62  // Parse URIs on command line
63  // Returns false on error
64  static void ipcParseCommandLine(int argc, char *argv[]);
65 
66  // Returns true if there were URIs on the command line
67  // which were successfully sent to an already-running
68  // process.
69  // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
70  // will be called so we startup in the right mode.
71  static bool ipcSendCommandLine();
72 
73  // parent should be QApplication object
74  explicit PaymentServer(QObject* parent, bool startLocalServer = true);
76 
77  // OptionsModel is used for getting proxy settings and display unit
79 
80 Q_SIGNALS:
81  // Fired when a valid payment request is received
83 
84  // Fired when a message should be reported to the user
85  void message(const QString &title, const QString &message, unsigned int style);
86 
87 public Q_SLOTS:
88  // Signal this when the main window's UI is ready
89  // to display payment requests to the user
90  void uiReady();
91 
92  // Handle an incoming URI, URI with local file scheme or file
93  void handleURIOrFile(const QString& s);
94 
95 private Q_SLOTS:
96  void handleURIConnection();
97 
98 protected:
99  // Constructor registers this on the parent QApplication to
100  // receive QEvent::FileOpen and QEvent:Drop events
101  bool eventFilter(QObject *object, QEvent *event) override;
102 
103 private:
104  bool saveURIs; // true during startup
105  QLocalServer* uriServer;
107 };
108 
109 #endif // BITCOIN_QT_PAYMENTSERVER_H
interfaces
Definition: dummywallet.cpp:11
PaymentServer::optionsModel
OptionsModel * optionsModel
Definition: paymentserver.h:106
PaymentServer::saveURIs
bool saveURIs
Definition: paymentserver.h:104
PaymentServer::message
void message(const QString &title, const QString &message, unsigned int style)
PaymentServer::~PaymentServer
~PaymentServer()
Definition: paymentserver.cpp:182
PaymentServer::setOptionsModel
void setOptionsModel(OptionsModel *optionsModel)
Definition: paymentserver.cpp:291
PaymentServer::handleURIConnection
void handleURIConnection()
Definition: paymentserver.cpp:271
PaymentServer::ipcParseCommandLine
static void ipcParseCommandLine(int argc, char *argv[])
Definition: paymentserver.cpp:76
bitcoin-config.h
PaymentServer::uiReady
void uiReady()
Definition: paymentserver.cpp:204
PaymentServer::ipcSendCommandLine
static bool ipcSendCommandLine()
Definition: paymentserver.cpp:117
SendCoinsRecipient
Definition: sendcoinsrecipient.h:19
OptionsModel
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:38
PaymentServer
Definition: paymentserver.h:57
PaymentServer::receivedPaymentRequest
void receivedPaymentRequest(SendCoinsRecipient)
PaymentServer::uriServer
QLocalServer * uriServer
Definition: paymentserver.h:105
PaymentServer::handleURIOrFile
void handleURIOrFile(const QString &s)
Definition: paymentserver.cpp:214
PaymentServer::eventFilter
bool eventFilter(QObject *object, QEvent *event) override
Definition: paymentserver.cpp:189
PaymentServer::PaymentServer
PaymentServer(QObject *parent, bool startLocalServer=true)
Definition: paymentserver.cpp:150
sendcoinsrecipient.h