mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-18 22:35:39 +01:00
wallet: Refactor to use WalletLocation
This commit is contained in:
@@ -2405,26 +2405,26 @@ static UniValue loadwallet(const JSONRPCRequest& request)
|
||||
+ HelpExampleCli("loadwallet", "\"test.dat\"")
|
||||
+ HelpExampleRpc("loadwallet", "\"test.dat\"")
|
||||
);
|
||||
std::string wallet_file = request.params[0].get_str();
|
||||
|
||||
WalletLocation location(request.params[0].get_str());
|
||||
std::string error;
|
||||
|
||||
fs::path wallet_path = fs::absolute(wallet_file, GetWalletDir());
|
||||
if (fs::symlink_status(wallet_path).type() == fs::file_not_found) {
|
||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + wallet_file + " not found.");
|
||||
} else if (fs::is_directory(wallet_path)) {
|
||||
if (!location.Exists()) {
|
||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Wallet " + location.GetName() + " not found.");
|
||||
} else if (fs::is_directory(location.GetPath())) {
|
||||
// The given filename is a directory. Check that there's a wallet.dat file.
|
||||
fs::path wallet_dat_file = wallet_path / "wallet.dat";
|
||||
fs::path wallet_dat_file = location.GetPath() / "wallet.dat";
|
||||
if (fs::symlink_status(wallet_dat_file).type() == fs::file_not_found) {
|
||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Directory " + wallet_file + " does not contain a wallet.dat file.");
|
||||
throw JSONRPCError(RPC_WALLET_NOT_FOUND, "Directory " + location.GetName() + " does not contain a wallet.dat file.");
|
||||
}
|
||||
}
|
||||
|
||||
std::string warning;
|
||||
if (!CWallet::Verify(wallet_file, false, error, warning)) {
|
||||
if (!CWallet::Verify(location, false, error, warning)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet file verification failed: " + error);
|
||||
}
|
||||
|
||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(wallet_file, fs::absolute(wallet_file, GetWalletDir()));
|
||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(location);
|
||||
if (!wallet) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet loading failed.");
|
||||
}
|
||||
@@ -2458,7 +2458,6 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
+ HelpExampleRpc("createwallet", "\"testwallet\"")
|
||||
);
|
||||
}
|
||||
std::string wallet_name = request.params[0].get_str();
|
||||
std::string error;
|
||||
std::string warning;
|
||||
|
||||
@@ -2467,17 +2466,17 @@ static UniValue createwallet(const JSONRPCRequest& request)
|
||||
disable_privatekeys = request.params[1].get_bool();
|
||||
}
|
||||
|
||||
fs::path wallet_path = fs::absolute(wallet_name, GetWalletDir());
|
||||
if (fs::symlink_status(wallet_path).type() != fs::file_not_found) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet " + wallet_name + " already exists.");
|
||||
WalletLocation location(request.params[0].get_str());
|
||||
if (location.Exists()) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet " + location.GetName() + " already exists.");
|
||||
}
|
||||
|
||||
// Wallet::Verify will check if we're trying to create a wallet with a duplication name.
|
||||
if (!CWallet::Verify(wallet_name, false, error, warning)) {
|
||||
if (!CWallet::Verify(location, false, error, warning)) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet file verification failed: " + error);
|
||||
}
|
||||
|
||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(wallet_name, fs::absolute(wallet_name, GetWalletDir()), (disable_privatekeys ? (uint64_t)WALLET_FLAG_DISABLE_PRIVATE_KEYS : 0));
|
||||
std::shared_ptr<CWallet> const wallet = CWallet::CreateWalletFromFile(location, (disable_privatekeys ? (uint64_t)WALLET_FLAG_DISABLE_PRIVATE_KEYS : 0));
|
||||
if (!wallet) {
|
||||
throw JSONRPCError(RPC_WALLET_ERROR, "Wallet creation failed.");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user