Skip to content

Commit 39ba99e

Browse files
committed
wallet: Set global hd key for migrated wallets
1 parent f3476d5 commit 39ba99e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/wallet/wallet.cpp

+8-2
Original file line numberDiff line numberDiff line change
@@ -4026,11 +4026,17 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
40264026
m_internal_spk_managers.clear();
40274027

40284028
// Setup new descriptors
4029-
SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
4029+
SetWalletFlag(WALLET_FLAG_DESCRIPTORS | WALLET_FLAG_GLOBAL_HD_KEY);
40304030
if (!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
40314031
// Use the existing master key if we have it
40324032
if (data.master_key.key.IsValid()) {
40334033
SetupDescriptorScriptPubKeyMans(data.master_key);
4034+
4035+
// Store the master key as our active hd key
4036+
if (!AddHDKey(data.master_key)) {
4037+
throw std::runtime_error(std::string(__func__) + ": Unable to add original seed's HD key");
4038+
}
4039+
SetActiveHDKey(data.master_key.Neuter());
40344040
} else {
40354041
// Setup with a new seed if we don't.
40364042
SetupDescriptorScriptPubKeyMans();
@@ -4193,7 +4199,7 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
41934199
options.require_create = true;
41944200

41954201
// Make the wallets
4196-
options.create_flags = WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_DESCRIPTORS;
4202+
options.create_flags = WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_DESCRIPTORS | WALLET_FLAG_GLOBAL_HD_KEY;
41974203
if (wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
41984204
options.create_flags |= WALLET_FLAG_AVOID_REUSE;
41994205
}

test/functional/wallet_migration.py

+4
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ def test_basic(self):
111111
# So, should have a total of 11 descriptors on it.
112112
assert_equal(len(basic0.listdescriptors()["descriptors"]), 11)
113113

114+
# A global hd key should be added which matches the ones in the descriptors
115+
xprv = basic0.getxpub(True)["xprv"]
116+
assert all([xprv in desc["desc"] for desc in filter(lambda x: "range" in x, basic0.listdescriptors(True)["descriptors"])])
117+
114118
# Compare addresses info
115119
addr_info = basic0.getaddressinfo(addr)
116120
change_addr_info = basic0.getaddressinfo(change)

0 commit comments

Comments
 (0)