Browse Source

[qt] receive tab: bech32 address opt-in checkbox

When launched with -adresstype=legacy the checkbox will be hidden.
0.16
Sjors Provoost 7 years ago
parent
commit
63ac8907ce
No known key found for this signature in database
GPG Key ID: 57FF9BDBCC301009
  1. 6
      src/qt/addresstablemodel.cpp
  2. 4
      src/qt/addresstablemodel.h
  3. 5
      src/qt/editaddressdialog.cpp
  4. 121
      src/qt/forms/receivecoinsdialog.ui
  5. 17
      src/qt/receivecoinsdialog.cpp
  6. 5
      src/qt/walletmodel.cpp
  7. 4
      src/qt/walletmodel.h
  8. 2
      src/wallet/wallet.h

6
src/qt/addresstablemodel.cpp

@ -341,7 +341,7 @@ void AddressTableModel::updateEntry(const QString &address, @@ -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 @@ -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
{

4
src/qt/addresstablemodel.h

@ -8,6 +8,8 @@ @@ -8,6 +8,8 @@
#include <QAbstractTableModel>
#include <QStringList>
enum OutputType : int;
class AddressTablePriv;
class WalletModel;
@ -61,7 +63,7 @@ public: @@ -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.
*/

5
src/qt/editaddressdialog.cpp

@ -11,6 +11,8 @@ @@ -11,6 +11,8 @@
#include <QDataWidgetMapper>
#include <QMessageBox>
extern OutputType g_address_type;
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
QDialog(parent),
ui(new Ui::EditAddressDialog),
@ -77,7 +79,8 @@ bool EditAddressDialog::saveCurrentRow() @@ -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:

121
src/qt/forms/receivecoinsdialog.ui

@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>776</width>
<height>364</height>
<height>396</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
@ -28,6 +28,22 @@ @@ -28,6 +28,22 @@
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
</property>
<property name="text">
<string>&amp;Amount:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>reqAmount</cstring>
</property>
</widget>
</item>
<item row="6" column="0">
<widget class="QLabel" name="label_3">
<property name="toolTip">
@ -51,13 +67,6 @@ @@ -51,13 +67,6 @@
</property>
</widget>
</item>
<item row="6" column="2">
<widget class="QLineEdit" name="reqMessage">
<property name="toolTip">
<string>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.</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLabel" name="label_5">
<property name="text">
@ -81,32 +90,10 @@ @@ -81,32 +90,10 @@
</property>
</widget>
</item>
<item row="5" column="0">
<widget class="QLabel" name="label">
<property name="toolTip">
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
</property>
<property name="text">
<string>&amp;Amount:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
<property name="buddy">
<cstring>reqAmount</cstring>
</property>
</widget>
</item>
<item row="5" column="2">
<widget class="BitcoinAmountField" name="reqAmount">
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<item row="6" column="2">
<widget class="QLineEdit" name="reqMessage">
<property name="toolTip">
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
<string>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.</string>
</property>
</widget>
</item>
@ -174,6 +161,73 @@ @@ -174,6 +161,73 @@
</property>
</widget>
</item>
<item row="5" column="2">
<layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="BitcoinAmountField" name="reqAmount">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>80</width>
<height>0</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>100</height>
</size>
</property>
<property name="toolTip">
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="useBech32">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>1000</width>
<height>16777215</height>
</size>
</property>
<property name="focusPolicy">
<enum>Qt::StrongFocus</enum>
</property>
<property name="toolTip">
<string>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.</string>
</property>
<property name="text">
<string>Generate Bech32 address</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>0</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</item>
</layout>
@ -306,6 +360,7 @@ @@ -306,6 +360,7 @@
<tabstops>
<tabstop>reqLabel</tabstop>
<tabstop>reqAmount</tabstop>
<tabstop>useBech32</tabstop>
<tabstop>reqMessage</tabstop>
<tabstop>receiveButton</tabstop>
<tabstop>clearButton</tabstop>

17
src/qt/receivecoinsdialog.cpp

@ -2,6 +2,8 @@ @@ -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 <wallet/wallet.h>
#include <qt/receivecoinsdialog.h>
#include <qt/forms/ui_receivecoinsdialog.h>
@ -41,6 +43,15 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid @@ -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() @@ -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);

5
src/qt/walletmodel.cpp

@ -733,6 +733,11 @@ bool WalletModel::hdEnabled() const @@ -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;

4
src/qt/walletmodel.h

@ -15,6 +15,8 @@ @@ -15,6 +15,8 @@
#include <QObject>
enum OutputType : int;
class AddressTableModel;
class OptionsModel;
class PlatformStyle;
@ -214,6 +216,8 @@ public: @@ -214,6 +216,8 @@ public:
bool hdEnabled() const;
OutputType getDefaultAddressType() const;
int getDefaultConfirmTarget() const;
private:

2
src/wallet/wallet.h

@ -99,7 +99,7 @@ enum WalletFeature @@ -99,7 +99,7 @@ enum WalletFeature
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
};
enum OutputType
enum OutputType : int
{
OUTPUT_TYPE_NONE,
OUTPUT_TYPE_LEGACY,

Loading…
Cancel
Save