Skip to content

Commit 48cc4fc

Browse files
committed
Merge pull request #3130 from Diapolo/paymentACK_via_message
Qt: move paymentACK handling to paymentserver
2 parents 3565876 + 08dd1b7 commit 48cc4fc

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

src/qt/bitcoin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,8 +331,6 @@ int main(int argc, char *argv[])
331331
&window, SLOT(handlePaymentRequest(SendCoinsRecipient)));
332332
QObject::connect(&walletModel, SIGNAL(coinsSent(CWallet*,SendCoinsRecipient,QByteArray)),
333333
paymentServer, SLOT(fetchPaymentACK(CWallet*,const SendCoinsRecipient&,QByteArray)));
334-
QObject::connect(paymentServer, SIGNAL(receivedPaymentACK(QString)),
335-
&window, SLOT(showPaymentACK(QString)));
336334
QObject::connect(paymentServer, SIGNAL(message(QString,QString,unsigned int)),
337335
guiref, SLOT(message(QString,QString,unsigned int)));
338336
QTimer::singleShot(100, paymentServer, SLOT(uiReady()));

src/qt/bitcoingui.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -763,11 +763,6 @@ void BitcoinGUI::handlePaymentRequest(const SendCoinsRecipient& recipient)
763763
walletFrame->handlePaymentRequest(recipient);
764764
}
765765

766-
void BitcoinGUI::showPaymentACK(const QString& msg)
767-
{
768-
message(tr("Payment acknowledged"), GUIUtil::HtmlEscape(msg), CClientUIInterface::MODAL);
769-
}
770-
771766
void BitcoinGUI::setEncryptionStatus(int status)
772767
{
773768
switch(status)

src/qt/bitcoingui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ public slots:
135135
@param[in] ret pointer to a bool that will be modified to whether Ok was clicked (modal only)
136136
*/
137137
void message(const QString &title, const QString &message, unsigned int style, bool *ret = NULL);
138+
138139
/** Asks the user whether to pay the transaction fee or to cancel the transaction.
139140
It is currently not possible to pass a return value to another thread through
140141
BlockingQueuedConnection, so an indirected pointer is used.
@@ -146,7 +147,6 @@ public slots:
146147
void askFee(qint64 nFeeRequired, bool *payFee);
147148

148149
void handlePaymentRequest(const SendCoinsRecipient& recipient);
149-
void showPaymentACK(const QString& msg);
150150

151151
/** Show incoming transaction notification for new transactions. */
152152
void incomingTransaction(const QString& date, int unit, qint64 amount, const QString& type, const QString& address);

src/qt/paymentserver.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
263263

264264
// Install global event filter to catch QFileOpenEvents
265265
// on Mac: sent when you click bitcoin: links
266-
// other OSes: helpful when dealing with payment-request files (in the future)
266+
// other OSes: helpful when dealing with payment request files (in the future)
267267
if (parent)
268268
parent->installEventFilter(this);
269269

@@ -278,8 +278,10 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) :
278278

279279
if (!uriServer->listen(name))
280280
qDebug() << "PaymentServer::PaymentServer : Cannot start bitcoin: click-to-pay handler";
281-
else
281+
else {
282282
connect(uriServer, SIGNAL(newConnection()), this, SLOT(handleURIConnection()));
283+
connect(this, SIGNAL(receivedPaymentACK(QString)), this, SLOT(handlePaymentACK(QString)));
284+
}
283285
}
284286

285287
// netManager is null until uiReady() is called
@@ -321,7 +323,7 @@ void PaymentServer::initNetManager()
321323
// netManager is used to fetch paymentrequests given in bitcoin: URIs
322324
netManager = new QNetworkAccessManager(this);
323325

