MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / MigrateLegacyToDescriptor

Function MigrateLegacyToDescriptor

src/wallet/wallet.cpp:4282–4325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4280}
4281
4282util::Result<MigrationResult> MigrateLegacyToDescriptor(const std::string& wallet_name, const SecureString& passphrase, WalletContext& context, bool load_wallet)
4283{
4284 std::vector<bilingual_str> warnings;
4285 bilingual_str error;
4286
4287 // The only kind of wallets that could be loaded are descriptor ones, which don't need to be migrated.
4288 if (auto wallet = GetWallet(context, wallet_name)) {
4289 assert(wallet->IsWalletFlagSet(WALLET_FLAG_DESCRIPTORS));
4290 return util::Error{_("Error: This wallet is already a descriptor wallet")};
4291 } else {
4292 // Check if the wallet is BDB
4293 const auto& wallet_path = GetWalletPath(wallet_name);
4294 if (!wallet_path) {
4295 return util::Error{util::ErrorString(wallet_path)};
4296 }
4297 if (!fs::exists(*wallet_path)) {
4298 return util::Error{_("Error: Wallet does not exist")};
4299 }
4300 if (!IsBDBFile(BDBDataFile(*wallet_path))) {
4301 return util::Error{_("Error: This wallet is already a descriptor wallet")};
4302 }
4303 }
4304
4305 // Load the wallet but only in the context of this function.
4306 // No signals should be connected nor should anything else be aware of this wallet
4307 WalletContext empty_context;
4308 empty_context.args = context.args;
4309 DatabaseOptions options;
4310 options.require_existing = true;
4311 options.require_format = DatabaseFormat::BERKELEY_RO;
4312 DatabaseStatus status;
4313 std::unique_ptr<WalletDatabase> database = MakeWalletDatabase(wallet_name, options, status, error);
4314 if (!database) {
4315 return util::Error{Untranslated("Wallet file verification failed.") + Untranslated(" ") + error};
4316 }
4317
4318 // Make the local wallet
4319 std::shared_ptr<CWallet> local_wallet = CWallet::LoadExisting(empty_context, wallet_name, std::move(database), error, warnings);
4320 if (!local_wallet) {
4321 return util::Error{Untranslated("Wallet loading failed.") + Untranslated(" ") + error};
4322 }
4323
4324 return MigrateLegacyToDescriptor(std::move(local_wallet), passphrase, context, load_wallet);
4325}
4326
4327util::Result<MigrationResult> MigrateLegacyToDescriptor(std::shared_ptr<CWallet> local_wallet, const SecureString& passphrase, WalletContext& context, bool load_wallet)
4328{

Callers 3

migrateWalletMethod · 0.85
migratewalletFunction · 0.85
WalletMigrationFunction · 0.85

Calls 15

GetWalletFunction · 0.85
_Function · 0.85
GetWalletPathFunction · 0.85
ErrorStringFunction · 0.85
existsFunction · 0.85
IsBDBFileFunction · 0.85
BDBDataFileFunction · 0.85
MakeWalletDatabaseFunction · 0.85
UntranslatedFunction · 0.85
MigrationPrefixNameFunction · 0.85
GetWalletDirFunction · 0.85
PathFromStringFunction · 0.85

Tested by

no test coverage detected