From 93cd3693c2ccc010a997d5596fb6582603f41d88 Mon Sep 17 00:00:00 2001 From: crowning- Date: Tue, 27 Sep 2016 09:48:52 +0200 Subject: [PATCH] [UI] Add Instantsend parameter to URI/QR-code (#1042) --- src/qt/forms/receivecoinsdialog.ui | 16 +++++++++++++--- src/qt/guiutil.cpp | 15 +++++++++++++++ src/qt/receivecoinsdialog.cpp | 1 + src/qt/receiverequestdialog.cpp | 4 ++++ src/qt/test/uritests.cpp | 28 ++++++++++++++++++++++++++++ 5 files changed, 61 insertions(+), 3 deletions(-) diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui index 1a4ac15adb..83909a0596 100644 --- a/src/qt/forms/receivecoinsdialog.ui +++ b/src/qt/forms/receivecoinsdialog.ui @@ -7,7 +7,7 @@ 0 0 776 - 364 + 387 @@ -127,7 +127,7 @@ - + @@ -176,13 +176,23 @@ - + + + + + Request InstantSend + + + true + + + diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp index 6496500e37..581fba1654 100644 --- a/src/qt/guiutil.cpp +++ b/src/qt/guiutil.cpp @@ -151,6 +151,8 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) QUrlQuery uriQuery(uri); QList > items = uriQuery.queryItems(); #endif + + rv.fUseInstantSend = false; for (QList >::iterator i = items.begin(); i != items.end(); i++) { bool fShouldReturnFalse = false; @@ -165,6 +167,13 @@ bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) rv.label = i->second; fShouldReturnFalse = false; } + if (i->first == "IS") + { + if(i->second.compare(QString("1")) == 0) + rv.fUseInstantSend = true; + + fShouldReturnFalse = false; + } if (i->first == "message") { rv.message = i->second; @@ -230,6 +239,12 @@ QString formatBitcoinURI(const SendCoinsRecipient &info) ret += QString("%1message=%2").arg(paramCount == 0 ? "?" : "&").arg(msg); paramCount++; } + + if(info.fUseInstantSend) + { + ret += QString("%1IS=1").arg(paramCount == 0 ? "?" : "&"); + paramCount++; + } return ret; } diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index 69cc0efa81..65c42e3d7b 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -152,6 +152,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() } SendCoinsRecipient info(address, label, ui->reqAmount->value(), ui->reqMessage->text()); + info.fUseInstantSend = ui->checkUseInstantSend->isChecked(); ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); dialog->setAttribute(Qt::WA_DeleteOnClose); dialog->setModel(model->getOptionsModel()); diff --git a/src/qt/receiverequestdialog.cpp b/src/qt/receiverequestdialog.cpp index a6fa3efc9b..fada57c80f 100644 --- a/src/qt/receiverequestdialog.cpp +++ b/src/qt/receiverequestdialog.cpp @@ -149,6 +149,10 @@ void ReceiveRequestDialog::update() html += ""+tr("Label")+": " + GUIUtil::HtmlEscape(info.label) + "
"; if(!info.message.isEmpty()) html += ""+tr("Message")+": " + GUIUtil::HtmlEscape(info.message) + "
"; + if(info.fUseInstantSend) + html += ""+tr("InstantSend")+": Yes
"; + else + html += ""+tr("InstantSend")+": No
"; ui->outUri->setText(html); #ifdef USE_QRCODE diff --git a/src/qt/test/uritests.cpp b/src/qt/test/uritests.cpp index f045c45e2d..fd55151249 100644 --- a/src/qt/test/uritests.cpp +++ b/src/qt/test/uritests.cpp @@ -63,4 +63,32 @@ void URITests::uriTests() uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=1,000.0&label=Some Example")); QVERIFY(!GUIUtil::parseBitcoinURI(uri, &rv)); + + uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=100&label=Some Example&message=Some Example Message&IS=1")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg")); + QVERIFY(rv.amount == 10000000000LL); + QVERIFY(rv.label == QString("Some Example")); + QVERIFY(rv.message == QString("Some Example Message")); + QVERIFY(rv.fUseInstantSend == 1); + + uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?amount=100&label=Some Example&message=Some Example Message&IS=Something Invalid")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.address == QString("XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg")); + QVERIFY(rv.amount == 10000000000LL); + QVERIFY(rv.label == QString("Some Example")); + QVERIFY(rv.message == QString("Some Example Message")); + QVERIFY(rv.fUseInstantSend != 1); + + uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?IS=1")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.fUseInstantSend == 1); + + uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg?IS=0")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.fUseInstantSend != 1); + + uri.setUrl(QString("dash:XwnLY9Tf7Zsef8gMGL2fhWA9ZmMjt4KPwg")); + QVERIFY(GUIUtil::parseBitcoinURI(uri, &rv)); + QVERIFY(rv.fUseInstantSend != 1); }