324-
// Use proxy settings from optionsModel:
326+
// Use proxy settings from optionsModel
325327
QString proxyIP;
326328
quint16 proxyPort;
327329
if (optionsModel->getProxySettings(proxyIP, proxyPort))
@@ -457,7 +459,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList<Sen
457459
foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) {
458460
CTxOut txOut(sendingTo.second, sendingTo.first);
459461
if (txOut.IsDust(CTransaction::nMinRelayTxFee)) {
460-
QString msg = QObject::tr("Requested payment amount (%1) too small")
462+
QString msg = tr("Requested payment amount of %1 is too small (considered dust).")
461463
.arg(BitcoinUnits::formatWithUnit(optionsModel->getDisplayUnit(), sendingTo.second));
462464

463465
qDebug() << "PaymentServer::processPaymentRequest : " << msg;
@@ -537,7 +539,7 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
537539
payment.add_transactions(transaction.data(), transaction.size());
538540

539541
// Create a new refund address, or re-use:
540-
QString account = tr("Refund from") + QString(" ") + recipient.authenticatedMerchant;
542+
QString account = tr("Refund from %1").arg(recipient.authenticatedMerchant);
541543
std::string strAccount = account.toStdString();
542544
set<CTxDestination> refundAddresses = wallet->GetAccountAddresses(strAccount);
543545
if (!refundAddresses.empty()) {
@@ -579,9 +581,10 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
579581
reply->deleteLater();
580582
if (reply->error() != QNetworkReply::NoError)
581583
{
582-
QString msg = QObject::tr("Error communicating with %1: %2")
584+
QString msg = tr("Error communicating with %1: %2")
583585
.arg(reply->request().url().toString())
584586
.arg(reply->errorString());
587+
585588
qDebug() << "PaymentServer::netRequestFinished : " << msg;
586589
emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
587590
return;
@@ -595,26 +598,28 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
595598
PaymentRequestPlus request;
596599
QList<SendCoinsRecipient> recipients;
597600
if (request.parse(data) && processPaymentRequest(request, recipients)) {
598-
foreach (const SendCoinsRecipient& recipient, recipients){
601+
foreach (const SendCoinsRecipient& recipient, recipients) {
599602
emit receivedPaymentRequest(recipient);
600603
}
601604
}
602605
else
603606
qDebug() << "PaymentServer::netRequestFinished : Error processing payment request";
607+
604608
return;
605609
}
606610
else if (requestType == "PaymentACK")
607611
{
608612
payments::PaymentACK paymentACK;
609613
if (!paymentACK.ParseFromArray(data.data(), data.size()))
610614
{
611-
QString msg = QObject::tr("Bad response from server %1")
615+
QString msg = tr("Bad response from server %1")
612616
.arg(reply->request().url().toString());
617+
613618
qDebug() << "PaymentServer::netRequestFinished : " << msg;
614619
emit message(tr("Network request error"), msg, CClientUIInterface::MSG_ERROR);
615620
}
616621
else {
617-
emit receivedPaymentACK(QString::fromStdString(paymentACK.memo()));
622+
emit receivedPaymentACK(GUIUtil::HtmlEscape(paymentACK.memo()));
618623
}
619624
}
620625
}
@@ -635,3 +640,9 @@ void PaymentServer::setOptionsModel(OptionsModel *optionsModel)
635640
{
636641
this->optionsModel = optionsModel;
637642
}
643+
644+
void PaymentServer::handlePaymentACK(const QString& paymentACKMsg)
645+
{
646+
// currently we don't futher process or store the paymentACK message
647+
emit message(tr("Payment acknowledged"), paymentACKMsg, CClientUIInterface::ICON_INFORMATION | CClientUIInterface::MODAL);
648+
}

src/qt/paymentserver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class PaymentServer : public QObject
8888
void receivedPaymentRequest(SendCoinsRecipient);
8989

9090
// Fired when a valid PaymentACK is received
91-
void receivedPaymentACK(QString);
91+
void receivedPaymentACK(const QString &paymentACKMsg);
9292

9393
// Fired when a message should be reported to the user
9494
void message(const QString &title, const QString &message, unsigned int style);
@@ -105,6 +105,7 @@ private slots:
105105
void handleURIConnection();
106106
void netRequestFinished(QNetworkReply*);
107107
void reportSslErrors(QNetworkReply*, const QList<QSslError> &);
108+
void handlePaymentACK(const QString& paymentACKMsg);
108109

109110
private:
110111
static bool readPaymentRequest(const QString& filename, PaymentRequestPlus& request);

0 commit comments

Comments
 (0)