Skip to content

Commit 062c8b6

Browse files
committed
Merge #11991: [qt] Receive: checkbox for bech32 address
63ac890 [qt] receive tab: bech32 address opt-in checkbox (Sjors Provoost) Pull request description: <img width="647" alt="schermafbeelding 2018-01-12 om 18 34 48" src="https://user-images.githubusercontent.com/10217/34887691-a6a796fe-f7c7-11e7-8b89-87ce07c61ce3.png"> Checkbox does what you would expect. Press tab from the amount field to get there. It's unchecked by default. When launched with `-addresstype=bech32` it's checked by default. When launched with `-addresstype=legacy` it unchecked and disabled. The change in `receivecoinsdialog.ui` is smaller than it looks, due to the way git handles XML diffs. I had to add a horizontal spacer to make it look decent, see bitcoin/bitcoin#11950 (comment). This causes column numbers to change in the rest of the grid. I recommend testing on at least one other OS than OSX to be on the safe side. Tree-SHA512: ec4b733b796d9a94278a5d8040a69d9574ef50021e68f94f61f2da75d1bb57f39272cbc9f1f7d34f733a19640daf666a23844fcd132f83bfdaf327d9d1d6f105
2 parents cad504b + 63ac890 commit 062c8b6

File tree

8 files changed

+124
-40
lines changed

8 files changed

+124
-40
lines changed

src/qt/addresstablemodel.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ void AddressTableModel::updateEntry(const QString &address,
341341
priv->updateEntry(address, label, isMine, purpose, status);
342342
}
343343

344-
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address)
344+
QString AddressTableModel::addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type)
345345
{
346346
std::string strLabel = label.toStdString();
347347
std::string strAddress = address.toStdString();
@@ -384,8 +384,8 @@ QString AddressTableModel::addRow(const QString &type, const QString &label, con
384384
return QString();
385385
}
386386
}
387-
wallet->LearnRelatedScripts(newKey, g_address_type);
388-
strAddress = EncodeDestination(GetDestinationForKey(newKey, g_address_type));
387+
wallet->LearnRelatedScripts(newKey, address_type);
388+
strAddress = EncodeDestination(GetDestinationForKey(newKey, address_type));
389389
}
390390
else
391391
{

src/qt/addresstablemodel.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include <QAbstractTableModel>
99
#include <QStringList>
1010

11+
enum OutputType : int;
12+
1113
class AddressTablePriv;
1214
class WalletModel;
1315

@@ -61,7 +63,7 @@ class AddressTableModel : public QAbstractTableModel
6163
/* Add an address to the model.
6264
Returns the added address on success, and an empty string otherwise.
6365
*/
64-
QString addRow(const QString &type, const QString &label, const QString &address);
66+
QString addRow(const QString &type, const QString &label, const QString &address, const OutputType address_type);
6567

6668
/* Look up label for address in address book, if not found return empty string.
6769
*/

src/qt/editaddressdialog.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#include <QDataWidgetMapper>
1212
#include <QMessageBox>
1313

14+
extern OutputType g_address_type;
15+
1416
EditAddressDialog::EditAddressDialog(Mode _mode, QWidget *parent) :
1517
QDialog(parent),
1618
ui(new Ui::EditAddressDialog),
@@ -77,7 +79,8 @@ bool EditAddressDialog::saveCurrentRow()
7779
address = model->addRow(
7880
mode == NewSendingAddress ? AddressTableModel::Send : AddressTableModel::Receive,
7981
ui->labelEdit->text(),
80-
ui->addressEdit->text());
82+
ui->addressEdit->text(),
83+
g_address_type);
8184
break;
8285
case EditReceivingAddress:
8386
case EditSendingAddress:

src/qt/forms/receivecoinsdialog.ui

