aboutsummaryrefslogtreecommitdiff
path: root/src/qt/paymentserver.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qt/paymentserver.cpp')
-rw-r--r--src/qt/paymentserver.cpp95
1 files changed, 64 insertions, 31 deletions
diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp
index ba5c06064f..ca6ae17990 100644
--- a/src/qt/paymentserver.cpp
+++ b/src/qt/paymentserver.cpp
@@ -8,8 +8,6 @@
#include "guiconstants.h"
#include "guiutil.h"
#include "optionsmodel.h"
-#include "paymentserver.h"
-#include "walletmodel.h"
#include "base58.h"
#include "ui_interface.h"
@@ -180,10 +178,8 @@ void PaymentServer::LoadRootCAs(X509_STORE* _store)
// and the items in savedPaymentRequest will be handled
// when uiReady() is called.
//
-bool PaymentServer::ipcSendCommandLine(int argc, char* argv[])
+bool PaymentServer::ipcParseCommandLine(int argc, char* argv[])
{
- bool fResult = false;
-
for (int i = 1; i < argc; i++)
{
QString arg(argv[i]);
@@ -226,7 +222,18 @@ bool PaymentServer::ipcSendCommandLine(int argc, char* argv[])
qDebug() << "PaymentServer::ipcSendCommandLine : Payment request file does not exist: " << arg;
}
}
+ return true;
+}
+//
+// Sending to the server is done synchronously, at startup.
+// If the server isn't already running, startup continues,
+// and the items in savedPaymentRequest will be handled
+// when uiReady() is called.
+//
+bool PaymentServer::ipcSendCommandLine()
+{
+ bool fResult = false;
foreach (const QString& r, savedPaymentRequests)
{
QLocalSocket* socket = new QLocalSocket();
@@ -328,17 +335,22 @@ void PaymentServer::initNetManager()
// netManager is used to fetch paymentrequests given in bitcoin: URIs
netManager = new QNetworkAccessManager(this);
- // Use proxy settings from optionsModel
- QString proxyIP;
- quint16 proxyPort;
- if (optionsModel->getProxySettings(proxyIP, proxyPort))
- {
- QNetworkProxy proxy;
- proxy.setType(QNetworkProxy::Socks5Proxy);
- proxy.setHostName(proxyIP);
- proxy.setPort(proxyPort);
- netManager->setProxy(proxy);
+ QNetworkProxy proxy;
+
+ // Query active proxy (fails if no SOCKS5 proxy)
+ if (optionsModel->getProxySettings(proxy)) {
+ if (proxy.type() == QNetworkProxy::Socks5Proxy) {
+ netManager->setProxy(proxy);
+
+ qDebug() << "PaymentServer::initNetManager : Using SOCKS5 proxy" << proxy.hostName() << ":" << proxy.port();
+ }
+ else
+ qDebug() << "PaymentServer::initNetManager : No active proxy server found.";
}
+ else
+ emit message(tr("Net manager warning"),
+ tr("Your active proxy doesn't support SOCKS5, which is required for payment requests via proxy."),
+ CClientUIInterface::MSG_WARNING);
connect(netManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(netRequestFinished(QNetworkReply*)));
@@ -373,40 +385,52 @@ void PaymentServer::handleURIOrFile(const QString& s)
#else
QUrlQuery uri((QUrl(s)));
#endif
- if (uri.hasQueryItem("r"))
+ if (uri.hasQueryItem("r")) // payment request URI
{
QByteArray temp;
temp.append(uri.queryItemValue("r"));
QString decoded = QUrl::fromPercentEncoding(temp);
QUrl fetchUrl(decoded, QUrl::StrictMode);
- qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
-
if (fetchUrl.isValid())
+ {
+ qDebug() << "PaymentServer::handleURIOrFile : fetchRequest(" << fetchUrl << ")";
fetchRequest(fetchUrl);
+ }
else
+ {
qDebug() << "PaymentServer::handleURIOrFile : Invalid URL: " << fetchUrl;
+ emit message(tr("URI handling"),
+ tr("Payment request fetch URL is invalid: %1").arg(fetchUrl.toString()),
+ CClientUIInterface::ICON_WARNING);
+ }
return;
}
+ else // normal URI
+ {
+ SendCoinsRecipient recipient;
+ if (GUIUtil::parseBitcoinURI(s, &recipient))
+ emit receivedPaymentRequest(recipient);
+ else
+ emit message(tr("URI handling"),
+ tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters."),
+ CClientUIInterface::ICON_WARNING);
- SendCoinsRecipient recipient;
- if (GUIUtil::parseBitcoinURI(s, &recipient))
- emit receivedPaymentRequest(recipient);
- else
- emit message(tr("URI handling"),
- tr("URI can not be parsed! This can be caused by an invalid Bitcoin address or malformed URI parameters."),
- CClientUIInterface::ICON_WARNING);
-
- return;
+ return;
+ }
}
- if (QFile::exists(s))
+ if (QFile::exists(s)) // payment request file
{
PaymentRequestPlus request;
SendCoinsRecipient recipient;
if (readPaymentRequest(s, request) && processPaymentRequest(request, recipient))
emit receivedPaymentRequest(recipient);
+ else
+ emit message(tr("Payment request file handling"),
+ tr("Payment request file can not be read or processed! This can be caused by an invalid payment request file."),
+ CClientUIInterface::ICON_WARNING);
return;
}
@@ -548,6 +572,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
else {
CPubKey newKey;
if (wallet->GetKeyFromPool(newKey)) {
+ LOCK(wallet->cs_wallet); // SetAddressBook
CKeyID keyID = newKey.GetID();
wallet->SetAddressBook(keyID, strAccount, "refund");
@@ -584,7 +609,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
.arg(reply->errorString());
qDebug() << "PaymentServer::netRequestFinished : " << msg;
- emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
+ emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
return;
}
@@ -596,9 +621,16 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
PaymentRequestPlus request;
SendCoinsRecipient recipient;
if (request.parse(data) && processPaymentRequest(request, recipient))
+ {
emit receivedPaymentRequest(recipient);
+ }
else
+ {
qDebug() << "PaymentServer::netRequestFinished : Error processing payment request";
+ emit message(tr("Payment request error"),
+ tr("Payment request can not be parsed or processed!"),
+ CClientUIInterface::MSG_ERROR);
+ }
return;
}
@@ -611,9 +643,10 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
.arg(reply->request().url().toString());
qDebug() << "PaymentServer::netRequestFinished : " << msg;
- emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
+ emit message(tr("Payment request error"), msg, CClientUIInterface::MSG_ERROR);
}
- else {
+ else
+ {
emit receivedPaymentACK(GUIUtil::HtmlEscape(paymentACK.memo()));
}
}