mirror of
https://github.com/monero-project/monero.git
synced 2024-12-14 04:16:32 +02:00
Wallet API : WalletManager::findWallets() added
This commit is contained in:
parent
ec949c383c
commit
2facbe77e4
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -73,11 +73,12 @@ const std::string TESTNET_WALLET2_NAME = WALLETS_ROOT_DIR + "wallet_02.bin";
|
||||
const std::string TESTNET_WALLET3_NAME = WALLETS_ROOT_DIR + "wallet_03.bin";
|
||||
const std::string TESTNET_WALLET4_NAME = WALLETS_ROOT_DIR + "wallet_04.bin";
|
||||
const std::string TESTNET_WALLET5_NAME = WALLETS_ROOT_DIR + "wallet_05.bin";
|
||||
const std::string TESTNET_WALLET6_NAME = WALLETS_ROOT_DIR + "wallet_06.bin";
|
||||
|
||||
const char * TESTNET_WALLET_PASS = "";
|
||||
|
||||
const std::string CURRENT_SRC_WALLET = TESTNET_WALLET1_NAME;
|
||||
const std::string CURRENT_DST_WALLET = TESTNET_WALLET5_NAME;
|
||||
const std::string CURRENT_DST_WALLET = TESTNET_WALLET6_NAME;
|
||||
|
||||
const char * TESTNET_DAEMON_ADDRESS = "localhost:38081";
|
||||
const uint64_t AMOUNT_10XMR = 10000000000000L;
|
||||
@ -131,12 +132,12 @@ struct Utils
|
||||
};
|
||||
|
||||
|
||||
struct DISABLED_WalletManagerTest : public testing::Test
|
||||
struct WalletManagerTest : public testing::Test
|
||||
{
|
||||
Bitmonero::WalletManager * wmgr;
|
||||
|
||||
|
||||
DISABLED_WalletManagerTest()
|
||||
WalletManagerTest()
|
||||
{
|
||||
std::cout << __FUNCTION__ << std::endl;
|
||||
wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
|
||||
@ -145,7 +146,7 @@ struct DISABLED_WalletManagerTest : public testing::Test
|
||||
}
|
||||
|
||||
|
||||
~DISABLED_WalletManagerTest()
|
||||
~WalletManagerTest()
|
||||
{
|
||||
std::cout << __FUNCTION__ << std::endl;
|
||||
//deleteWallet(WALLET_NAME);
|
||||
@ -180,7 +181,7 @@ struct WalletTest2 : public testing::Test
|
||||
};
|
||||
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerCreatesWallet)
|
||||
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
||||
{
|
||||
|
||||
Bitmonero::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
@ -197,7 +198,7 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerCreatesWallet)
|
||||
|
||||
}
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerOpensWallet)
|
||||
TEST_F(WalletManagerTest, WalletManagerOpensWallet)
|
||||
{
|
||||
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
@ -209,8 +210,8 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerOpensWallet)
|
||||
std::cout << "** seed: " << wallet2->seed() << std::endl;
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerChangesPassword)
|
||||
/*
|
||||
TEST_F(WalletManagerTest, WalletManagerChangesPassword)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
std::string seed1 = wallet1->seed();
|
||||
@ -226,7 +227,7 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerChangesPassword)
|
||||
|
||||
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerRecoversWallet)
|
||||
TEST_F(WalletManagerTest, WalletManagerRecoversWallet)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
std::string seed1 = wallet1->seed();
|
||||
@ -242,7 +243,7 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerRecoversWallet)
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet1)
|
||||
TEST_F(WalletManagerTest, WalletManagerStoresWallet1)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
std::string seed1 = wallet1->seed();
|
||||
@ -259,7 +260,7 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet1)
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet2)
|
||||
TEST_F(WalletManagerTest, WalletManagerStoresWallet2)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
std::string seed1 = wallet1->seed();
|
||||
@ -275,7 +276,7 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet2)
|
||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||
}
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet3)
|
||||
TEST_F(WalletManagerTest, WalletManagerStoresWallet3)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
std::string seed1 = wallet1->seed();
|
||||
@ -297,7 +298,7 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet3)
|
||||
|
||||
}
|
||||
|
||||
TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet4)
|
||||
TEST_F(WalletManagerTest, WalletManagerStoresWallet4)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->createWallet(WALLET_NAME, WALLET_PASS, WALLET_LANG);
|
||||
std::string seed1 = wallet1->seed();
|
||||
@ -317,7 +318,17 @@ TEST_F(DISABLED_WalletManagerTest, WalletManagerStoresWallet4)
|
||||
ASSERT_TRUE(wallet1->address() == address1);
|
||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||
}
|
||||
*/
|
||||
|
||||
TEST_F(WalletManagerTest, WalletManagerFindsWallet)
|
||||
{
|
||||
std::vector<std::string> wallets = wmgr->findWallets(WALLETS_ROOT_DIR);
|
||||
ASSERT_FALSE(wallets.empty());
|
||||
std::cout << "Found wallets: " << std::endl;
|
||||
for (auto wallet_path: wallets) {
|
||||
std::cout << wallet_path << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_F(WalletTest1, WalletShowsBalance)
|
||||
@ -349,6 +360,8 @@ TEST_F(WalletTest1, WalletRefresh)
|
||||
ASSERT_TRUE(wmgr->closeWallet(wallet1));
|
||||
}
|
||||
|
||||
|
||||
|
||||
TEST_F(WalletTest1, WalletTransaction)
|
||||
{
|
||||
Bitmonero::Wallet * wallet1 = wmgr->openWallet(CURRENT_SRC_WALLET, TESTNET_WALLET_PASS, true);
|
||||
|
@ -10,7 +10,7 @@ function create_wallet {
|
||||
create_wallet wallet_01.bin
|
||||
create_wallet wallet_02.bin
|
||||
create_wallet wallet_03.bin
|
||||
#create_wallet wallet_04.bin
|
||||
create_wallet wallet_04.bin
|
||||
create_wallet wallet_05.bin
|
||||
create_wallet wallet_06.bin
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
#!/bin/bash
|
||||
|
||||
rlwrap simplewallet --wallet-file wallet_04.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_04.log
|
||||
rlwrap simplewallet --wallet-file wallet_05.bin --password "" --testnet --trusted-daemon --daemon-address localhost:38081 --log-file wallet_05.log
|
||||
|
||||
|
@ -17,5 +17,6 @@ send_funds 100 wallet_02.bin
|
||||
send_funds 100 wallet_03.bin
|
||||
send_funds 100 wallet_04.bin
|
||||
send_funds 100 wallet_05.bin
|
||||
send_funds 100 wallet_06.bin
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user