Skip to content

Commit 3a45dc3

Browse files
committed
Change type of backup_file parameter in RestoreWallet/restoreWallet
`fs::path` looks more native than `std::string` for a parameter which represents a backup file. This change eliminates back-and-forth type conversions.
1 parent 213172c commit 3a45dc3

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

src/interfaces/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#define BITCOIN_INTERFACES_WALLET_H
77

88
#include <consensus/amount.h>
9+
#include <fs.h>
910
#include <interfaces/chain.h> // For ChainClient
1011
#include <pubkey.h> // For CKeyID and CScriptID (definitions needed in CTxDestination instantiation)
1112
#include <script/standard.h> // For CTxDestination
@@ -326,7 +327,7 @@ class WalletLoader : public ChainClient
326327
virtual std::string getWalletDir() = 0;
327328

328329
//! Restore backup wallet
329-
virtual std::unique_ptr<Wallet> restoreWallet(const std::string& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
330+
virtual std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) = 0;
330331

331332
//! Return available wallets in wallet directory.
332333
virtual std::vector<std::string> listWalletDir() = 0;

src/wallet/interfaces.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ class WalletLoaderImpl : public WalletLoader
557557
options.require_existing = true;
558558
return MakeWallet(m_context, LoadWallet(m_context, name, true /* load_on_start */, options, status, error, warnings));
559559
}
560-
std::unique_ptr<Wallet> restoreWallet(const std::string& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
560+
std::unique_ptr<Wallet> restoreWallet(const fs::path& backup_file, const std::string& wallet_name, bilingual_str& error, std::vector<bilingual_str>& warnings) override
561561
{
562562
DatabaseStatus status;
563563

src/wallet/rpc/backup.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1887,7 +1887,7 @@ RPCHelpMan restorewallet()
18871887
bilingual_str error;
18881888
std::vector<bilingual_str> warnings;
18891889

1890-
const std::shared_ptr<CWallet> wallet = RestoreWallet(context, fs::PathToString(backup_file), wallet_name, load_on_start, status, error, warnings);
1890+
const std::shared_ptr<CWallet> wallet = RestoreWallet(context, backup_file, wallet_name, load_on_start, status, error, warnings);
18911891

18921892
HandleWalletError(wallet, status, error);
18931893

src/wallet/wallet.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,12 +357,12 @@ std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string&
357357
return wallet;
358358
}
359359

360-
std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const std::string& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings)
360+
std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings)
361361
{
362362
DatabaseOptions options;
363363
options.require_existing = true;
364364

365-
if (!fs::exists(fs::u8path(backup_file))) {
365+
if (!fs::exists(backup_file)) {
366366
error = Untranslated("Backup file does not exist");
367367
status = DatabaseStatus::FAILED_INVALID_BACKUP_FILE;
368368
return nullptr;
@@ -377,7 +377,7 @@ std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const std::string
377377
}
378378

379379
auto wallet_file = wallet_path / "wallet.dat";
380-
fs::copy_file(fs::u8path(backup_file), wallet_file, fs::copy_option::fail_if_exists);
380+
fs::copy_file(backup_file, wallet_file, fs::copy_option::fail_if_exists);
381381

382382
auto wallet = LoadWallet(context, wallet_name, load_on_start, options, status, error, warnings);
383383

src/wallet/wallet.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#define BITCOIN_WALLET_WALLET_H
88

99
#include <consensus/amount.h>
10+
#include <fs.h>
1011
#include <interfaces/chain.h>
1112
#include <interfaces/handler.h>
1213
#include <outputtype.h>
@@ -60,7 +61,7 @@ std::vector<std::shared_ptr<CWallet>> GetWallets(WalletContext& context);
6061
std::shared_ptr<CWallet> GetWallet(WalletContext& context, const std::string& name);
6162
std::shared_ptr<CWallet> LoadWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
6263
std::shared_ptr<CWallet> CreateWallet(WalletContext& context, const std::string& name, std::optional<bool> load_on_start, DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
63-
std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const std::string& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
64+
std::shared_ptr<CWallet> RestoreWallet(WalletContext& context, const fs::path& backup_file, const std::string& wallet_name, std::optional<bool> load_on_start, DatabaseStatus& status, bilingual_str& error, std::vector<bilingual_str>& warnings);
6465
std::unique_ptr<interfaces::Handler> HandleLoadWallet(WalletContext& context, LoadWalletFn load_wallet);
6566
std::unique_ptr<WalletDatabase> MakeWalletDatabase(const std::string& name, const DatabaseOptions& options, DatabaseStatus& status, bilingual_str& error);
6667

0 commit comments

Comments
 (0)