17 #include <QApplication>
19 #include <QDataStream>
21 #include <QFileOpenEvent>
22 #include <QLocalServer>
23 #include <QLocalSocket>
24 #include <QStringList>
36 static QString ipcServerName()
38 QString
name(
"PIVXQt");
43 QString ddir(QString::fromStdString(
GetDataDir(
true).
string()));
44 name.append(QString::number(qHash(ddir)));
54 static QList<QString> savedPaymentRequests;
67 for (
int i = 1; i < argc; i++) {
69 if (arg.startsWith(
"-"))
78 savedPaymentRequests.append(arg);
100 bool fResult =
false;
101 for (
const QString& r : savedPaymentRequests) {
102 QLocalSocket* socket =
new QLocalSocket();
103 socket->connectToServer(ipcServerName(), QIODevice::WriteOnly);
111 QDataStream out(&block, QIODevice::WriteOnly);
112 out.setVersion(QDataStream::Qt_4_0);
114 out.device()->seek(0);
116 socket->write(block);
119 socket->disconnectFromServer();
138 parent->installEventFilter(
this);
140 QString
name = ipcServerName();
143 QLocalServer::removeServer(
name);
145 if (startLocalServer) {
150 QMessageBox::critical(0, tr(
"Payment request error"),
151 tr(
"Cannot start pivx: click-to-pay handler"));
168 if (event->type() == QEvent::FileOpen) {
169 QFileOpenEvent* fileEvent =
static_cast<QFileOpenEvent*
>(event);
170 if (!fileEvent->file().isEmpty())
172 else if (!fileEvent->url().isEmpty())
178 return QObject::eventFilter(
object, event);
184 for (
const QString& s : savedPaymentRequests) {
187 savedPaymentRequests.clear();
193 savedPaymentRequests.append(s);
199 QUrlQuery uri((QUrl(s)));
205 Q_EMIT
message(tr(
"URI handling"), tr(
"Invalid payment address %1").arg(recipient.
address),
210 Q_EMIT
message(tr(
"URI handling"),
211 tr(
"URI cannot be parsed! This can be caused by an invalid PIVX address or malformed URI parameters."),
221 QLocalSocket* clientConnection =
uriServer->nextPendingConnection();
223 while (clientConnection->bytesAvailable() < (
int)
sizeof(quint32))
224 clientConnection->waitForReadyRead();
226 connect(clientConnection, &QLocalSocket::disconnected, clientConnection, &QLocalSocket::deleteLater);
228 QDataStream in(clientConnection);
229 in.setVersion(QDataStream::Qt_4_0);
230 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.
const CChainParams & Params()
Return the currently selected parameters.
std::unique_ptr< CChainParams > CreateChainParams(const std::string &chain)
Creates and returns a std::unique_ptr<CChainParams> of the chosen chain.
static const std::string TESTNET
static const std::string MAIN
Chain name strings.
Interface from Qt to configuration data structure for PIVX client.
static bool ipcSendCommandLine()
void receivedPaymentRequest(const SendCoinsRecipient &recipient)
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 handleURIOrFile(const QString &s)
bool eventFilter(QObject *object, QEvent *event)
OptionsModel * optionsModel
bool IsValidDestinationString(const std::string &str, bool fStaking, const CChainParams ¶ms)
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out)
const int BITCOIN_IPC_CONNECT_TIMEOUT
const QString BITCOIN_IPC_PREFIX("pivx:")
const fs::path & GetDataDir(bool fNetSpecific)