diff options
author | Ilya Kitaev <mbg033@gmail.com> | 2016-06-03 14:52:58 +0300 |
---|---|---|
committer | Ilya Kitaev <mbg033@gmail.com> | 2016-06-03 14:52:58 +0300 |
commit | 2facbe77e485e8a824a08d862aa63f3f179480e9 (patch) | |
tree | 381d6c0411c4242c3e602fc16fe77472a2e1ea00 /src | |
parent | scripts for faster test wallets generation (diff) | |
download | monero-2facbe77e485e8a824a08d862aa63f3f179480e9.tar.xz |
Wallet API : WalletManager::findWallets() added
Diffstat (limited to 'src')
-rw-r--r-- | src/wallet/api/wallet_manager.cpp | 37 | ||||
-rw-r--r-- | src/wallet/api/wallet_manager.h | 1 | ||||
-rw-r--r-- | src/wallet/wallet2.h | 2 | ||||
-rw-r--r-- | src/wallet/wallet2_api.h | 21 |
4 files changed, 57 insertions, 4 deletions
diff --git a/src/wallet/api/wallet_manager.cpp b/src/wallet/api/wallet_manager.cpp index c056ada2c..c578098cc 100644 --- a/src/wallet/api/wallet_manager.cpp +++ b/src/wallet/api/wallet_manager.cpp @@ -32,6 +32,11 @@ #include "wallet_manager.h" #include "wallet.h" +#include <boost/filesystem.hpp> +#include <boost/regex.hpp> + +namespace fs = ::boost::filesystem; + namespace epee { unsigned int g_test_dbg_lock_sleep = 0; } @@ -77,6 +82,38 @@ bool WalletManagerImpl::walletExists(const std::string &path) return false; } + +std::vector<std::string> WalletManagerImpl::findWallets(const std::string &path) +{ + std::vector<std::string> result; + const boost::regex wallet_rx("(.*)\\.(address\\.txt)$"); + boost::filesystem::recursive_directory_iterator end_itr; // Default ctor yields past-the-end + boost::filesystem::path work_dir(path); + + for (boost::filesystem::recursive_directory_iterator itr(path); itr != end_itr; ++itr) { + // Skip if not a file + if (!boost::filesystem::is_regular_file(itr->status())) + continue; + boost::smatch what; + std::string filename = itr->path().filename().string(); + + LOG_PRINT_L3("Checking filename: " << filename); + + bool matched = boost::regex_match(filename, what, wallet_rx); + if (matched) { + // if address file found, checking if there's corresponding .keys file and wallet file itself + std::string wallet_file = (itr->path().parent_path() /= what[1]).string(); + std::string wallet_key_file = wallet_file + std::string(".keys"); + if (boost::filesystem::exists(wallet_file) + && boost::filesystem::exists(wallet_key_file)) { + LOG_PRINT_L3("Found wallet: " << wallet_file); + result.push_back(wallet_file); + } + } + } + return result; +} + std::string WalletManagerImpl::errorString() const { return m_errorString; diff --git a/src/wallet/api/wallet_manager.h b/src/wallet/api/wallet_manager.h index d608eb7f0..7585c1af7 100644 --- a/src/wallet/api/wallet_manager.h +++ b/src/wallet/api/wallet_manager.h @@ -43,6 +43,7 @@ public: virtual Wallet * recoveryWallet(const std::string &path, const std::string &memo, bool testnet); virtual bool closeWallet(Wallet *wallet); bool walletExists(const std::string &path); + std::vector<std::string> findWallets(const std::string &path); std::string errorString() const; void setDaemonHost(const std::string &hostname); diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 85bf33e3f..e7e4e7772 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -219,7 +219,7 @@ namespace tools void store(); /*! * \brief store_to - stores wallet to another file(s), deleting old ones - * \param path - path to the wallet file (keys and address filenames will be generated based on this filename) + * \param path - path to the wallet file (withkeys and address filenames will be generated based on this filename) * \param password - password to protect new wallet (TODO: probably better save the password in the wallet object?) */ void store_to(const std::string &path, const std::string &password); diff --git a/src/wallet/wallet2_api.h b/src/wallet/wallet2_api.h index 7841c299d..b98bb8661 100644 --- a/src/wallet/wallet2_api.h +++ b/src/wallet/wallet2_api.h @@ -190,12 +190,27 @@ struct WalletManager */ virtual bool closeWallet(Wallet *wallet) = 0; - //! checks if wallet with the given name already exists + /* + * ! checks if wallet with the given name already exists + */ + + /*! + * @brief TODO: delme walletExists - check if the given filename is the wallet + * @param path - filename + * @return + */ virtual bool walletExists(const std::string &path) = 0; + /*! + * \brief findWallets - searches for the wallet files by given path name recursively + * \param path - starting point to search + * \return - list of strings with found wallets (absolute paths); + */ + virtual std::vector<std::string> findWallets(const std::string &path) = 0; + + //! returns verbose error string regarding last error; virtual std::string errorString() const = 0; -// //! set -// virtual void setDaemonAddress(const std::string &address) = 0; + }; |