mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 06:49:38 -04:00
wallet, migration: Fix crash on empty wallet
Same as with a blank wallet, wallets with no legacy records (i.e. empty, non-blank, watch-only wallet) do not require to be migrated.
This commit is contained in:
parent
42c13141b5
commit
0f602c5693
2 changed files with 12 additions and 3 deletions
|
@ -4534,13 +4534,13 @@ util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet>
|
|||
// First change to using SQLite
|
||||
if (!local_wallet->MigrateToSQLite(error)) return util::Error{error};
|
||||
|
||||
// Do the migration of keys and scripts for non-blank wallets, and cleanup if it fails
|
||||
success = local_wallet->IsWalletFlagSet(WALLET_FLAG_BLANK_WALLET);
|
||||
if (!success) {
|
||||
// Do the migration of keys and scripts for non-empty wallets, and cleanup if it fails
|
||||
if (HasLegacyRecords(*local_wallet)) {
|
||||
success = DoMigration(*local_wallet, context, error, res);
|
||||
} else {
|
||||
// Make sure that descriptors flag is actually set
|
||||
local_wallet->SetWalletFlag(WALLET_FLAG_DESCRIPTORS);
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -445,6 +445,15 @@ class WalletMigrationTest(BitcoinTestFramework):
|
|||
# After migrating, the "keypool" is empty
|
||||
assert_raises_rpc_error(-4, "Error: This wallet has no available keys", watchonly1.getnewaddress)
|
||||
|
||||
self.log.info("Test migration of a watch-only empty wallet")
|
||||
for idx, is_blank in enumerate([True, False], start=1):
|
||||
wallet_name = f"watchonly_empty{idx}"
|
||||
self.create_legacy_wallet(wallet_name, disable_private_keys=True, blank=is_blank)
|
||||
_, watchonly_empty = self.migrate_and_get_rpc(wallet_name)
|
||||
info = watchonly_empty.getwalletinfo()
|
||||
assert_equal(info["private_keys_enabled"], False)
|
||||
assert_equal(info["blank"], is_blank)
|
||||
|
||||
def test_pk_coinbases(self):
|
||||
self.log.info("Test migration of a wallet using old pk() coinbases")
|
||||
wallet = self.create_legacy_wallet("pkcb")
|
||||
|
|
Loading…
Add table
Reference in a new issue