Lines changed: 88 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<x>0</x>
88
<y>0</y>
99
<width>776</width>
10-
<height>364</height>
10+
<height>396</height>
1111
</rect>
1212
</property>
1313
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,1">
@@ -28,6 +28,22 @@
2828
<layout class="QVBoxLayout" name="verticalLayout_3">
2929
<item>
3030
<layout class="QGridLayout" name="gridLayout">
31+
<item row="5" column="0">
32+
<widget class="QLabel" name="label">
33+
<property name="toolTip">
34+
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
35+
</property>
36+
<property name="text">
37+
<string>&amp;Amount:</string>
38+
</property>
39+
<property name="alignment">
40+
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
41+
</property>
42+
<property name="buddy">
43+
<cstring>reqAmount</cstring>
44+
</property>
45+
</widget>
46+
</item>
3147
<item row="6" column="0">
3248
<widget class="QLabel" name="label_3">
3349
<property name="toolTip">
@@ -51,13 +67,6 @@
5167
</property>
5268
</widget>
5369
</item>
54-
<item row="6" column="2">
55-
<widget class="QLineEdit" name="reqMessage">
56-
<property name="toolTip">
57-
<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>
58-
</property>
59-
</widget>
60-
</item>
6170
<item row="2" column="2">
6271
<widget class="QLabel" name="label_5">
6372
<property name="text">
@@ -81,32 +90,10 @@
8190
</property>
8291
</widget>
8392
</item>
84-
<item row="5" column="0">
85-
<widget class="QLabel" name="label">
86-
<property name="toolTip">
87-
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
88-
</property>
89-
<property name="text">
90-
<string>&amp;Amount:</string>
91-
</property>
92-
<property name="alignment">
93-
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
94-
</property>
95-
<property name="buddy">
96-
<cstring>reqAmount</cstring>
97-
</property>
98-
</widget>
99-
</item>
100-
<item row="5" column="2">
101-
<widget class="BitcoinAmountField" name="reqAmount">
102-
<property name="minimumSize">
103-
<size>
104-
<width>80</width>
105-
<height>0</height>
106-
</size>
107-
</property>
93+
<item row="6" column="2">
94+
<widget class="QLineEdit" name="reqMessage">
10895
<property name="toolTip">
109-
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
96+
<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>
11097
</property>
11198
</widget>
11299
</item>
@@ -174,6 +161,73 @@
174161
</property>
175162
</widget>
176163
</item>
164+
<item row="5" column="2">
165+
<layout class="QHBoxLayout" name="horizontalLayout_6">
166+
<item>
167+
<widget class="BitcoinAmountField" name="reqAmount">
168+
<property name="sizePolicy">
169+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
170+
<horstretch>0</horstretch>
171+
<verstretch>0</verstretch>
172+
</sizepolicy>
173+
</property>
174+
<property name="minimumSize">
175+
<size>
176+
<width>80</width>
177+
<height>0</height>
178+
</size>
179+
</property>
180+
<property name="maximumSize">
181+
<size>
182+
<width>1000</width>
183+
<height>100</height>
184+
</size>
185+
</property>
186+
<property name="toolTip">
187+
<string>An optional amount to request. Leave this empty or zero to not request a specific amount.</string>
188+
</property>
189+
</widget>
190+
</item>
191+
<item>
192+
<widget class="QCheckBox" name="useBech32">
193+
<property name="sizePolicy">
194+
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
195+
<horstretch>0</horstretch>
196+
<verstretch>0</verstretch>
197+
</sizepolicy>
198+
</property>
199+
<property name="maximumSize">
200+
<size>
201+
<width>1000</width>
202+
<height>16777215</height>
203+
</size>
204+
</property>
205+
<property name="focusPolicy">
206+
<enum>Qt::StrongFocus</enum>
207+
</property>
208+
<property name="toolTip">
209+
<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>
210+
</property>
211+
<property name="text">
212+
<string>Generate Bech32 address</string>
213+
</property>
214+
</widget>
215+
</item>
216+
<item>
217+
<spacer name="horizontalSpacer_3">
218+
<property name="orientation">
219+
<enum>Qt::Horizontal</enum>
220+
</property>
221+
<property name="sizeHint" stdset="0">
222+
<size>
223+
<width>0</width>
224+
<height>0</height>
225+
</size>
226+
</property>
227+
</spacer>
228+
</item>
229+
</layout>
230+
</item>
177231
</layout>
178232
</item>
179233
</layout>
@@ -306,6 +360,7 @@
306360
<tabstops>
307361
<tabstop>reqLabel</tabstop>
308362
<tabstop>reqAmount</tabstop>
363+
<tabstop>useBech32</tabstop>
309364
<tabstop>reqMessage</tabstop>
310365
<tabstop>receiveButton</tabstop>
311366
<tabstop>clearButton</tabstop>

