Skip to content

Commit

Permalink
Merge bitcoin#14350: Add WalletLocation class
Browse files Browse the repository at this point in the history
65f3672 wallet: Refactor to use WalletLocation (João Barbosa)
01a4c09 wallet: Add WalletLocation utility class (João Barbosa)

Pull request description:

  Advantages of this change:
   - avoid resolving wallet absolute path and name repetitively and in multiple places;
   - avoid calling `GetWalletDir` in multiple places;
   - extract these details from the actual wallet implementation.

  The `WalletLocation` class can be a way to represent a wallet not yet loaded that exists in the wallet directory.

Tree-SHA512: 71ec09786e038499710e7acafe92d66ab9883fc894964e267443ae9c10a6872a10995c3987a169c436a4e793dae96b28fb97bd7f78483c4b72ac930fa23f8686

# Conflicts:
#	src/qt/test/wallettests.cpp
#	src/wallet/rpcwallet.cpp
#	src/wallet/wallet.cpp
#	src/wallet/wallet.h
  • Loading branch information
laanwj authored and Munkybooty committed Jul 22, 2021
1 parent c97c579 commit a2c6db9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/wallet/wallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4930,9 +4930,11 @@ bool CWallet::Verify(const WalletLocation& location, bool salvage_wallet, std::s
}

// Make sure that the wallet path doesn't clash with an existing wallet path
if (IsWalletLoaded(wallet_path)) {
error_string = strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", location.GetName());
return false;
for (auto wallet : GetWallets()) {
if (wallet->GetLocation().GetPath() == wallet_path) {
error_string = strprintf("Error loading wallet %s. Duplicate -wallet filename specified.", location.GetName());
return false;
}
}

// Keep same database environment instance across Verify/Recover calls below.
Expand Down
11 changes: 11 additions & 0 deletions src/wallet/walletutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,14 @@ bool WalletLocation::Exists() const
{
return fs::symlink_status(m_path).type() != fs::file_not_found;
}

WalletLocation::WalletLocation(const std::string& name)
: m_name(name)
, m_path(fs::absolute(name, GetWalletDir()))
{
}

bool WalletLocation::Exists() const
{
return fs::symlink_status(m_path).type() != fs::file_not_found;
}
20 changes: 20 additions & 0 deletions src/wallet/walletutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,24 @@ class WalletLocation final
bool Exists() const;
};

//! The WalletLocation class provides wallet information.
class WalletLocation final
{
std::string m_name;
fs::path m_path;

public:
explicit WalletLocation() {}
explicit WalletLocation(const std::string& name);

//! Get wallet name.
const std::string& GetName() const { return m_name; }

//! Get wallet absolute path.
const fs::path& GetPath() const { return m_path; }

//! Return whether the wallet exists.
bool Exists() const;
};

#endif // BITCOIN_WALLET_WALLETUTIL_H

0 comments on commit a2c6db9

Please sign in to comment.