New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[qt] Receive: checkbox for bech32 address #11991
Conversation
I haven't tried, but this should work with or without #11937. |
Sounds like a good idea to me, when updating the PR you might want to fix the spelling in the commit message: reveice -> receive. utACK |
fd2d57a
to
92fca0e
Compare
Concept ACK. Needs rebase. |
94c218e
to
2e68c57
Compare
Rebased on top of 5d92439 (and fixed typo in commit message). By the way, I generally use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK. Needs rebase.
src/qt/walletmodel.h
Outdated
@@ -217,6 +217,8 @@ class WalletModel : public QObject | |||
int getDefaultConfirmTarget() const; | |||
|
|||
bool getDefaultWalletRbf() const; | |||
|
|||
bool getDefaultBech32() const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Expose address type instead getDefaultAddressType()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although it introduces a compiler warning:
qt/receivecoinsdialog.cpp:45:62: warning: comparison of constant 'OUTPUT_TYPE_BECH32' (3)
with expression of type 'bool' is always false [-Wtautological-constant-out-of-range-compare]
ui->bech32->setCheckState(model->getDefaultAddressType() == OUTPUT_TYPE_BECH32 ? Qt::Checked : Qt::Unchecked)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nvm, I broke it.
@Sjors what do think about aligning this next to the units dropdown instead of centered? Not sure if this is intended to look like this: Also needs rebase |
I'll rebase after the SegWit stuff is merged. @jb55 good catch, it doesn't look like that on OSX (see my own screenshot). It should be more or less attached to the currency dropdown, definitely not centered. I'm guessing you're on Ubuntu? I'll try to reproduce. What happens when you make the window a little less wide? I notice it shows "bits" for you, so you've somehow combined this with your own PR? That's probably not related though. |
I'm guessing you're on Ubuntu? I'll try to reproduce. What happens when you make the window a little less wide?
I'm using nixos with a tiling window manager (xmonad), allowing me to resize it to any size.
It gets closer to the dropdown when I make it shorter.
I notice it shows "bits" for you, so you've somehow combined this with your own PR? That's probably not related though.
Yeah I'm just in my gui integration testing branch, but nothing else should be affecting this particular issue.
|
f58e356
to
4dc35c6
Compare
Rebased. Horizontally expanding the window now behaves. |
Tested ACK 4dc35c6c2677a470ee2189c11fa16aedc2b8df56
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct me if I'm wrong but if g_address_type
is OUTPUT_TYPE_BECH32
and the checkbox is unchecked, it will still use bech32 type.
Edit: in other words, maybe if g_address_type == OUTPUT_TYPE_BECH32
the checkbox should be checked and disabled.
Some review comments. Have to test though.
src/qt/forms/receivecoinsdialog.ui
Outdated
</widget> | ||
</item> | ||
<item> | ||
<widget class="QCheckBox" name="bech32"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, use_bech32_checkbox
or similar? Just bech32
is a weak name IMO.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll rename to useBech32
.
<verstretch>0</verstretch> | ||
</sizepolicy> | ||
</property> | ||
<property name="maximumSize"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The horizontal resize UI glitch I encountered above seems be caused by the input field and dropdown menu having a really large maximum width. In case of the currency dropdown, this causes the whitespace around the dropdown to stretch, which in turn causes it to be separated from the bech32 checkbox. I'm not sure if there's another way to prevent that. I also don't know if this max size plays well with l18n.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
src/qt/addresstablemodel.cpp
Outdated
@@ -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 bool bech32) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could receive OutputType type
instead of bool bech32
? Just pass that to AddDestinationForKey
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a boolean makes more sense here, because the check-box can only tell that OUTPUT_TYPE_BECH32
should be used. If it's unchecked, it doesn't know if the fallback is OUTPUT_TYPE_P2SH
or OUTPUT_TYPE_LEGACY
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: it now uses OutputType
.
src/qt/walletmodel.h
Outdated
@@ -214,6 +216,9 @@ class WalletModel : public QObject | |||
|
|||
bool hdEnabled() const; | |||
|
|||
// returns OUTPUT_TYPE_LEGACY, OUTPUT_TYPE_P2SH or OUTPUT_TYPE_BECH32 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove comment? Return type is enough.
@@ -733,6 +733,11 @@ bool WalletModel::hdEnabled() const | |||
return wallet->IsHDEnabled(); | |||
} | |||
|
|||
OutputType WalletModel::getDefaultAddressType() const | |||
{ | |||
return g_address_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, assert(g_address_type != OUTPUT_TYPE_NONE)
ping @sipa.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feature doesn't really care if OUTPUT_TYPE_NONE Is returned though; the checkbox would be unchecked. So is this really the place for an assert? If so, I'm happy to add it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine. NONE will be caught if it's passed down and actually used somewhere.
I compiled this PR for windows to test but the checkbox is not there. I guess right now this PR is only for linux? |
@molxyz QT is cross-platform, so if the check-box is missing on Windows that's either a bug or something went wrong when you compiled it. I'll try it in my own VM once I have that setup. |
@promag when launched with |
Right, either the checkbox should be hidden or disabled? |
@promag I'll disable it. |
4dc35c6
to
9ee4b06
Compare
|
@Sjors restarted the failing job. Not the 1st time I see that test failing. Seems that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK c3752c4324ce8a4a9a615896e50f771df83f945d. Looks great!
Other feedback:
-
If I hover over the disabled checkbox with
-addresstype=legacy
, I still see tooltip suggesting that generated address will be a segwit address, which seems misleading. It would be better to hide the checkbox in this case, or to show a more accurate tooltip when the box is disabled. Hiding the checkbox doesn't seem like a terrible thing given that the requested configuration is "legacy" and not having a checkbox was the old behavior. -
It might be useful if address type were shown in requested payments details popup (displayed when you double click on a requested payment). This would make it easier for users to distinguish address types, and see effect of the new checkbox,
-
Would be nice to have some unit test coverage for this.
-
I tend to agree that
-defaultaddresstype
would be clearer name than-addresstype
. Could open a separate PR to rename it and see what people think of the idea. -
Maybe say "Generate Bech32 address" instead of "Use Bech32 address" since latter could imply that it is using something that already exists.
-
Maybe incorporate some help wording suggested by gmaxwell in "This will use an address that begins with BC1 instead of 1 and will result in lower transaction fees in the future. BC1 style addresses are not accepted everywhere yet. Turn off this option if the sending party says your address is invalid" or similar." https://botbot.me/freenode/bitcoin-core-dev/msg/95662952/
src/qt/editaddressdialog.cpp
Outdated
@@ -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> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could declare g_address_type as extern if you wanted to remove this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, but wasn't able to do this in receivecoinsdialog (undeclared identifier 'OUTPUT_TYPE_BECH32
, etc).
src/qt/receivecoinsdialog.cpp
Outdated
} | ||
|
||
if (model->getDefaultAddressType() == OUTPUT_TYPE_LEGACY) { | ||
ui->useBech32->setEnabled(false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might want to call setenabled unconditionally (ui->useBech32->setEnabled(model->getDefaultAddressType() == OUTPUT_TYPE_LEGACY))
) in case we want to support changing default address type in the ui in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
src/qt/receivecoinsdialog.cpp
Outdated
@@ -133,7 +146,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 = g_address_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use model->getDefaultAddressType() here instead of g_address_type to be more consistent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes then perhaps next line only use address_type
for comparison.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tACK, typo aside
Also thumbs-upped a few comments that I agree with, though non-blockers.
src/qt/forms/receivecoinsdialog.ui
Outdated
<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 PS2SH wrapped SegWit address will be created, compatible with older wallets.</string> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/PS2SH /P2SH-/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/qt/receivecoinsdialog.cpp
Outdated
@@ -133,7 +146,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 = g_address_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes then perhaps next line only use address_type
for comparison.
c3752c4
to
aac36a5
Compare
Todo, though can probably be merged without:
Leaving for future PRs:
Arguably too late if that doesn't get into the 0.16 release. |
When launched with -adresstype=legacy the checkbox will be hidden.
aac36a5
to
63ac890
Compare
Pff, not sure how to avoid turning the tooltip into War & Peace. How about:
|
Here's my stab at a slightly shorter version (270 chars insted of 359):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
utACK 63ac890. Changes since last review: removed wallet.h include, hiding checkbox with legacy option, using getDefaultAddressType instead of g_address_type another place, fixing PS2SH typo.
Pff, not sure how to avoid turning the tooltip into War & Peace. How about... #11991 (comment)
That seems very good. flack's version is also ok, but I think yours is better because his kind of sounds like something magical about the letters "bc1" lowers the fees.
Arguably too late if that doesn't get into the 0.16 release.
0.16 branch hasn't even been created yet, so it seems not too late. Anyway I suggested creating a PR because I liked your idea, but thought it would be better to propose someplace else, rather than here.
Well, it is Magical Internet Money after all :-) on a slightly more serious note: I actually had to scratch my head for a minute when reading
because it's not immediately obvious that the lower transaction fees only apply when you actually use the Bech32 address. If I'm not really familiar with how all this works, I might get the impression that all my future transactions will somehow get a discounted fee. Or is this meant to convey that the mempool would be less full if everybody used Bech32, thus lowering the fee for everyone? |
Yes, definitely. I liked the part of your suggestion that says this "will lower your fees when you spend it." I was going to mention this but forgot. |
Perhaps it would be better worded as "an address that begins with bc1 and will lower your fees when you spend from it"? |
@@ -11,6 +11,8 @@ | |||
#include <QDataWidgetMapper> | |||
#include <QMessageBox> | |||
|
|||
extern OutputType g_address_type; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can also be done in a follow up PR, but directly accessing the underlaying non QT system should be avoided. This should be accessed via WalletModel.
@@ -7,7 +7,7 @@ | |||
<x>0</x> | |||
<y>0</y> | |||
<width>776</width> | |||
<height>364</height> | |||
<height>396</height> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the reason for changing the height?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it's QT Creators magic... I guess others do usually edit those files "by hand" to avoid such "larger" unnecessary changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was magic. Didn't seem worth tweaking with so many other changes in that file, but will keep in mind.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested ACK 63ac890
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 #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
…constructor cc90a4f Avoid potential null dereference in ReceiveCoinsDialog constructor (Russell Yanofsky) Pull request description: Not a bug in practice because current `WalletModel::getDefaultAddressType()` implementation does not dereference its `this` pointer. Encountered issue while rebasing #10244 after #11991 was merged. Tree-SHA512: d76afc410d4a436ec62936196fdac1af89c221d8c0d6e73349024afe55bbf8820f843177a8fe8210aa8021d45a17a0ecd9b6f693381e3edb234d9897cece29d7
… P2WPKH or P2WSH 596c446 [wallet] use P2WPKH change output if any destination is P2WPKH or P2WSH (Sjors Provoost) Pull request description: If `-changetype` is not explicitly set, then regardless of `-addresstype`, the wallet will use a ~`bech32` change address~ `P2WPKH` change output if any destination is `P2WPKH` or `P2WSH`. This seems more intuitive to me and more in line with the spirit of [BIP-69](https://github.com/bitcoin/bips/blob/master/bip-0069.mediawiki). When combined with #11991 a QT user could opt to use `bech32` exclusively without having to figure out how to launch with `-changetype=bech32`, although so would #11937. Tree-SHA512: 9238d3ccd1f3be8dfdd43444ccf45d6bdc6584ced3172a3045f3ecfec4a7cc8999db0cdb76ae49236492a84e6dbf3a1fdf18544d3eaf6d518e1f8bd241db33e7
…Dialog constructor cc90a4f Avoid potential null dereference in ReceiveCoinsDialog constructor (Russell Yanofsky) Pull request description: Not a bug in practice because current `WalletModel::getDefaultAddressType()` implementation does not dereference its `this` pointer. Encountered issue while rebasing bitcoin#10244 after bitcoin#11991 was merged. Tree-SHA512: d76afc410d4a436ec62936196fdac1af89c221d8c0d6e73349024afe55bbf8820f843177a8fe8210aa8021d45a17a0ecd9b6f693381e3edb234d9897cece29d7
…Dialog constructor cc90a4f Avoid potential null dereference in ReceiveCoinsDialog constructor (Russell Yanofsky) Pull request description: Not a bug in practice because current `WalletModel::getDefaultAddressType()` implementation does not dereference its `this` pointer. Encountered issue while rebasing bitcoin#10244 after bitcoin#11991 was merged. Tree-SHA512: d76afc410d4a436ec62936196fdac1af89c221d8c0d6e73349024afe55bbf8820f843177a8fe8210aa8021d45a17a0ecd9b6f693381e3edb234d9897cece29d7
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 #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.