Skip to content

Commit

Permalink
[wallet] Change default address type to bech32 (bitcoin#16884)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkLTZ committed Nov 17, 2019
1 parent 0815981 commit bbae9da
Show file tree
Hide file tree
Showing 11 changed files with 16 additions and 21 deletions.
2 changes: 2 additions & 0 deletions doc/release-notes-16884.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The wallet now by default uses bech32 addresses when using RPC, and creates native segwit
change outputs.
1 change: 0 additions & 1 deletion src/interfaces/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,6 @@ class NodeImpl : public Node
return GuessVerificationProgress(Params().TxData(), tip);
}
bool isInitialBlockDownload() override { return ::ChainstateActive().IsInitialBlockDownload(); }
bool isAddressTypeSet() override { return !::gArgs.GetArg("-addresstype", "").empty(); }
bool getReindex() override { return ::fReindex; }
bool getImporting() override { return ::fImporting; }
void setNetworkActive(bool active) override
Expand Down
3 changes: 0 additions & 3 deletions src/interfaces/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,6 @@ class Node
//! Is initial block download.
virtual bool isInitialBlockDownload() = 0;

//! Is -addresstype set.
virtual bool isAddressTypeSet() = 0;

//! Get reindex.
virtual bool getReindex() = 0;

Expand Down
13 changes: 3 additions & 10 deletions src/qt/receivecoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include <qt/receivecoinsdialog.h>
#include <qt/forms/ui_receivecoinsdialog.h>

#include <interfaces/node.h>
#include <qt/addresstablemodel.h>
#include <qt/optionsmodel.h>
#include <qt/platformstyle.h>
Expand Down Expand Up @@ -93,16 +92,10 @@ void ReceiveCoinsDialog::setModel(WalletModel *_model)
// Last 2 columns are set by the columnResizingFixer, when the table geometry is ready.
columnResizingFixer = new GUIUtil::TableViewLastColumnResizingFixer(tableView, AMOUNT_MINIMUM_COLUMN_WIDTH, DATE_COLUMN_WIDTH, this);

if (model->node().isAddressTypeSet()) {
// user explicitly set the type, use it
if (model->wallet().getDefaultAddressType() == OutputType::BECH32) {
ui->useBech32->setCheckState(Qt::Checked);
} else {
ui->useBech32->setCheckState(Qt::Unchecked);
}
} else {
// Always fall back to bech32 in the gui
if (model->wallet().getDefaultAddressType() == OutputType::BECH32) {
ui->useBech32->setCheckState(Qt::Checked);
} else {
ui->useBech32->setCheckState(Qt::Unchecked);
}

// Set the button to be enabled or disabled based on whether the wallet can give out new addresses.
Expand Down
2 changes: 1 addition & 1 deletion src/wallet/wallet.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ enum WalletFeature
};

//! Default for -addresstype
constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::P2SH_SEGWIT};
constexpr OutputType DEFAULT_ADDRESS_TYPE{OutputType::BECH32};

//! Default for -changetype
constexpr OutputType DEFAULT_CHANGE_TYPE{OutputType::CHANGE_AUTO};
Expand Down
5 changes: 3 additions & 2 deletions test/functional/feature_bip68_sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@
class BIP68Test(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2
# TODO remove output type argument and fix resulting "tx-size-small" errors
self.extra_args = [
["-acceptnonstdtxn=1"],
["-acceptnonstdtxn=0"],
["-acceptnonstdtxn=1", "-addresstype=p2sh-segwit"],
["-acceptnonstdtxn=0", "-addresstype=p2sh-segwit"],
]

def skip_test_if_missing_module(self):
Expand Down
2 changes: 2 additions & 0 deletions test/functional/feature_rbf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def make_utxo(node, amount, confirmed=True, scriptPubKey=CScript([1])):
class ReplaceByFeeTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 1
# TODO remove output type argument and fix resulting "tx-size-small" errors
self.extra_args = [
[
"-acceptnonstdtxn=1",
Expand All @@ -73,6 +74,7 @@ def set_test_params(self):
"-limitancestorsize=101",
"-limitdescendantcount=200",
"-limitdescendantsize=101",
"-addresstype=p2sh-segwit",
],
]

Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_address_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ def run_test(self):
self.sync_blocks()
assert_equal(self.nodes[4].getbalance(), 1)

self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output")
self.log.info("Nodes with addresstype=legacy never use a P2WPKH change output (unless changetype is set otherwise):")
self.test_change_output_type(0, [to_address_bech32_1], 'legacy')

self.log.info("Nodes with addresstype=p2sh-segwit only use a P2WPKH change output if any destination address is bech32:")
Expand Down
2 changes: 1 addition & 1 deletion test/functional/wallet_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def run_test(self):
assert_raises_rpc_error(-5, "Invalid private key encoding", self.nodes[0].importprivkey, "invalid")

# This will raise an exception for importing an address with the PS2H flag
temp_address = self.nodes[1].getnewaddress()
temp_address = self.nodes[1].getnewaddress("", "p2sh-segwit")
assert_raises_rpc_error(-5, "Cannot use the p2sh flag with an address - use a script instead", self.nodes[0].importaddress, temp_address, "label", False, True)

# This will raise an exception for attempting to dump the private key of an address you do not own
Expand Down
1 change: 1 addition & 0 deletions test/functional/wallet_bumpfee.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ def set_test_params(self):
"-walletrbf={}".format(i),
"-mintxfee=0.00002",
"-deprecatedrpc=totalFee",
"-addresstype=p2sh-segwit", # TODO update constants in test and remove
] for i in range(self.num_nodes)]

def skip_test_if_missing_module(self):
Expand Down
4 changes: 2 additions & 2 deletions test/functional/wallet_import_with_label.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def run_test(self):
"Test importprivkey won't label new dests with the same "
"label as others labeled dests for the same key."
)
self.log.info("Import a watch-only legacy address with a label.")
address4 = self.nodes[0].getnewaddress()
self.log.info("Import a watch-only p2sh-segwit address with a label.")
address4 = self.nodes[0].getnewaddress("", "p2sh-segwit")
label4_addr = "Test Label 4 for importaddress"
self.nodes[1].importaddress(address4, label4_addr)
test_address(self.nodes[1],
Expand Down

0 comments on commit bbae9da

Please sign in to comment.