From 6bbb2241a3cf85127a9680019395d0b838a59699 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 22 Feb 2024 14:43:16 -0500 Subject: [PATCH] scripted-diff: replace wallet DatabaseStatus with DatabaseError -BEGIN VERIFY SCRIPT- git grep -l DatabaseStatus src | xargs sed -i s/DatabaseStatus/DatabaseError/g sed -i '/^ SUCCESS,$/d' src/wallet/db.h -END VERIFY SCRIPT- --- src/wallet/bdb.cpp | 8 +++---- src/wallet/bdb.h | 2 +- src/wallet/db.h | 5 ++-- src/wallet/load.cpp | 4 ++-- src/wallet/migrate.cpp | 4 ++-- src/wallet/migrate.h | 2 +- src/wallet/rpc/util.cpp | 12 +++++----- src/wallet/rpc/util.h | 4 ++-- src/wallet/rpc/wallet.cpp | 2 +- src/wallet/sqlite.cpp | 8 +++---- src/wallet/sqlite.h | 2 +- src/wallet/wallet.cpp | 48 +++++++++++++++++++-------------------- src/wallet/wallet.h | 8 +++---- src/wallet/walletdb.cpp | 18 +++++++-------- 14 files changed, 63 insertions(+), 64 deletions(-) diff --git a/src/wallet/bdb.cpp b/src/wallet/bdb.cpp index 64b7f71bf18d1..a54b39c1063ea 100644 --- a/src/wallet/bdb.cpp +++ b/src/wallet/bdb.cpp @@ -943,9 +943,9 @@ std::unique_ptr BerkeleyDatabase::MakeBatch(bool flush_on_close) return std::make_unique(*this, false, flush_on_close); } -util::ResultPtr, DatabaseStatus> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options) { - util::ResultPtr, DatabaseStatus> result; + util::ResultPtr, DatabaseError> result; fs::path data_file = BDBDataFile(path); std::unique_ptr db; @@ -955,14 +955,14 @@ util::ResultPtr, DatabaseStatus> MakeBerkeleyD std::shared_ptr env = GetBerkeleyEnv(data_file.parent_path(), options.use_shared_memory); if (env->m_databases.count(data_filename)) { result.Update({util::Error{Untranslated(strprintf("Refusing to load database. Data file '%s' is already loaded.", fs::PathToString(env->Directory() / data_filename)))}, - DatabaseStatus::FAILED_ALREADY_LOADED}); + DatabaseError::FAILED_ALREADY_LOADED}); return result; } db = std::make_unique(std::move(env), std::move(data_filename), options); } if (options.verify && !(db->Verify() >> result)) { - result.Update({util::Error{}, DatabaseStatus::FAILED_VERIFY}); + result.Update({util::Error{}, DatabaseError::FAILED_VERIFY}); return result; } diff --git a/src/wallet/bdb.h b/src/wallet/bdb.h index 6b74c53440ece..97cf8fa4e45f2 100644 --- a/src/wallet/bdb.h +++ b/src/wallet/bdb.h @@ -220,7 +220,7 @@ std::string BerkeleyDatabaseVersion(); bool BerkeleyDatabaseSanityCheck(); //! Return object giving access to Berkeley database at specified path. -util::ResultPtr, DatabaseStatus> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options); +util::ResultPtr, DatabaseError> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options); } // namespace wallet #endif // BITCOIN_WALLET_BDB_H diff --git a/src/wallet/db.h b/src/wallet/db.h index b1f5d2b446cf2..2149e018eb37e 100644 --- a/src/wallet/db.h +++ b/src/wallet/db.h @@ -203,8 +203,7 @@ struct DatabaseOptions { int64_t max_log_mb = 100; //!< Max log size to allow before consolidating. }; -enum class DatabaseStatus { - SUCCESS, +enum class DatabaseError { FAILED_BAD_PATH, FAILED_BAD_FORMAT, FAILED_ALREADY_LOADED, @@ -221,7 +220,7 @@ enum class DatabaseStatus { std::vector> ListDatabases(const fs::path& path); void ReadDatabaseArgs(const ArgsManager& args, DatabaseOptions& options); -util::ResultPtr, DatabaseStatus> MakeDatabase(const fs::path& path, const DatabaseOptions& options); +util::ResultPtr, DatabaseError> MakeDatabase(const fs::path& path, const DatabaseOptions& options); fs::path BDBDataFile(const fs::path& path); fs::path SQLiteDataFile(const fs::path& path); diff --git a/src/wallet/load.cpp b/src/wallet/load.cpp index dd9380bf4427a..6758acb797c14 100644 --- a/src/wallet/load.cpp +++ b/src/wallet/load.cpp @@ -94,7 +94,7 @@ bool VerifyWallets(WalletContext& context) options.verify = true; auto result{MakeWalletDatabase(wallet_file, options)}; if (!result) { - if (result.GetFailure() == DatabaseStatus::FAILED_NOT_FOUND) { + if (result.GetFailure() == DatabaseError::FAILED_NOT_FOUND) { chain.initWarning(Untranslated(strprintf("Skipping -wallet path that doesn't exist. %s", util::ErrorString(result).original))); } else { chain.initError(util::ErrorString(result)); @@ -127,7 +127,7 @@ bool LoadWallets(WalletContext& context) options.verify = false; // No need to verify, assuming verified earlier in VerifyWallets() util::Result result; auto database{MakeWalletDatabase(name, options) >> result}; - if (!database && database.GetFailure() == DatabaseStatus::FAILED_NOT_FOUND) { + if (!database && database.GetFailure() == DatabaseError::FAILED_NOT_FOUND) { continue; } chain.initMessage(_("Loading wallet…").translated); diff --git a/src/wallet/migrate.cpp b/src/wallet/migrate.cpp index 3d4729a04ff41..072fcf4a73e92 100644 --- a/src/wallet/migrate.cpp +++ b/src/wallet/migrate.cpp @@ -768,13 +768,13 @@ std::unique_ptr BerkeleyROBatch::GetNewPrefixCursor(Span(m_database, prefix); } -util::ResultPtr, DatabaseStatus> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options) { fs::path data_file = BDBDataFile(path); try { return std::make_unique(data_file); } catch (const std::runtime_error& e) { - return {util::Error{Untranslated(e.what())}, DatabaseStatus::FAILED_LOAD}; + return {util::Error{Untranslated(e.what())}, DatabaseError::FAILED_LOAD}; } } } // namespace wallet diff --git a/src/wallet/migrate.h b/src/wallet/migrate.h index dc4fde95d02e4..ca00e317067bd 100644 --- a/src/wallet/migrate.h +++ b/src/wallet/migrate.h @@ -120,7 +120,7 @@ class BerkeleyROBatch : public DatabaseBatch }; //! Return object giving access to Berkeley Read Only database at specified path. -util::ResultPtr, DatabaseStatus> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options); +util::ResultPtr, DatabaseError> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options); } // namespace wallet #endif // BITCOIN_WALLET_MIGRATE_H diff --git a/src/wallet/rpc/util.cpp b/src/wallet/rpc/util.cpp index 57a2c3950af7e..f191644fee0ba 100644 --- a/src/wallet/rpc/util.cpp +++ b/src/wallet/rpc/util.cpp @@ -152,24 +152,24 @@ void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, entry.pushKV("parent_descs", std::move(parent_descs)); } -void HandleWalletError(const util::ResultPtr, DatabaseStatus>& wallet) +void HandleWalletError(const util::ResultPtr, DatabaseError>& wallet) { if (!wallet) { // Map bad format to not found, since bad format is returned when the // wallet directory exists, but doesn't contain a data file. RPCErrorCode code = RPC_WALLET_ERROR; switch (wallet.GetFailure()) { - case DatabaseStatus::FAILED_NOT_FOUND: - case DatabaseStatus::FAILED_BAD_FORMAT: + case DatabaseError::FAILED_NOT_FOUND: + case DatabaseError::FAILED_BAD_FORMAT: code = RPC_WALLET_NOT_FOUND; break; - case DatabaseStatus::FAILED_ALREADY_LOADED: + case DatabaseError::FAILED_ALREADY_LOADED: code = RPC_WALLET_ALREADY_LOADED; break; - case DatabaseStatus::FAILED_ALREADY_EXISTS: + case DatabaseError::FAILED_ALREADY_EXISTS: code = RPC_WALLET_ALREADY_EXISTS; break; - case DatabaseStatus::FAILED_INVALID_BACKUP_FILE: + case DatabaseError::FAILED_INVALID_BACKUP_FILE: code = RPC_INVALID_PARAMETER; break; default: // RPC_WALLET_ERROR is returned for all other cases. diff --git a/src/wallet/rpc/util.h b/src/wallet/rpc/util.h index b6bfcdf0c864c..111978c6b819d 100644 --- a/src/wallet/rpc/util.h +++ b/src/wallet/rpc/util.h @@ -21,7 +21,7 @@ struct bilingual_str; namespace wallet { class LegacyScriptPubKeyMan; -enum class DatabaseStatus; +enum class DatabaseError; struct WalletContext; extern const std::string HELP_REQUIRING_PASSPHRASE; @@ -51,7 +51,7 @@ std::string LabelFromValue(const UniValue& value); //! Fetch parent descriptors of this scriptPubKey. void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey, UniValue& entry); -void HandleWalletError(const util::ResultPtr, DatabaseStatus>& wallet); +void HandleWalletError(const util::ResultPtr, DatabaseError>& wallet); int64_t ParseISO8601DateTime(const std::string& str); void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet); } // namespace wallet diff --git a/src/wallet/rpc/wallet.cpp b/src/wallet/rpc/wallet.cpp index 41de353219e03..91c8863489c3a 100644 --- a/src/wallet/rpc/wallet.cpp +++ b/src/wallet/rpc/wallet.cpp @@ -426,7 +426,7 @@ static RPCHelpMan createwallet() std::optional load_on_start = request.params[6].isNull() ? std::nullopt : std::optional(request.params[6].get_bool()); auto wallet{CreateWallet(context, request.params[0].get_str(), load_on_start, options) >> result}; if (!wallet) { - RPCErrorCode code = wallet.GetFailure() == DatabaseStatus::FAILED_ENCRYPT ? RPC_WALLET_ENCRYPTION_FAILED : RPC_WALLET_ERROR; + RPCErrorCode code = wallet.GetFailure() == DatabaseError::FAILED_ENCRYPT ? RPC_WALLET_ENCRYPTION_FAILED : RPC_WALLET_ERROR; throw JSONRPCError(code, util::ErrorString(result).original); } diff --git a/src/wallet/sqlite.cpp b/src/wallet/sqlite.cpp index d4977d9bca0a8..14168e7588e3e 100644 --- a/src/wallet/sqlite.cpp +++ b/src/wallet/sqlite.cpp @@ -696,19 +696,19 @@ bool SQLiteBatch::TxnAbort() return res == SQLITE_OK; } -util::ResultPtr, DatabaseStatus> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options) { - util::ResultPtr, DatabaseStatus> result; + util::ResultPtr, DatabaseError> result; try { fs::path data_file = SQLiteDataFile(path); auto db = std::make_unique(data_file.parent_path(), data_file, options); if (options.verify && !(db->Verify() >> result)) { - result.Update({util::Error{}, DatabaseStatus::FAILED_VERIFY}); + result.Update({util::Error{}, DatabaseError::FAILED_VERIFY}); } else { result.Update(std::move(db)); } } catch (const std::runtime_error& e) { - result.Update({util::Error{Untranslated(e.what())}, DatabaseStatus::FAILED_LOAD}); + result.Update({util::Error{Untranslated(e.what())}, DatabaseError::FAILED_LOAD}); } return result; } diff --git a/src/wallet/sqlite.h b/src/wallet/sqlite.h index 219bd00e6d0e2..df8c77dac8068 100644 --- a/src/wallet/sqlite.h +++ b/src/wallet/sqlite.h @@ -179,7 +179,7 @@ class SQLiteDatabase : public WalletDatabase bool m_use_unsafe_sync; }; -util::ResultPtr, DatabaseStatus> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options); +util::ResultPtr, DatabaseError> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options); std::string SQLiteDatabaseVersion(); } // namespace wallet diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index b75e1a65d7e55..bbf3e5b2ca0d4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -282,9 +282,9 @@ void WaitForDeleteWallet(std::shared_ptr&& wallet) } namespace { -util::ResultPtr, DatabaseStatus> LoadWalletInternal(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> LoadWalletInternal(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options) { - util::ResultPtr, DatabaseStatus> result; + util::ResultPtr, DatabaseError> result; try { auto database{MakeWalletDatabase(name, options) >> result}; if (!database) { @@ -299,7 +299,7 @@ util::ResultPtr, DatabaseStatus> LoadWalletInternal(Wal if (!wallet) { auto& errors{result.EnsureMessages().errors}; errors.insert(errors.begin(), Untranslated("Wallet loading failed.")); - result.Update({util::Error{}, DatabaseStatus::FAILED_LOAD}); + result.Update({util::Error{}, DatabaseError::FAILED_LOAD}); return result; } @@ -317,7 +317,7 @@ util::ResultPtr, DatabaseStatus> LoadWalletInternal(Wal result.Update(std::move(wallet.value())); } catch (const std::runtime_error& e) { - result.Update({util::Error{Untranslated(e.what())}, DatabaseStatus::FAILED_LOAD}); + result.Update({util::Error{Untranslated(e.what())}, DatabaseError::FAILED_LOAD}); } return result; } @@ -381,20 +381,20 @@ class FastWalletRescanFilter }; } // namespace -util::ResultPtr, DatabaseStatus> LoadWallet(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> LoadWallet(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options) { auto result = WITH_LOCK(g_loading_wallet_mutex, return g_loading_wallet_set.insert(name)); if (!result.second) { - return {util::Error{Untranslated("Wallet already loading.")}, DatabaseStatus::FAILED_LOAD}; + return {util::Error{Untranslated("Wallet already loading.")}, DatabaseError::FAILED_LOAD}; } auto wallet{LoadWalletInternal(context, name, load_on_start, options)}; WITH_LOCK(g_loading_wallet_mutex, g_loading_wallet_set.erase(result.first)); return wallet; } -util::ResultPtr, DatabaseStatus> CreateWallet(WalletContext& context, const std::string& name, std::optional load_on_start, DatabaseOptions& options) +util::ResultPtr, DatabaseError> CreateWallet(WalletContext& context, const std::string& name, std::optional load_on_start, DatabaseOptions& options) { - util::Result, DatabaseStatus> result; + util::Result, DatabaseError> result; uint64_t wallet_creation_flags = options.create_flags; const SecureString& passphrase = options.create_passphrase; @@ -415,19 +415,19 @@ util::ResultPtr, DatabaseStatus> CreateWallet(WalletCon // Private keys must be disabled for an external signer wallet if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) && !(wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { - result.Update({util::Error{Untranslated("Private keys must be disabled when using an external signer")}, DatabaseStatus::FAILED_CREATE}); + result.Update({util::Error{Untranslated("Private keys must be disabled when using an external signer")}, DatabaseError::FAILED_CREATE}); return result; } // Descriptor support must be enabled for an external signer wallet if ((wallet_creation_flags & WALLET_FLAG_EXTERNAL_SIGNER) && !(wallet_creation_flags & WALLET_FLAG_DESCRIPTORS)) { - result.Update({util::Error{Untranslated("Descriptor support must be enabled when using an external signer")}, DatabaseStatus::FAILED_CREATE}); + result.Update({util::Error{Untranslated("Descriptor support must be enabled when using an external signer")}, DatabaseError::FAILED_CREATE}); return result; } // Do not allow a passphrase when private keys are disabled if (!passphrase.empty() && (wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { - result.Update({util::Error{Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.")}, DatabaseStatus::FAILED_CREATE}); + result.Update({util::Error{Untranslated("Passphrase provided but private keys are disabled. A passphrase is only used to encrypt private keys, so cannot be used for wallets with private keys disabled.")}, DatabaseError::FAILED_CREATE}); return result; } @@ -436,7 +436,7 @@ util::ResultPtr, DatabaseStatus> CreateWallet(WalletCon if (!database) { auto& errors{result.EnsureMessages().errors}; errors.insert(errors.begin(), Untranslated("Wallet file verification failed.")); - result.Update({util::Error{}, DatabaseStatus::FAILED_VERIFY}); + result.Update({util::Error{}, DatabaseError::FAILED_VERIFY}); return result; } @@ -444,7 +444,7 @@ util::ResultPtr, DatabaseStatus> CreateWallet(WalletCon context.chain->initMessage(_("Loading wallet…").translated); auto create{CWallet::Create(context, name, std::move(database.value()), wallet_creation_flags) >> result}; if (!create) { - result.Update({util::Error{Untranslated("Wallet creation failed.")}, DatabaseStatus::FAILED_CREATE}); + result.Update({util::Error{Untranslated("Wallet creation failed.")}, DatabaseError::FAILED_CREATE}); return result; } std::shared_ptr wallet = create.value(); @@ -452,13 +452,13 @@ util::ResultPtr, DatabaseStatus> CreateWallet(WalletCon // Encrypt the wallet if (!passphrase.empty() && !(wallet_creation_flags & WALLET_FLAG_DISABLE_PRIVATE_KEYS)) { if (!wallet->EncryptWallet(passphrase)) { - result.Update({util::Error{Untranslated("Error: Wallet created but failed to encrypt.")}, DatabaseStatus::FAILED_ENCRYPT}); + result.Update({util::Error{Untranslated("Error: Wallet created but failed to encrypt.")}, DatabaseError::FAILED_ENCRYPT}); return result; } if (!create_blank) { // Unlock the wallet if (!wallet->Unlock(passphrase)) { - result.Update({util::Error{Untranslated("Error: Wallet was encrypted but could not be unlocked")}, DatabaseStatus::FAILED_ENCRYPT}); + result.Update({util::Error{Untranslated("Error: Wallet was encrypted but could not be unlocked")}, DatabaseError::FAILED_ENCRYPT}); return result; } @@ -470,7 +470,7 @@ util::ResultPtr, DatabaseStatus> CreateWallet(WalletCon } else { for (auto spk_man : wallet->GetActiveScriptPubKeyMans()) { if (!spk_man->SetupGeneration()) { - result.Update({util::Error{Untranslated("Unable to generate initial keys")}, DatabaseStatus::FAILED_CREATE}); + result.Update({util::Error{Untranslated("Unable to generate initial keys")}, DatabaseError::FAILED_CREATE}); return result; } } @@ -498,9 +498,9 @@ util::ResultPtr, DatabaseStatus> CreateWallet(WalletCon return result; } -util::ResultPtr, DatabaseStatus> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional load_on_start) +util::ResultPtr, DatabaseError> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional load_on_start) { - util::ResultPtr, DatabaseStatus> result; + util::ResultPtr, DatabaseError> result; DatabaseOptions options; ReadDatabaseArgs(*context.args, options); options.require_existing = true; @@ -510,12 +510,12 @@ util::ResultPtr, DatabaseStatus> RestoreWallet(WalletCo try { if (!fs::exists(backup_file)) { - result.Update({util::Error{Untranslated("Backup file does not exist")}, DatabaseStatus::FAILED_INVALID_BACKUP_FILE}); + result.Update({util::Error{Untranslated("Backup file does not exist")}, DatabaseError::FAILED_INVALID_BACKUP_FILE}); return result; } if (fs::exists(wallet_path) || !TryCreateDirectories(wallet_path)) { - result.Update({util::Error{Untranslated(strprintf("Failed to create database path '%s'. Database already exists.", fs::PathToString(wallet_path)))}, DatabaseStatus::FAILED_ALREADY_EXISTS}); + result.Update({util::Error{Untranslated(strprintf("Failed to create database path '%s'. Database already exists.", fs::PathToString(wallet_path)))}, DatabaseError::FAILED_ALREADY_EXISTS}); return result; } @@ -524,7 +524,7 @@ util::ResultPtr, DatabaseStatus> RestoreWallet(WalletCo result.Update(LoadWallet(context, wallet_name, load_on_start, options)); } catch (const std::exception& e) { assert(!result.value()); - result.Update({util::Error{strprintf(Untranslated("Unexpected exception: %s"), e.what())}, DatabaseStatus::FAILED_LOAD}); + result.Update({util::Error{strprintf(Untranslated("Unexpected exception: %s"), e.what())}, DatabaseError::FAILED_LOAD}); return result; } if (!result) { @@ -2973,12 +2973,12 @@ static util::Result GetWalletPath(const std::string& name) return wallet_path; } -util::ResultPtr, DatabaseStatus> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options) { - util::ResultPtr, DatabaseStatus> result; + util::ResultPtr, DatabaseError> result; auto wallet_path{GetWalletPath(name) >> result}; if (!wallet_path) { - result.Update({util::Error{}, DatabaseStatus::FAILED_BAD_PATH}); + result.Update({util::Error{}, DatabaseError::FAILED_BAD_PATH}); return result; } result.Update(MakeDatabase(*wallet_path, options)); diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h index 6a355e6aacd48..759e45171aa8e 100644 --- a/src/wallet/wallet.h +++ b/src/wallet/wallet.h @@ -92,12 +92,12 @@ util::Result RemoveWallet(WalletContext& context, const std::shared_ptr> GetWallets(WalletContext& context); std::shared_ptr GetDefaultWallet(WalletContext& context, size_t& count); std::shared_ptr GetWallet(WalletContext& context, const std::string& name); -util::ResultPtr, DatabaseStatus> LoadWallet(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options); -util::ResultPtr, DatabaseStatus> CreateWallet(WalletContext& context, const std::string& name, std::optional load_on_start, DatabaseOptions& options); -util::ResultPtr, DatabaseStatus> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional load_on_start); +util::ResultPtr, DatabaseError> LoadWallet(WalletContext& context, const std::string& name, std::optional load_on_start, const DatabaseOptions& options); +util::ResultPtr, DatabaseError> CreateWallet(WalletContext& context, const std::string& name, std::optional load_on_start, DatabaseOptions& options); +util::ResultPtr, DatabaseError> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional load_on_start); std::unique_ptr HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet); void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr& wallet); -util::ResultPtr, DatabaseStatus> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options); +util::ResultPtr, DatabaseError> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options); //! -paytxfee default constexpr CAmount DEFAULT_PAY_TX_FEE = 0; diff --git a/src/wallet/walletdb.cpp b/src/wallet/walletdb.cpp index 2fefc91db1636..fff5f8a710611 100644 --- a/src/wallet/walletdb.cpp +++ b/src/wallet/walletdb.cpp @@ -1377,13 +1377,13 @@ void WalletBatch::RegisterTxnListener(const DbTxnListener& l) m_txn_listeners.emplace_back(l); } -util::ResultPtr, DatabaseStatus> MakeDatabase(const fs::path& path, const DatabaseOptions& options) +util::ResultPtr, DatabaseError> MakeDatabase(const fs::path& path, const DatabaseOptions& options) { bool exists; try { exists = fs::symlink_status(path).type() != fs::file_type::not_found; } catch (const fs::filesystem_error& e) { - return {util::Error{Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), fsbridge::get_filesystem_error_message(e)))}, DatabaseStatus::FAILED_BAD_PATH}; + return {util::Error{Untranslated(strprintf("Failed to access database path '%s': %s", fs::PathToString(path), fsbridge::get_filesystem_error_message(e)))}, DatabaseError::FAILED_BAD_PATH}; } std::optional format; @@ -1393,20 +1393,20 @@ util::ResultPtr, DatabaseStatus> MakeDatabase(co } if (IsSQLiteFile(SQLiteDataFile(path))) { if (format) { - return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Data is in ambiguous format.", fs::PathToString(path)))}, DatabaseStatus::FAILED_BAD_FORMAT}; + return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Data is in ambiguous format.", fs::PathToString(path)))}, DatabaseError::FAILED_BAD_FORMAT}; } format = DatabaseFormat::SQLITE; } } else if (options.require_existing) { - return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Path does not exist.", fs::PathToString(path)))}, DatabaseStatus::FAILED_NOT_FOUND}; + return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Path does not exist.", fs::PathToString(path)))}, DatabaseError::FAILED_NOT_FOUND}; } if (!format && options.require_existing) { - return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Data is not in recognized format.", fs::PathToString(path)))}, DatabaseStatus::FAILED_BAD_FORMAT}; + return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Data is not in recognized format.", fs::PathToString(path)))}, DatabaseError::FAILED_BAD_FORMAT}; } if (format && options.require_create) { - return {util::Error{Untranslated(strprintf("Failed to create database path '%s'. Database already exists.", fs::PathToString(path)))}, DatabaseStatus::FAILED_ALREADY_EXISTS}; + return {util::Error{Untranslated(strprintf("Failed to create database path '%s'. Database already exists.", fs::PathToString(path)))}, DatabaseError::FAILED_ALREADY_EXISTS}; } // If BERKELEY was the format, then change the format from BERKELEY to BERKELEY_RO @@ -1416,7 +1416,7 @@ util::ResultPtr, DatabaseStatus> MakeDatabase(co // A db already exists so format is set, but options also specifies the format, so make sure they agree if (format && options.require_format && format != options.require_format) { - return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Data is not in required format.", fs::PathToString(path)))}, DatabaseStatus::FAILED_BAD_FORMAT}; + return {util::Error{Untranslated(strprintf("Failed to load database path '%s'. Data is not in required format.", fs::PathToString(path)))}, DatabaseError::FAILED_BAD_FORMAT}; } // Format is not set when a db doesn't already exist, so use the format specified by the options if it is set. @@ -1440,7 +1440,7 @@ util::ResultPtr, DatabaseStatus> MakeDatabase(co #endif { return {util::Error{Untranslated(strprintf("Failed to open database path '%s'. Build does not support SQLite database format.", fs::PathToString(path)))}, - DatabaseStatus::FAILED_BAD_FORMAT}; + DatabaseError::FAILED_BAD_FORMAT}; } } @@ -1455,7 +1455,7 @@ util::ResultPtr, DatabaseStatus> MakeDatabase(co #endif { return {util::Error{Untranslated(strprintf("Failed to open database path '%s'. Build does not support Berkeley DB database format.", fs::PathToString(path)))}, - DatabaseStatus::FAILED_BAD_FORMAT}; + DatabaseError::FAILED_BAD_FORMAT}; } } } // namespace wallet