Skip to content

Commit 63b5dfa

Browse files
author
MarcoFalke
committed
Merge #459: Address type dropdown, add Taproot (Receive tab)
c9a77e2 gui: address type dropdown, add bech32m (Sjors Provoost) 56113da wallet: add taprootEnabled() to interface (Sjors Provoost) Pull request description: This PR replaces the Bech32 checkbox with an address type dropdown It "Use Taproot" checkbox to the receive screen for any wallet with a Taproot descriptor. The Bech32m option is hidden for wallets that don't have taproot descriptors. Bech32 is kept as the default even for Taproot enabled wallets until it's more widely supported. (an earlier attempt of this PR added a second checkbox) <img width="469" alt="Schermafbeelding 2021-12-21 om 11 44 05" src="https://user-images.githubusercontent.com/10217/146872660-339fae1f-c0b8-4673-b8be-33c25f3933fd.png"> **Suggested testing** * notice that the Bech32m entry only appears for wallet with a taproot descriptor * verify that it generates a bc1p instead of bc1q address 1. Legacy wallet 2. Default descriptor wallet (current does not have taproot descriptor) 3. Wallet with taproot descriptor: * just create a new descriptor wallet Replaces bitcoin/bitcoin#22260 ACKs for top commit: Rspigler: tACK c9a77e2. I like the changes made now, thanks! kristapsk: re-ACK c9a77e2 Tree-SHA512: bae66ac90ed55372e6c94878db0e37d32b7b5c24ed00c0f2ebb10fd127dddce3a061162df915d67e92d7b35b3da093137db17b73931a0ae1a470fff20be1f30b
2 parents 887796a + c9a77e2 commit 63b5dfa

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

doc/release-notes-gui-459.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
GUI changes
2+
-----------
3+
4+
- The Bech32 checkbox has been replaced with a dropdown for all address types, including the new Bech32m (BIP-350) standard for Taproot enabled wallets.

src/interfaces/wallet.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,9 @@ class Wallet
256256
// Return whether private keys enabled.
257257
virtual bool privateKeysDisabled() = 0;
258258

259+
// Return whether the wallet contains a Taproot scriptPubKeyMan
260+
virtual bool taprootEnabled() = 0;
261+
259262
// Return whether wallet uses an external signer.
260263
virtual bool hasExternalSigner() = 0;
261264

src/qt/forms/receivecoinsdialog.ui

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@
195195
</widget>
196196
</item>
197197
<item>
198-
<widget class="QCheckBox" name="useBech32">
198+
<widget class="QComboBox" name="addressType">
199199
<property name="sizePolicy">
200200
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
201201
<horstretch>0</horstretch>
@@ -211,12 +211,6 @@
211211
<property name="focusPolicy">
212212
<enum>Qt::StrongFocus</enum>
213213
</property>
214-
<property name="toolTip">
215-
<string>Native segwit addresses (aka Bech32 or BIP-173) reduce your transaction fees later on and offer better protection against typos, but old wallets don't support them. When unchecked, an address compatible with older wallets will be created instead.</string>
216-
</property>
217-
<property name="text">
218-
<string>Generate native segwit (Bech32) address</string>
219-
</property>
220214
</widget>
221215
</item>
222216
<item>
@@ -366,7 +360,7 @@
366360
<tabstops>
367361
<tabstop>reqLabel</tabstop>
368362
<tabstop>reqAmount</tabstop>
369-
<tabstop>useBech32</tabstop>
363+
<tabstop>addressType</tabstop>
370364
<tabstop>reqMessage</tabstop>
371365
<tabstop>receiveButton</tabstop>
372366
<tabstop>clearButton</tabstop>

src/qt/receivecoinsdialog.cpp

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,18 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
8787
&QItemSelectionModel::selectionChanged, this,
8888
&ReceiveCoinsDialog::recentRequestsView_selectionChanged);
8989

90-
if (model->wallet().getDefaultAddressType() == OutputType::BECH32) {
91-
ui->useBech32->setCheckState(Qt::Checked);
92-
} else {
93-
ui->useBech32->setCheckState(Qt::Unchecked);
90+
// Populate address type dropdown and select default
91+
auto add_address_type = [&](OutputType type, const QString& text, const QString& tooltip) {
92+
const auto index = ui->addressType->count();
93+
ui->addressType->addItem(text, (int) type);
94+
ui->addressType->setItemData(index, tooltip, Qt::ToolTipRole);
95+
if (model->wallet().getDefaultAddressType() == type) ui->addressType->setCurrentIndex(index);
96+
};
97+
add_address_type(OutputType::LEGACY, "Base58 (Legacy)", "Not recommended due to higher fees and less protection against typos.");
98+
add_address_type(OutputType::P2SH_SEGWIT, "Base58 (P2SH-SegWit)", "Generates an address compatible with older wallets.");
99+
add_address_type(OutputType::BECH32, "Bech32 (SegWit)", "Generates a native segwit address (BIP-173). Some old wallets don't support it.");
100+
if (model->wallet().taprootEnabled()) {
101+
add_address_type(OutputType::BECH32M, "Bech32m (Taproot)", "Bech32m (BIP-350) is an upgrade to Bech32, wallet support is still limited.");
94102
}
95103

96104
// Set the button to be enabled or disabled based on whether the wallet can give out new addresses.
@@ -144,15 +152,7 @@ void ReceiveCoinsDialog::on_receiveButton_clicked()
144152
QString address;
145153
QString label = ui->reqLabel->text();
146154
/* Generate new receiving address */
147-
OutputType address_type;
148-
if (ui->useBech32->isChecked()) {
149-
address_type = OutputType::BECH32;
150-
} else {
151-
address_type = model->wallet().getDefaultAddressType();
152-
if (address_type == OutputType::BECH32) {
153-
address_type = OutputType::P2SH_SEGWIT;
154-
}
155-
}
155+
const OutputType address_type = (OutputType)ui->addressType->currentData().toInt();
156156
address = model->getAddressTableModel()->addRow(AddressTableModel::Receive, label, "", address_type);
157157

158158
switch(model->getAddressTableModel()->getEditStatus())

src/wallet/interfaces.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,11 @@ class WalletImpl : public Wallet
461461
bool canGetAddresses() override { return m_wallet->CanGetAddresses(); }
462462
bool hasExternalSigner() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_EXTERNAL_SIGNER); }
463463
bool privateKeysDisabled() override { return m_wallet->IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS); }
464+
bool taprootEnabled() override {
465+
if (m_wallet->IsLegacy()) return false;
466+
auto spk_man = m_wallet->GetScriptPubKeyMan(OutputType::BECH32M, /*internal=*/false);
467+
return spk_man != nullptr;
468+
}
464469
OutputType getDefaultAddressType() override { return m_wallet->m_default_address_type; }
465470
CAmount getDefaultMaxTxFee() override { return m_wallet->m_default_max_tx_fee; }
466471
void remove() override

0 commit comments

Comments
 (0)