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-
This commit is contained in:
Ryan Ofsky 2024-02-22 14:43:16 -05:00
parent f193dfd14e
commit e2376f9847
14 changed files with 63 additions and 64 deletions

View file

@ -943,9 +943,9 @@ std::unique_ptr<DatabaseBatch> BerkeleyDatabase::MakeBatch(bool flush_on_close)
return std::make_unique<BerkeleyBatch>(*this, false, flush_on_close);
}
util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseStatus> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options)
util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseError> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options)
{
util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseStatus> result;
util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseError> result;
fs::path data_file = BDBDataFile(path);
std::unique_ptr<BerkeleyDatabase> db;
@ -955,14 +955,14 @@ util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseStatus> MakeBerkeleyD
std::shared_ptr<BerkeleyEnvironment> 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<BerkeleyDatabase>(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;
}

View file

@ -220,7 +220,7 @@ std::string BerkeleyDatabaseVersion();
bool BerkeleyDatabaseSanityCheck();
//! Return object giving access to Berkeley database at specified path.
util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseStatus> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options);
util::ResultPtr<std::unique_ptr<BerkeleyDatabase>, DatabaseError> MakeBerkeleyDatabase(const fs::path& path, const DatabaseOptions& options);
} // namespace wallet
#endif // BITCOIN_WALLET_BDB_H

View file

@ -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<std::pair<fs::path, std::string>> ListDatabases(const fs::path& path);
void ReadDatabaseArgs(const ArgsManager& args, DatabaseOptions& options);
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseStatus> MakeDatabase(const fs::path& path, const DatabaseOptions& options);
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseError> MakeDatabase(const fs::path& path, const DatabaseOptions& options);
fs::path BDBDataFile(const fs::path& path);
fs::path SQLiteDataFile(const fs::path& path);

View file

@ -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<void> 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);

View file

@ -768,13 +768,13 @@ std::unique_ptr<DatabaseCursor> BerkeleyROBatch::GetNewPrefixCursor(Span<const s
return std::make_unique<BerkeleyROCursor>(m_database, prefix);
}
util::ResultPtr<std::unique_ptr<BerkeleyRODatabase>, DatabaseStatus> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options)
util::ResultPtr<std::unique_ptr<BerkeleyRODatabase>, DatabaseError> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options)
{
fs::path data_file = BDBDataFile(path);
try {
return std::make_unique<BerkeleyRODatabase>(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

View file

@ -120,7 +120,7 @@ public:
};
//! Return object giving access to Berkeley Read Only database at specified path.
util::ResultPtr<std::unique_ptr<BerkeleyRODatabase>, DatabaseStatus> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options);
util::ResultPtr<std::unique_ptr<BerkeleyRODatabase>, DatabaseError> MakeBerkeleyRODatabase(const fs::path& path, const DatabaseOptions& options);
} // namespace wallet
#endif // BITCOIN_WALLET_MIGRATE_H

View file

@ -136,24 +136,24 @@ void PushParentDescriptors(const CWallet& wallet, const CScript& script_pubkey,
entry.pushKV("parent_descs", std::move(parent_descs));
}
void HandleWalletError(const util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus>& wallet)
void HandleWalletError(const util::ResultPtr<std::shared_ptr<CWallet>, 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.

View file

@ -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<std::shared_ptr<CWallet>, DatabaseStatus>& wallet);
void HandleWalletError(const util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError>& wallet);
void AppendLastProcessedBlock(UniValue& entry, const CWallet& wallet) EXCLUSIVE_LOCKS_REQUIRED(wallet.cs_wallet);
} // namespace wallet

View file

@ -426,7 +426,7 @@ static RPCHelpMan createwallet()
std::optional<bool> load_on_start = request.params[6].isNull() ? std::nullopt : std::optional<bool>(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);
}

View file

