5#if defined(HAVE_CONFIG_H)
26#include <QApplication>
31#include <QFileOpenEvent>
34#include <QLocalServer>
35#include <QLocalSocket>
49 QString
name(
"BitcoinQt");
55 name.append(QString::number(qHash(ddir)));
78 for (
int i = 1; i < argc; i++)
81 if (arg.startsWith(
"-"))
119 bool fResult =
false;
122 QLocalSocket* socket =
new QLocalSocket();
123 socket->connectToServer(
ipcServerName(), QIODevice::WriteOnly);
132 QDataStream out(&block, QIODevice::WriteOnly);
133 out.setVersion(QDataStream::Qt_4_0);
135 out.device()->seek(0);
137 socket->write(block);
140 socket->disconnectFromServer();
154 optionsModel(nullptr)
160 parent->installEventFilter(
this);
165 QLocalServer::removeServer(
name);
167 if (startLocalServer)
173 QMessageBox::critical(
nullptr, tr(
"Payment request error"),
174 tr(
"Cannot start bitcoin: click-to-pay handler"));
191 if (event->type() == QEvent::FileOpen) {
192 QFileOpenEvent *fileEvent =
static_cast<QFileOpenEvent*
>(event);
193 if (!fileEvent->file().isEmpty())
195 else if (!fileEvent->url().isEmpty())
201 return QObject::eventFilter(
object, event);
222 if (s.startsWith(
"bitcoin://", Qt::CaseInsensitive))
224 Q_EMIT
message(tr(
"URI handling"), tr(
"'bitcoin://' is not a valid URI. Use 'bitcoin:' instead."),
229 QUrlQuery uri((QUrl(s)));
235 std::string error_msg;
239 if (uri.hasQueryItem(
"r")) {
240 Q_EMIT
message(tr(
"URI handling"),
241 tr(
"Cannot process payment request because BIP70 is not supported.\n"
242 "Due to widespread security flaws in BIP70 it's strongly recommended that any merchant instructions to switch wallets be ignored.\n"
243 "If you are receiving this error you should request the merchant provide a BIP21 compatible URI."),
246 Q_EMIT
message(tr(
"URI handling"), QString::fromStdString(error_msg),
253 Q_EMIT
message(tr(
"URI handling"),
254 tr(
"URI cannot be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters."),
263 Q_EMIT
message(tr(
"Payment request file handling"),
264 tr(
"Cannot process payment request because BIP70 is not supported.\n"
265 "Due to widespread security flaws in BIP70 it's strongly recommended that any merchant instructions to switch wallets be ignored.\n"
266 "If you are receiving this error you should request the merchant provide a BIP21 compatible URI."),
273 QLocalSocket *clientConnection =
uriServer->nextPendingConnection();
275 while (clientConnection->bytesAvailable() < (
int)
sizeof(quint32))
276 clientConnection->waitForReadyRead();
278 connect(clientConnection, &QLocalSocket::disconnected, clientConnection, &QLocalSocket::deleteLater);
280 QDataStream in(clientConnection);
281 in.setVersion(QDataStream::Qt_4_0);
282 if (clientConnection->bytesAvailable() < (
int)
sizeof(quint16)) {
void SelectParams(const std::string &network)
Sets the params returned by Params() to those for the given chain name.
std::unique_ptr< const CChainParams > CreateChainParams(const ArgsManager &args, const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
static const std::string TESTNET
static const std::string MAIN
Chain name strings.
Interface from Qt to configuration data structure for Bitcoin client.
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[])
void receivedPaymentRequest(SendCoinsRecipient)
bool eventFilter(QObject *object, QEvent *event) override
void handleURIOrFile(const QString &s)
OptionsModel * optionsModel
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
CTxDestination DecodeDestination(const std::string &str, std::string &error_msg)
QString boostPathToQString(const fs::path &path)
Convert OS specific boost path to QString through UTF-8.
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
static bool exists(const path &p)
static QString ipcServerName()
const int BITCOIN_IPC_CONNECT_TIMEOUT
const QString BITCOIN_IPC_PREFIX("bitcoin:")
static QSet< QString > savedPaymentRequests
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
std::variant< CNoDestination, PKHash, ScriptHash, WitnessV0ScriptHash, WitnessV0KeyHash, WitnessV1Taproot, WitnessUnknown > CTxDestination
A txout script template with a specific destination.