src/qt/receivecoinsdialog.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5+
#include <wallet/wallet.h>
6+
57
#include <qt/receivecoinsdialog.h>
68
#include <qt/forms/ui_receivecoinsdialog.h>
79

@@ -41,6 +43,15 @@ ReceiveCoinsDialog::ReceiveCoinsDialog(const PlatformStyle *_platformStyle, QWid
4143
ui->removeRequestButton->setIcon(_platformStyle->SingleColorIcon(":/icons/remove"));
4244
}
4345

46+
// configure bech32 checkbox, disable if launched with legacy as default:
47+
if (model->getDefaultAddressType() == OUTPUT_TYPE_BECH32) {
48+
ui->useBech32->setCheckState(Qt::Checked);
49+
} else {
50+
ui->useBech32->setCheckState(Qt::Unchecked);
51+
}
52+
53+
ui->useBech32->setVisible(model->getDefaultAddressType() != OUTPUT_TYPE_LEGACY);
54+
4455
// context menu actions
4556
QAction *copyURIAction = new QAction(tr("Copy URI"), this);
4657
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
@@ -133,7 +144,11 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
133144
QString address;
134145
QString label = ui->reqLabel->text();
135146
/* Generate new receiving address */
136-
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "");
147+
OutputType address_type = model->getDefaultAddressType();
148+
if (address_type != OUTPUT_TYPE_LEGACY) {
149+
address_type = ui->useBech32->isChecked() ? OUTPUT_TYPE_BECH32 : OUTPUT_TYPE_P2SH_SEGWIT;
150+
}
151+
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);
137152
SendCoinsRecipient info(address, label,
138153
ui->reqAmount->value(), ui->reqMessage->text());
139154
ReceiveRequestDialog *dialog = new ReceiveRequestDialog(this);

src/qt/walletmodel.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,11 @@ bool WalletModel::hdEnabled() const
733733
return wallet->IsHDEnabled();
734734
}
735735

736+
OutputType WalletModel::getDefaultAddressType() const
737+
{
738+
return g_address_type;
739+
}
740+
736741
int WalletModel::getDefaultConfirmTarget() const
737742
{
738743
return nTxConfirmTarget;

src/qt/walletmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
#include <QObject>
1717

18+
enum OutputType : int;
19+
1820
class AddressTableModel;
1921
class OptionsModel;
2022
class PlatformStyle;
@@ -214,6 +216,8 @@ class WalletModel : public QObject
214216

215217
bool hdEnabled() const;
216218

219+
OutputType getDefaultAddressType() const;
220+
217221
int getDefaultConfirmTarget() const;
218222

219223
private:

src/wallet/wallet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ enum WalletFeature
9999
FEATURE_LATEST = FEATURE_COMPRPUBKEY // HD is optional, use FEATURE_COMPRPUBKEY as latest version
100100
};
101101

102-
enum OutputType
102+
enum OutputType : int
103103
{
104104
OUTPUT_TYPE_NONE,
105105
OUTPUT_TYPE_LEGACY,

0 commit comments

Comments
 (0)