Skip to content

Commit 814429d

Browse files
author
Philip Kaufmann
committed
[Qt] add BIP70/BIP71 constants for all messages and mime types
- also rename current ones to match the new ones - remove constant from guiconstant.h and add it to paymentserver.cpp
1 parent b82695b commit 814429d

File tree

2 files changed

+18
-15
lines changed

2 files changed

+18
-15
lines changed

src/qt/guiconstants.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ static const int TOOLTIP_WRAP_THRESHOLD = 80;
3838
/* Maximum allowed URI length */
3939
static const int MAX_URI_LENGTH = 255;
4040

41-
/* Maximum somewhat-sane size of a payment request file */
42-
static const int MAX_PAYMENT_REQUEST_SIZE = 50000; // bytes
43-
4441
/* QRCodeDialog -- size of exported QR Code image */
4542
#define EXPORT_IMAGE_SIZE 256
4643

src/qt/paymentserver.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "paymentserver.h"
66

77
#include "bitcoinunits.h"
8-
#include "guiconstants.h"
98
#include "guiutil.h"
109
#include "optionsmodel.h"
1110

@@ -19,6 +18,7 @@
1918

2019
#include <openssl/x509.h>
2120
#include <openssl/x509_vfy.h>
21+
2222
#include <QApplication>
2323
#include <QByteArray>
2424
#include <QDataStream>
@@ -51,9 +51,15 @@ using namespace boost;
5151

5252
const int BITCOIN_IPC_CONNECT_TIMEOUT = 1000; // milliseconds
5353
const QString BITCOIN_IPC_PREFIX("bitcoin:");
54-
const char* BITCOIN_REQUEST_MIMETYPE = "application/bitcoin-paymentrequest";
55-
const char* BITCOIN_PAYMENTACK_MIMETYPE = "application/bitcoin-paymentack";
56-
const char* BITCOIN_PAYMENTACK_CONTENTTYPE = "application/bitcoin-payment";
54+
// BIP70 payment protocol messages
55+
const char* BIP70_MESSAGE_PAYMENTACK = "PaymentACK";
56+
const char* BIP70_MESSAGE_PAYMENTREQUEST = "PaymentRequest";
57+
// BIP71 payment protocol media types
58+
const char* BIP71_MIMETYPE_PAYMENT = "application/bitcoin-payment";
59+
const char* BIP71_MIMETYPE_PAYMENTACK = "application/bitcoin-paymentack";
60+
const char* BIP71_MIMETYPE_PAYMENTREQUEST = "application/bitcoin-paymentrequest";
61+
// BIP70 max payment request size in bytes (DoS protection)
62+
const qint64 BIP70_MAX_PAYMENTREQUEST_SIZE = 50000;
5763

5864
X509_STORE* PaymentServer::certStore = NULL;
5965
void PaymentServer::freeCertStore()
@@ -486,7 +492,7 @@ bool PaymentServer::readPaymentRequest(const QString& filename, PaymentRequestPl
486492
return false;
487493
}
488494

489-
if (f.size() > MAX_PAYMENT_REQUEST_SIZE)
495+
if (f.size() > BIP70_MAX_PAYMENTREQUEST_SIZE)
490496
{
491497
qWarning() << "PaymentServer::readPaymentRequest : " << filename << " too large";
492498
return false;
@@ -583,10 +589,10 @@ bool PaymentServer::processPaymentRequest(PaymentRequestPlus& request, SendCoins
583589
void PaymentServer::fetchRequest(const QUrl& url)
584590
{
585591
QNetworkRequest netRequest;
586-
netRequest.setAttribute(QNetworkRequest::User, "PaymentRequest");
592+
netRequest.setAttribute(QNetworkRequest::User, BIP70_MESSAGE_PAYMENTREQUEST);
587593
netRequest.setUrl(url);
588594
netRequest.setRawHeader("User-Agent", CLIENT_NAME.c_str());
589-
netRequest.setRawHeader("Accept", BITCOIN_REQUEST_MIMETYPE);
595+
netRequest.setRawHeader("Accept", BIP71_MIMETYPE_PAYMENTREQUEST);
590596
netManager->get(netRequest);
591597
}
592598

@@ -597,11 +603,11 @@ void PaymentServer::fetchPaymentACK(CWallet* wallet, SendCoinsRecipient recipien
597603
return;
598604

599605
QNetworkRequest netRequest;
600-
netRequest.setAttribute(QNetworkRequest::User, "PaymentACK");
606+
netRequest.setAttribute(QNetworkRequest::User, BIP70_MESSAGE_PAYMENTACK);
601607
netRequest.setUrl(QString::fromStdString(details.payment_url()));
602-
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, BITCOIN_PAYMENTACK_CONTENTTYPE);
608+
netRequest.setHeader(QNetworkRequest::ContentTypeHeader, BIP71_MIMETYPE_PAYMENT);
603609
netRequest.setRawHeader("User-Agent", CLIENT_NAME.c_str());
604-
netRequest.setRawHeader("Accept", BITCOIN_PAYMENTACK_MIMETYPE);
610+
netRequest.setRawHeader("Accept", BIP71_MIMETYPE_PAYMENTACK);
605611

606612
payments::Payment payment;
607613
payment.set_merchant_data(details.merchant_data());
@@ -663,7 +669,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
663669
QByteArray data = reply->readAll();
664670

665671
QString requestType = reply->request().attribute(QNetworkRequest::User).toString();
666-
if (requestType == "PaymentRequest")
672+
if (requestType == BIP70_MESSAGE_PAYMENTREQUEST)
667673
{
668674
PaymentRequestPlus request;
669675
SendCoinsRecipient recipient;
@@ -679,7 +685,7 @@ void PaymentServer::netRequestFinished(QNetworkReply* reply)
679685

680686
return;
681687
}
682-
else if (requestType == "PaymentACK")
688+
else if (requestType == BIP70_MESSAGE_PAYMENTACK)
683689
{
684690
payments::PaymentACK paymentACK;
685691
if (!paymentACK.ParseFromArray(data.data(), data.size()))

0 commit comments

Comments
 (0)