This PR is mostly a refactor which splits out logic used for creating wallets and for loading wallets, both of which are presently contained in CWallet::Create()
into CWallet::CreateNew()
and CWallet::LoadExisting()
The real win of this PR is that CWallet::Create()
uses a very bad heuristic for trying to guess whether or not it is supposed to be creating a new wallet or loading an existing wallet:
This heuristic assumes that wallets with no ScriptPubKeyMans
are being created, which sounds reasonable, but as demonstrated in #32112 and #32111, this can happen when the user tries to load a wallet file that is corrupted, both issues are fixed by this PR and any other misbehavior for wallet files which succeeded the broken heuristic’s sniff test for new wallets.
It was already the case that every caller of CWallet::Create()
knows whether it is creating a wallet or loading one, so we can avoid replacing this bad heuristic with another one, and just shift the burden to the caller.