diff options
author | Ilya Kitaev <mbg033@gmail.com> | 2016-06-03 14:52:58 +0300 |
---|---|---|
committer | Ilya Kitaev <mbg033@gmail.com> | 2016-06-23 16:01:41 +0300 |
commit | 8390bfa770e6606594b9feb5afb0d0ab0e6453aa (patch) | |
tree | 51810cfded2bd96332dd260e215ea4f6d38f8b4f /src/wallet/api/wallet_manager.cpp | |
parent | scripts for faster test wallets generation (diff) | |
download | monero-8390bfa770e6606594b9feb5afb0d0ab0e6453aa.tar.xz |
Wallet API : WalletManager::findWallets() added
Diffstat (limited to 'src/wallet/api/wallet_manager.cpp')
-rw-r--r-- | src/wallet/api/wallet_manager.cpp | 37 |
1 files changed, 37 insertions, 0 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; |