Skip to content

Commit

Permalink
wallet: Set global hd key for migrated wallets
Browse files Browse the repository at this point in the history
  • Loading branch information
achow101 committed Sep 7, 2023
1 parent f3476d5 commit 39ba99e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4026,11 +4026,17 @@ bool CWallet::ApplyMigrationData(MigrationData& data, bilingual_str& error)
m_internal_spk_managers.clear();

// Setup new descriptors
SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
SetWalletFlag(WALLET_FLAG_DESCRIPTORS | WALLET_FLAG_GLOBAL_HD_KEY);
if (!IsWalletFlagSet(WALLET_FLAG_DISABLE_PRIVATE_KEYS)) {
// Use the existing master key if we have it
if (data.master_key.key.IsValid()) {
SetupDescriptorScriptPubKeyMans(data.master_key);

// Store the master key as our active hd key
if (!AddHDKey(data.master_key)) {
throw std::runtime_error(std::string(__func__) + ": Unable to add original seed's HD key");
}
SetActiveHDKey(data.master_key.Neuter());
} else {
// Setup with a new seed if we don't.
SetupDescriptorScriptPubKeyMans();
Expand Down Expand Up @@ -4193,7 +4199,7 @@ bool DoMigration(CWallet& wallet, WalletContext& context, bilingual_str& error,
options.require_create = true;

// Make the wallets
options.create_flags = WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_DESCRIPTORS;
options.create_flags = WALLET_FLAG_DISABLE_PRIVATE_KEYS | WALLET_FLAG_BLANK_WALLET | WALLET_FLAG_DESCRIPTORS | WALLET_FLAG_GLOBAL_HD_KEY;
if (wallet.IsWalletFlagSet(WALLET_FLAG_AVOID_REUSE)) {
options.create_flags |= WALLET_FLAG_AVOID_REUSE;
}
Expand Down
4 changes: 4 additions & 0 deletions test/functional/wallet_migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ def test_basic(self):
# So, should have a total of 11 descriptors on it.
assert_equal(len(basic0.listdescriptors()["descriptors"]), 11)

# A global hd key should be added which matches the ones in the descriptors
xprv = basic0.getxpub(True)["xprv"]
assert all([xprv in desc["desc"] for desc in filter(lambda x: "range" in x, basic0.listdescriptors(True)["descriptors"])])

# Compare addresses info
addr_info = basic0.getaddressinfo(addr)
change_addr_info = basic0.getaddressinfo(change)
Expand Down

0 comments on commit 39ba99e

Please sign in to comment.