Skip to content

Commit

Permalink
feat: forbid wallet upgrade from non-HD to HD by upgradewallet
Browse files Browse the repository at this point in the history
  • Loading branch information
knst committed Jan 25, 2024
1 parent 0127da8 commit a78fbc2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4897,7 +4897,14 @@ bool CWallet::UpgradeWallet(int version, bilingual_str& error)
return false;
}

// Discourage users to skip passphrase for HD wallets
if (nMaxVersion >= FEATURE_HD && !IsHDEnabled()) {
error = Untranslated("You should use upgradetohd RPC to upgrade non-HD wallet to HD");
return false;
}

SetMaxVersion(nMaxVersion);

return true;
}

Expand Down
11 changes: 6 additions & 5 deletions test/functional/wallet_upgradewallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
assert_equal,
assert_greater_than_or_equal,
assert_is_hex_string,
assert_raises_rpc_error,
)


Expand Down Expand Up @@ -125,14 +126,14 @@ def run_test(self):
assert_equal('hdseedid' in wallet.getwalletinfo(), False)
# calling upgradewallet with explicit version number
# should return nothing if successful
assert_equal(wallet.upgradewallet(120200), "")
assert_raises_rpc_error(-4, "You should use upgradetohd RPC to upgrade non-HD wallet to HD", wallet.upgradewallet, 120200)

new_version = wallet.getwalletinfo()["walletversion"]
# upgraded wallet should have version 120200
#assert_equal(new_version, 120200)
# after conversion master key hash should not be present yet
assert 'hdchainid' not in wallet.getwalletinfo()

assert_equal(wallet.upgradetohd(), True)
new_version = wallet.getwalletinfo()["walletversion"]
# after conversion master key hash should not be present yet
assert 'hdchainid' in wallet.getwalletinfo()
assert_equal(new_version, 120200)
assert_is_hex_string(wallet.getwalletinfo()['hdchainid'])

Expand Down

0 comments on commit a78fbc2

Please sign in to comment.