From 63ac8907ce6ab095b37858d6e96946b59ce1c13f Mon Sep 17 00:00:00 2001 From: Sjors Provoost Date: Tue, 16 Jan 2018 20:11:40 +0000 Subject: [qt] receive tab: bech32 address opt-in checkbox When launched with -adresstype=legacy the checkbox will be hidden. --- src/qt/addresstablemodel.cpp | 6 +- src/qt/addresstablemodel.h | 4 +- src/qt/editaddressdialog.cpp | 5 +- src/qt/forms/receivecoinsdialog.ui | 121 +++++++++++++++++++++++++++---------- src/qt/receivecoinsdialog.cpp | 17 +++++- src/qt/walletmodel.cpp | 5 ++ src/qt/walletmodel.h | 4 ++ 7 files changed, 123 insertions(+), 39 deletions(-) (limited to 'src/qt') diff --git a/src/qt/addresstablemodel.cpp b/src/qt/addresstablemodel.cpp index a2521a1e9e..74f0db3520 100644 --- a/src/qt/addresstablemodel.cpp +++ b/src/qt/addresstablemodel.cpp @@ -341,7 +341,7 @@ void AddressTableModel::updateEntry(const QString &address, priv->updateEntry(address, label, isMine, purpose, status); } -QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address) +QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type) { std::string strLabel = label.toStdString(); std::string strAddress = address.toStdString(); @@ -384,8 +384,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con return QString(); } } - wallet->LearnRelatedScripts(newKey, g_address_type); - strAddress = EncodeDestination(GetDestinationForKey(newKey, g_address_type)); + wallet->LearnRelatedScripts(newKey, address_type); + strAddress = EncodeDestination(GetDestinationForKey(newKey, address_type)); } else { diff --git a/src/qt/addresstablemodel.h b/src/qt/addresstablemodel.h index d04b95ebae..11439e25d5 100644 --- a/src/qt/addresstablemodel.h +++ b/src/qt/addresstablemodel.h @@ -8,6 +8,8 @@ #include #include +enum OutputType : int; + class AddressTablePriv; class WalletModel; @@ -61,7 +63,7 @@ public: /* Add an address to the model. Returns the added address on success, and an empty string otherwise. */ - QString addRow(const QString &type, const QString &label, const QString &address); + QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type); /* Look up label for address in address book, if not found return empty string. */ diff --git a/src/qt/editaddressdialog.cpp b/src/qt/editaddressdialog.cpp index 6b7df2f2b9..a945fc6aa0 100644 --- a/src/qt/editaddressdialog.cpp +++ b/src/qt/editaddressdialog.cpp @@ -11,6 +11,8 @@ #include #include +extern OutputType g_address_type; + EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) : QDialog(parent), ui(new Ui::EditAddressDialog), @@ -77,7 +79,8 @@ bool EditAddressDialog::saveCurrentRow() address = model->addRow( mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive, ui->labelEdit->text(), - ui->addressEdit->text()); + ui->addressEdit->text(), + g_address_type); break; case EditReceivingAddress: case EditSendingAddress: diff --git a/src/qt/forms/receivecoinsdialog.ui b/src/qt/forms/receivecoinsdialog.ui index 58f030ebf0..09fb435a58 100644 --- a/src/qt/forms/receivecoinsdialog.ui +++ b/src/qt/forms/receivecoinsdialog.ui @@ -7,7 +7,7 @@ 0 0 776 - 364 + 396 @@ -28,6 +28,22 @@ + + + + An optional amount to request. Leave this empty or zero to not request a specific amount. + + + &Amount: + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + reqAmount + + + @@ -51,13 +67,6 @@ - - - - An optional message to attach to the payment request, which will be displayed when the request is opened. Note: The message will not be sent with the payment over the Bitcoin network. - - - @@ -81,32 +90,10 @@ - - - - An optional amount to request. Leave this empty or zero to not request a specific amount. - - - &Amount: - - - Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter - - - reqAmount - - - - - - - - 80 - 0 - - + + - An optional amount to request. Leave this empty or zero to not request a specific amount. + An optional message to attach to the payment request, which will be displayed when the request is opened. Note: The message will not be sent with the payment over the Bitcoin network. @@ -174,6 +161,73 @@ + + + + + + + 0 + 0 + + + + + 80 + 0 + + + + + 1000 + 100 + + + + An optional amount to request. Leave this empty or zero to not request a specific amount. + + + + + + + + 0 + 0 + + + + + 1000 + 16777215 + + + + Qt::StrongFocus + + + Bech32 addresses (BIP-173) are cheaper to spend from and offer better protection against typos. When unchecked a P2SH wrapped SegWit address will be created, compatible with older wallets. + + + Generate Bech32 address + + + + + + + Qt::Horizontal + + + + 0 + 0 + + + + + + @@ -306,6 +360,7 @@ reqLabel reqAmount + useBech32 reqMessage receiveButton clearButton diff --git a/src/qt/receivecoinsdialog.cpp b/src/qt/receivecoinsdialog.cpp index e07f2b74ee..f6c2fa7de7 100644 --- a/src/qt/receivecoinsdialog.cpp +++ b/src/qt/receivecoinsdialog.cpp @@ -2,6 +2,8 @@ // Distributed under the MIT software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include + #include #include @@ -41,6 +43,15 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove")); } + // configure bech32 checkbox, disable if launched with legacy as default: + if (model->getDefaultAddressType() == OUTPUT_TYPE_BECH32) { + ui->useBech32->setCheckState(Qt::Checked); + } else { + ui->useBech32->setCheckState(Qt::Unchecked); + } + + ui->useBech32->setVisible(model->getDefaultAddressType() != OUTPUT_TYPE_LEGACY); + // context menu actions QAction *copyURIAction = new QAction(tr("Copy URI"), this); QAction *copyLabelAction = new QAction(tr("Copy label"), this); @@ -133,7 +144,11 @@ void ReceiveCoinsDialog::on_receiveButton_clicked() QString address; QString label = ui->reqLabel->text(); /* Generate new receiving address */ - address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, ""); + OutputType address_type = model->getDefaultAddressType(); + if (address_type != OUTPUT_TYPE_LEGACY) { + address_type = ui->useBech32->isChecked() ? OUTPUT_TYPE_BECH32 : OUTPUT_TYPE_P2SH_SEGWIT; + } + address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type); SendCoinsRecipient info(address, label, ui->reqAmount->value(), ui->reqMessage->text()); ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this); diff --git a/src/qt/walletmodel.cpp b/src/qt/walletmodel.cpp index 494b46905d..4d7e977fcb 100644 --- a/src/qt/walletmodel.cpp +++ b/src/qt/walletmodel.cpp @@ -733,6 +733,11 @@ bool WalletModel::hdEnabled() const return wallet->IsHDEnabled(); } +OutputType WalletModel::getDefaultAddressType() const +{ + return g_address_type; +} + int WalletModel::getDefaultConfirmTarget() const { return nTxConfirmTarget; diff --git a/src/qt/walletmodel.h b/src/qt/walletmodel.h index 7d7e4f160e..9e13de79be 100644 --- a/src/qt/walletmodel.h +++ b/src/qt/walletmodel.h @@ -15,6 +15,8 @@ #include +enum OutputType : int; + class AddressTableModel; class OptionsModel; class PlatformStyle; @@ -214,6 +216,8 @@ public: bool hdEnabled() const; + OutputType getDefaultAddressType() const; + int getDefaultConfirmTarget() const; private: -- cgit v1.2.3