From c6c97e0f4e3d9d8d5b8a1e60174e9ff11e70b6c1 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Thu, 24 Oct 2013 16:02:39 +0200 Subject: [Qt] Rework of payment request UI (mainly for insecure pr) - this shows insecure (unsecured) payment requests in a new yellowish colored UI (based on the secure payment request UI) instead of our normal payment UI - allows us to receive paymentACK messages for insecure payment requests - allows us to handle expirations for insecure payment request - changed walletmodel, so that all types of payment requests don't touch the addressbook --- src/qt/paymentserver.cpp | 74 +++++++++++++++++++++++------------------------- 1 file changed, 36 insertions(+), 38 deletions(-) (limited to 'src/qt/paymentserver.cpp') diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 0f386680ac..50847c4c48 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -280,9 +280,6 @@ PaymentServer::PaymentServer(QObject* parent, bool startLocalServer) : connect(this, SIGNAL(receivedPaymentACK(QString)), this, SLOT(handlePaymentACK(QString))); } } - - // netManager is null until uiReady() is called - netManager = NULL; } PaymentServer::~PaymentServer() @@ -450,9 +447,36 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList > sendingTos = request.getPayTo(); - qint64 totalAmount = 0; + recipients.append(SendCoinsRecipient()); + + recipients[0].paymentRequest = request; + recipients[0].label = GUIUtil::HtmlEscape(request.getDetails().memo()); // Todo: Change to .message once available + + request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant); + + QList > sendingTos = request.getPayTo(); + + int i = 0; foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) { + // Extract and check destination addresses + CTxDestination dest; + if (ExtractDestination(sendingTo.first, dest)) { + // Append destination address (for payment requests .address is used ONLY for GUI display) + recipients[0].address.append(QString::fromStdString(CBitcoinAddress(dest).ToString())); + if (i < sendingTos.size() - 1) // prevent new-line for last entry + recipients[0].address.append("
"); + } + else if (!recipients[0].authenticatedMerchant.isEmpty()){ + // Insecure payments to custom bitcoin addresses are not supported + // (there is no good way to tell the user where they are paying in a way + // they'd have a chance of understanding). + emit message(tr("Payment request error"), + tr("Unverified payment requests to custom payment scripts are unsupported."), + CClientUIInterface::MSG_ERROR); + return false; + } + + // Extract and check amounts CTxOut txOut(sendingTo.second, sendingTo.first); if (txOut.IsDust(CTransaction::nMinRelayTxFee)) { QString msg = tr("Requested payment amount of %1 is too small (considered dust).") @@ -463,43 +487,17 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList"); - recipients.append(SendCoinsRecipient()); - - if (request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant)) { - recipients[0].paymentRequest = request; - recipients[0].amount = totalAmount; - qDebug() << "PaymentServer::processPaymentRequest : Payment request from " << recipients[0].authenticatedMerchant; + if (!recipient.authenticatedMerchant.isEmpty()) { + qDebug() << "PaymentServer::processPaymentRequest : Secure payment request from " << recipient.authenticatedMerchant; } else { - recipients.clear(); - // Insecure payment requests may turn into more than one recipient if - // the merchant is requesting payment to more than one address. - for (int i = 0; i < sendingTos.size(); i++) { - std::pair& sendingTo = sendingTos[i]; - recipients.append(SendCoinsRecipient()); - recipients[i].amount = sendingTo.second; - QString memo = QString::fromStdString(request.getDetails().memo()); - recipients[i].label = GUIUtil::HtmlEscape(memo); - CTxDestination dest; - if (ExtractDestination(sendingTo.first, dest)) { - if (i == 0) // Tie request to first pay-to, we don't want multiple ACKs - recipients[i].paymentRequest = request; - recipients[i].address = QString::fromStdString(CBitcoinAddress(dest).ToString()); - qDebug() << "PaymentServer::processPaymentRequest : Payment request, insecure " << recipients[i].address; - } - else { - // Insecure payments to custom bitcoin addresses are not supported - // (there is no good way to tell the user where they are paying in a way - // they'd have a chance of understanding). - emit message(tr("Payment request error"), - tr("Insecure requests to custom payment scripts unsupported"), - CClientUIInterface::MSG_ERROR); - return false; - } - } + qDebug() << "PaymentServer::processPaymentRequest : Insecure payment request to " << addresses.join(", "); } return true; -- cgit v1.2.3 From 983cef48027f1bdf651c19d72cf615cf4345dbe6 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Sun, 27 Oct 2013 21:52:01 +0100 Subject: payment-request UI: use SendCoinsRecipient.message for memo --- src/qt/paymentserver.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/qt/paymentserver.cpp') diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 50847c4c48..c113c0ff13 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -450,7 +450,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList Date: Mon, 28 Oct 2013 13:29:13 +0100 Subject: make processPaymentRequest() use a single SendCoinsRecipient - as one this pulls main purpose is to change a payment request to be displayed as a single sendcoins entry --- src/qt/paymentserver.cpp | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'src/qt/paymentserver.cpp') diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index c113c0ff13..71a5bb4550 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -375,6 +375,7 @@ void PaymentServer::handleURIOrFile(const QString& s) fetchRequest(fetchUrl); else qDebug() << "PaymentServer::handleURIOrFile : Invalid URL: " << fetchUrl; + return; } @@ -385,18 +386,17 @@ void PaymentServer::handleURIOrFile(const QString& s) 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; } if (QFile::exists(s)) { PaymentRequestPlus request; - QList recipients; - if (readPaymentRequest(s, request) && processPaymentRequest(request, recipients)) { - foreach (const SendCoinsRecipient& recipient, recipients){ - emit receivedPaymentRequest(recipient); - } - } + SendCoinsRecipient recipient; + if (readPaymentRequest(s, request) && processPaymentRequest(request, recipient)) + emit receivedPaymentRequest(recipient); + return; } } @@ -442,17 +442,15 @@ bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPl return request.parse(data); } -bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList& recipients) +bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoinsRecipient& recipient) { if (!optionsModel) return false; - recipients.append(SendCoinsRecipient()); - - recipients[0].paymentRequest = request; - recipients[0].message = GUIUtil::HtmlEscape(request.getDetails().memo()); + recipient.paymentRequest = request; + recipient.message = GUIUtil::HtmlEscape(request.getDetails().memo()); - request.getMerchant(PaymentServer::certStore, recipients[0].authenticatedMerchant); + request.getMerchant(PaymentServer::certStore, recipient.authenticatedMerchant); QList > sendingTos = request.getPayTo(); @@ -462,11 +460,11 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList"); + recipient.address.append("
"); } - else if (!recipients[0].authenticatedMerchant.isEmpty()){ + else if (!recipient.authenticatedMerchant.isEmpty()){ // Insecure payments to custom bitcoin addresses are not supported // (there is no good way to tell the user where they are paying in a way // they'd have a chance of understanding). @@ -487,7 +485,7 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, QList recipients; - if (request.parse(data) && processPaymentRequest(request, recipients)) { - foreach (const SendCoinsRecipient& recipient, recipients) { - emit receivedPaymentRequest(recipient); - } - } + SendCoinsRecipient recipient; + if (request.parse(data) && processPaymentRequest(request, recipient)) + emit receivedPaymentRequest(recipient); else qDebug() << "PaymentServer::netRequestFinished : Error processing payment request"; -- cgit v1.2.3 From 395d0d5af017bbf6d432471075608efaf4104a03 Mon Sep 17 00:00:00 2001 From: Philip Kaufmann Date: Wed, 30 Oct 2013 11:26:44 +0100 Subject: rework an ugly hack in processPaymentRequest() - use a QStringList to store valid addresses and format them for GUI and debug.log usage via .join() --- src/qt/paymentserver.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/qt/paymentserver.cpp') diff --git a/src/qt/paymentserver.cpp b/src/qt/paymentserver.cpp index 71a5bb4550..b6c869a2c9 100644 --- a/src/qt/paymentserver.cpp +++ b/src/qt/paymentserver.cpp @@ -453,16 +453,14 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins request.getMerchant(PaymentServer::certStore, recipient.authenticatedMerchant); QList > sendingTos = request.getPayTo(); + QStringList addresses; - int i = 0; foreach(const PAIRTYPE(CScript, qint64)& sendingTo, sendingTos) { // Extract and check destination addresses CTxDestination dest; if (ExtractDestination(sendingTo.first, dest)) { - // Append destination address (for payment requests .address is used ONLY for GUI display) - recipient.address.append(QString::fromStdString(CBitcoinAddress(dest).ToString())); - if (i < sendingTos.size() - 1) // prevent new-line for last entry - recipient.address.append("
"); + // Append destination address + addresses.append(QString::fromStdString(CBitcoinAddress(dest).ToString())); } else if (!recipient.authenticatedMerchant.isEmpty()){ // Insecure payments to custom bitcoin addresses are not supported @@ -486,7 +484,6 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins } recipient.amount += sendingTo.second; - i++; } // Store addresses and format them to fit nicely into the GUI recipient.address = addresses.join("
"); -- cgit v1.2.3