mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-02 17:56:16 +00:00
wallet: refactor: PopulateWalletFromDB use switch statement.
Co-authored-by: @w0xlt <w0xlt@users.noreply.github.com>
This commit is contained in:
parent
a48e23f566
commit
411caf7281
@ -2312,36 +2312,47 @@ DBErrors CWallet::PopulateWalletFromDB(bilingual_str& error, std::vector<bilingu
|
||||
assert(m_internal_spk_managers.empty());
|
||||
}
|
||||
|
||||
if (nLoadWalletRet != DBErrors::LOAD_OK) {
|
||||
const auto wallet_file = m_database->Filename();
|
||||
if (nLoadWalletRet == DBErrors::CORRUPT) {
|
||||
error = strprintf(_("Error loading %s: Wallet corrupted"), wallet_file);
|
||||
} else if (nLoadWalletRet == DBErrors::NONCRITICAL_ERROR) {
|
||||
warnings.push_back(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
|
||||
" or address metadata may be missing or incorrect."),
|
||||
wallet_file));
|
||||
} else if (nLoadWalletRet == DBErrors::TOO_NEW) {
|
||||
error = strprintf(_("Error loading %s: Wallet requires newer version of %s"), wallet_file, CLIENT_NAME);
|
||||
} else if (nLoadWalletRet == DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED) {
|
||||
error = strprintf(_("Error loading %s: External signer wallet being loaded without external signer support compiled"), wallet_file);
|
||||
} else if (nLoadWalletRet == DBErrors::NEED_REWRITE) {
|
||||
error = strprintf(_("Wallet needed to be rewritten: restart %s to complete"), CLIENT_NAME);
|
||||
} else if (nLoadWalletRet == DBErrors::NEED_RESCAN) {
|
||||
warnings.push_back(strprintf(_("Error reading %s! Transaction data may be missing or incorrect."
|
||||
" Rescanning wallet."), wallet_file));
|
||||
} else if (nLoadWalletRet == DBErrors::UNKNOWN_DESCRIPTOR) {
|
||||
error = strprintf(_("Unrecognized descriptor found. Loading wallet %s\n\n"
|
||||
"The wallet might have been created on a newer version.\n"
|
||||
"Please try running the latest software version.\n"), wallet_file);
|
||||
} else if (nLoadWalletRet == DBErrors::UNEXPECTED_LEGACY_ENTRY) {
|
||||
error = strprintf(_("Unexpected legacy entry in descriptor wallet found. Loading wallet %s\n\n"
|
||||
"The wallet might have been tampered with or created with malicious intent.\n"), wallet_file);
|
||||
} else if (nLoadWalletRet == DBErrors::LEGACY_WALLET) {
|
||||
error = strprintf(_("Error loading %s: Wallet is a legacy wallet. Please migrate to a descriptor wallet using the migration tool (migratewallet RPC)."), wallet_file);
|
||||
} else {
|
||||
error = strprintf(_("Error loading %s"), wallet_file);
|
||||
}
|
||||
}
|
||||
const auto wallet_file = m_database->Filename();
|
||||
switch (nLoadWalletRet) {
|
||||
case DBErrors::LOAD_OK:
|
||||
break;
|
||||
case DBErrors::NONCRITICAL_ERROR:
|
||||
warnings.push_back(strprintf(_("Error reading %s! All keys read correctly, but transaction data"
|
||||
" or address metadata may be missing or incorrect."),
|
||||
wallet_file));
|
||||
break;
|
||||
case DBErrors::NEED_RESCAN:
|
||||
warnings.push_back(strprintf(_("Error reading %s! Transaction data may be missing or incorrect."
|
||||
" Rescanning wallet."), wallet_file));
|
||||
break;
|
||||
case DBErrors::CORRUPT:
|
||||
error = strprintf(_("Error loading %s: Wallet corrupted"), wallet_file);
|
||||
break;
|
||||
case DBErrors::TOO_NEW:
|
||||
error = strprintf(_("Error loading %s: Wallet requires newer version of %s"), wallet_file, CLIENT_NAME);
|
||||
break;
|
||||
case DBErrors::EXTERNAL_SIGNER_SUPPORT_REQUIRED:
|
||||
error = strprintf(_("Error loading %s: External signer wallet being loaded without external signer support compiled"), wallet_file);
|
||||
break;
|
||||
case DBErrors::NEED_REWRITE:
|
||||
error = strprintf(_("Wallet needed to be rewritten: restart %s to complete"), CLIENT_NAME);
|
||||
break;
|
||||
case DBErrors::UNKNOWN_DESCRIPTOR:
|
||||
error = strprintf(_("Unrecognized descriptor found. Loading wallet %s\n\n"
|
||||
"The wallet might have been created on a newer version.\n"
|
||||
"Please try running the latest software version.\n"), wallet_file);
|
||||
break;
|
||||
case DBErrors::UNEXPECTED_LEGACY_ENTRY:
|
||||
error = strprintf(_("Unexpected legacy entry in descriptor wallet found. Loading wallet %s\n\n"
|
||||
"The wallet might have been tampered with or created with malicious intent.\n"), wallet_file);
|
||||
break;
|
||||
case DBErrors::LEGACY_WALLET:
|
||||
error = strprintf(_("Error loading %s: Wallet is a legacy wallet. Please migrate to a descriptor wallet using the migration tool (migratewallet RPC)."), wallet_file);
|
||||
break;
|
||||
case DBErrors::LOAD_FAIL:
|
||||
error = strprintf(_("Error loading %s"), wallet_file);
|
||||
break;
|
||||
} // no default case, so the compiler can warn about missing cases
|
||||
return nLoadWalletRet;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user