@ -696,19 +696,19 @@ bool SQLiteBatch::TxnAbort()
return res == SQLITE_OK;
}
util::ResultPtr<std::unique_ptr<SQLiteDatabase>, DatabaseStatus> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options)
util::ResultPtr<std::unique_ptr<SQLiteDatabase>, DatabaseError> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options)
{
util::ResultPtr<std::unique_ptr<SQLiteDatabase>, DatabaseStatus> result;
util::ResultPtr<std::unique_ptr<SQLiteDatabase>, DatabaseError> result;
try {
fs::path data_file = SQLiteDataFile(path);
auto db = std::make_unique<SQLiteDatabase>(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;
}

View file

@ -179,7 +179,7 @@ public:
bool m_use_unsafe_sync;
};
util::ResultPtr<std::unique_ptr<SQLiteDatabase>, DatabaseStatus> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options);
util::ResultPtr<std::unique_ptr<SQLiteDatabase>, DatabaseError> MakeSQLiteDatabase(const fs::path& path, const DatabaseOptions& options);
std::string SQLiteDatabaseVersion();
} // namespace wallet

View file

@ -270,9 +270,9 @@ void WaitForDeleteWallet(std::shared_ptr<CWallet>&& wallet)
}
namespace {
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> LoadWalletInternal(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options)
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> LoadWalletInternal(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options)
{
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> result;
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> result;
try {
auto database{MakeWalletDatabase(name, options) >> result};
if (!database) {
@ -287,7 +287,7 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
@ -305,7 +305,7 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
@ -369,20 +369,20 @@ private:
};
} // namespace
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options)
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> 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<std::shared_ptr<CWallet>, DatabaseStatus> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options)
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options)
{
util::Result<std::shared_ptr<CWallet>, DatabaseStatus> result;
util::Result<std::shared_ptr<CWallet>, DatabaseError> result;
uint64_t wallet_creation_flags = options.create_flags;
const SecureString& passphrase = options.create_passphrase;
@ -403,19 +403,19 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
@ -424,7 +424,7 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
@ -432,7 +432,7 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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<CWallet> wallet = create.value();
@ -440,13 +440,13 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
@ -458,7 +458,7 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
}
@ -486,9 +486,9 @@ util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> CreateWallet(WalletCon
return result;
}
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start)
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start)
{
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> result;
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> result;
DatabaseOptions options;
ReadDatabaseArgs(*context.args, options);
options.require_existing = true;
@ -498,12 +498,12 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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;
}
@ -512,7 +512,7 @@ util::ResultPtr<std::shared_ptr<CWallet>, 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{Untranslated(strprintf("Unexpected exception: %s", e.what()))}, DatabaseStatus::FAILED_LOAD});
result.Update({util::Error{Untranslated(strprintf("Unexpected exception: %s", e.what()))}, DatabaseError::FAILED_LOAD});
return result;
}
if (!result) {
@ -2961,12 +2961,12 @@ static util::Result<fs::path> GetWalletPath(const std::string& name)
return wallet_path;
}
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseStatus> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options)
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseError> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options)
{
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseStatus> result;
util::ResultPtr<std::unique_ptr<WalletDatabase>, 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));

View file

@ -92,12 +92,12 @@ util::Result<void> RemoveWallet(WalletContext& context, const std::shared_ptr<CW
std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
std::shared_ptr<CWallet> GetDefaultWallet(WalletContext& context, size_t& count);
std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options);
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options);
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseStatus> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start);
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options);
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options);
util::ResultPtr<std::shared_ptr<CWallet>, DatabaseError> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start);
std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
void NotifyWalletLoaded(WalletContext& context, const std::shared_ptr<CWallet>& wallet);
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseStatus> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options);
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseError> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options);
//! -paytxfee default
constexpr CAmount DEFAULT_PAY_TX_FEE = 0;

View file

@ -1377,13 +1377,13 @@ void WalletBatch::RegisterTxnListener(const DbTxnListener& l)
m_txn_listeners.emplace_back(l);
}
util::ResultPtr<std::unique_ptr<WalletDatabase>, DatabaseStatus> MakeDatabase(const fs::path& path, const DatabaseOptions& options)
util::ResultPtr<std::unique_ptr<WalletDatabase>, 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<DatabaseFormat> format;
@ -1393,20 +1393,20 @@ util::ResultPtr<std::unique_ptr<WalletDatabase>, 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<std::unique_ptr<WalletDatabase>, 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<std::unique_ptr<WalletDatabase>, 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<std::unique_ptr<WalletDatabase>, 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