Skip to content

Commit 4f7e37e

Browse files
committed
Merge #11307: wallet: Display non-HD error on first run
fadf31e wallet: Display non-HD error on first run (MarcoFalke) Pull request description: On current master a fresh wallet created with `-usehd=0` is silently created as HD wallet. An error should be displayed on the first run. Also, this restores a test that was removed in c22a53c Fixes: #11313 Tree-SHA512: 226a4129984324f88a431c7e2726383f6841711f0227d8e9f5b4f89d4bb9f2b8e922e6cf0a6f91d6efa747d139543a236b9f29326fc5d1e5d6f1dea2465d9b85
2 parents 1ab1b68 + fadf31e commit 4f7e37e

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

src/wallet/wallet.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3827,6 +3827,10 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
38273827
if (fFirstRun)
38283828
{
38293829
// ensure this wallet.dat can only be opened by clients supporting HD with chain split and expects no default key
3830+
if (!gArgs.GetBoolArg("-usehd", true)) {
3831+
InitError(strprintf(_("Error creating %s: You can't create non-HD wallets with this version."), walletFile));
3832+
return nullptr;
3833+
}
38303834
walletInstance->SetMinVersion(FEATURE_NO_DEFAULT_KEY);
38313835

38323836
// generate a new master key
@@ -3843,9 +3847,9 @@ CWallet* CWallet::CreateWalletFromFile(const std::string walletFile)
38433847
walletInstance->SetBestChain(chainActive.GetLocator());
38443848
}
38453849
else if (gArgs.IsArgSet("-usehd")) {
3846-
bool useHD = gArgs.GetBoolArg("-usehd", DEFAULT_USE_HD_WALLET);
3850+
bool useHD = gArgs.GetBoolArg("-usehd", true);
38473851
if (walletInstance->IsHDEnabled() && !useHD) {
3848-
InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet or create new non-HD wallets."), walletFile));
3852+
InitError(strprintf(_("Error loading %s: You can't disable HD on an already existing HD wallet"), walletFile));
38493853
return nullptr;
38503854
}
38513855
if (!walletInstance->IsHDEnabled() && useHD) {

src/wallet/wallet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ static const unsigned int DEFAULT_TX_CONFIRM_TARGET = 6;
6565
static const bool DEFAULT_WALLET_RBF = false;
6666
static const bool DEFAULT_WALLETBROADCAST = true;
6767
static const bool DEFAULT_DISABLE_WALLET = false;
68-
//! if set, all keys will be derived by using BIP32
69-
static const bool DEFAULT_USE_HD_WALLET = true;
7068

7169
extern const char * DEFAULT_WALLET_DAT;
7270

test/functional/wallet-hd.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@ def set_test_params(self):
2020
def run_test (self):
2121
tmpdir = self.options.tmpdir
2222

23+
# Make sure can't switch off usehd after wallet creation
24+
self.stop_node(1)
25+
self.assert_start_raises_init_error(1, ['-usehd=0'], 'already existing HD wallet')
26+
self.start_node(1)
27+
connect_nodes_bi(self.nodes, 0, 1)
28+
2329
# Make sure we use hd, keep masterkeyid
2430
masterkeyid = self.nodes[1].getwalletinfo()['hdmasterkeyid']
2531
assert_equal(len(masterkeyid), 40)

0 commit comments

Comments
 (0)