Bitcoin Core 28.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
36
37#include <QObject>
38#include <QString>
39
40class OptionsModel;
41
42namespace interfaces {
43class Node;
44} // namespace interfaces
45
46QT_BEGIN_NAMESPACE
47class QApplication;
48class QByteArray;
49class QLocalServer;
50class QUrl;
51QT_END_NAMESPACE
52
53extern const QString BITCOIN_IPC_PREFIX;
54
55class PaymentServer : public QObject
56{
57 Q_OBJECT
58
59public:
60 // Parse URIs on command line
61 // Returns false on error
62 static void ipcParseCommandLine(int argc, char *argv[]);
63
64 // Returns true if there were URIs on the command line
65 // which were successfully sent to an already-running
66 // process.
67 // Note: if a payment request is given, SelectParams(MAIN/TESTNET)
68 // will be called so we startup in the right mode.
69 static bool ipcSendCommandLine();
70
71 // parent should be QApplication object
72 explicit PaymentServer(QObject* parent, bool startLocalServer = true);
74
75 // OptionsModel is used for getting proxy settings and display unit
77
78Q_SIGNALS:
79 // Fired when a valid payment request is received
81
82 // Fired when a message should be reported to the user
83 void message(const QString &title, const QString &message, unsigned int style);
84
85public Q_SLOTS:
86 // Signal this when the main window's UI is ready
87 // to display payment requests to the user
88 void uiReady();
89
90 // Handle an incoming URI, URI with local file scheme or file
91 void handleURIOrFile(const QString& s);
92
93private Q_SLOTS:
95
96protected:
97 // Constructor registers this on the parent QApplication to
98 // receive QEvent::FileOpen and QEvent:Drop events
99 bool eventFilter(QObject *object, QEvent *event) override;
100
101private:
102 bool saveURIs{true}; // true during startup
103 QLocalServer* uriServer{nullptr};
105};
106
107#endif // BITCOIN_QT_PAYMENTSERVER_H
Interface from Qt to configuration data structure for Bitcoin client.
Definition: optionsmodel.h:43
static bool ipcSendCommandLine()
void setOptionsModel(OptionsModel *optionsModel)
PaymentServer(QObject *parent, bool startLocalServer=true)
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)
OptionsModel * optionsModel
QT_END_NAMESPACE const QString BITCOIN_IPC_PREFIX