mirror of
https://git.wownero.com/wownero/wownero.git
synced 2024-08-15 01:03:23 +00:00
get_seed() included to interface
This commit is contained in:
parent
930bed7074
commit
f1f9279d90
3 changed files with 65 additions and 23 deletions
|
@ -45,6 +45,7 @@ namespace {
|
|||
|
||||
}
|
||||
|
||||
Wallet::~Wallet() {}
|
||||
|
||||
///////////////////////// Wallet implementation ////////////////////////////////
|
||||
class WalletImpl : public Wallet
|
||||
|
@ -55,26 +56,26 @@ public:
|
|||
bool create(const std::string &path, const std::string &password,
|
||||
const std::string &language);
|
||||
bool open(const std::string &path, const std::string &password);
|
||||
|
||||
std::string seed() const;
|
||||
std::string getSeedLanguage() const;
|
||||
void setSeedLanguage(const std::string &arg);
|
||||
|
||||
private:
|
||||
std::unique_ptr<tools::wallet2> m_wallet;
|
||||
//std::unique_ptr<tools::wallet2> m_wallet;
|
||||
tools::wallet2 * m_wallet;
|
||||
|
||||
};
|
||||
|
||||
|
||||
WalletImpl::WalletImpl()
|
||||
:m_wallet(nullptr)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
Wallet::~Wallet() {}
|
||||
|
||||
WalletImpl::~WalletImpl()
|
||||
{
|
||||
//delete m_wallet;
|
||||
delete m_wallet;
|
||||
}
|
||||
|
||||
bool WalletImpl::create(const std::string &path, const std::string &password, const std::string &language)
|
||||
|
@ -82,6 +83,7 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
|
|||
bool keys_file_exists;
|
||||
bool wallet_file_exists;
|
||||
tools::wallet2::wallet_exists(path, keys_file_exists, wallet_file_exists);
|
||||
// TODO: figure out how to setup logger;
|
||||
LOG_PRINT_L3("wallet_path: " << path << "");
|
||||
LOG_PRINT_L3("keys_file_exists: " << std::boolalpha << keys_file_exists << std::noboolalpha
|
||||
<< " wallet_file_exists: " << std::boolalpha << wallet_file_exists << std::noboolalpha);
|
||||
|
@ -94,12 +96,12 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
|
|||
return false;
|
||||
|
||||
}
|
||||
|
||||
// TODO: validate language
|
||||
|
||||
|
||||
// TODO: create wallet
|
||||
m_wallet.reset(new tools::wallet2());
|
||||
//m_wallet.reset(new tools::wallet2());
|
||||
m_wallet = new tools::wallet2();
|
||||
m_wallet->set_seed_language(language);
|
||||
|
||||
crypto::secret_key recovery_val, secret_key;
|
||||
try {
|
||||
recovery_val = m_wallet->generate(path, password, secret_key, false, false);
|
||||
|
@ -107,14 +109,27 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
|
|||
// TODO: log exception
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string WalletImpl::seed() const
|
||||
{
|
||||
return "";
|
||||
std::string seed;
|
||||
if (m_wallet)
|
||||
m_wallet->get_seed(seed);
|
||||
return seed;
|
||||
}
|
||||
|
||||
std::string WalletImpl::getSeedLanguage() const
|
||||
{
|
||||
return m_wallet->get_seed_language();
|
||||
}
|
||||
|
||||
void WalletImpl::setSeedLanguage(const std::string &arg)
|
||||
{
|
||||
m_wallet->set_seed_language(arg);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////// WalletManager implementation /////////////////////////
|
||||
|
@ -141,7 +156,6 @@ Wallet *WalletManagerImpl::createWallet(const std::string &path, const std::stri
|
|||
delete wallet;
|
||||
wallet = nullptr;
|
||||
}
|
||||
|
||||
return wallet;
|
||||
}
|
||||
|
||||
|
|
|
@ -44,8 +44,11 @@ namespace Bitmonero {
|
|||
struct Wallet
|
||||
{
|
||||
// TODO define wallet interface (decide what needed from wallet2)
|
||||
virtual ~Wallet() = 0;
|
||||
virtual std::string seed() const = 0;
|
||||
virtual ~Wallet() = 0;
|
||||
virtual std::string seed() const = 0;
|
||||
virtual std::string getSeedLanguage() const = 0;
|
||||
virtual void setSeedLanguage(const std::string &arg) = 0;
|
||||
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,14 @@
|
|||
|
||||
#include "gtest/gtest.h"
|
||||
#include "wallet/wallet2_api.h"
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
|
||||
using namespace std;
|
||||
//unsigned int epee::g_test_dbg_lock_sleep = 0;
|
||||
|
||||
|
||||
|
@ -39,26 +46,44 @@ struct WalletManagerTest : public testing::Test
|
|||
{
|
||||
Bitmonero::WalletManager * wmgr;
|
||||
|
||||
const char * WALLET_NAME = "testwallet";
|
||||
const char * WALLET_PASS = "password";
|
||||
|
||||
|
||||
WalletManagerTest()
|
||||
{
|
||||
wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
|
||||
deleteWallet(WALLET_NAME);
|
||||
}
|
||||
|
||||
|
||||
~WalletManagerTest()
|
||||
{
|
||||
deleteWallet(WALLET_NAME);
|
||||
}
|
||||
|
||||
|
||||
void deleteWallet(const std::string & walletname)
|
||||
{
|
||||
boost::filesystem::remove(walletname);
|
||||
boost::filesystem::remove(walletname + ".address.txt");
|
||||
boost::filesystem::remove(walletname + ".keys");
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
TEST(WalletFactoryTest, WalletFactoryReturnsWalletManager)
|
||||
{
|
||||
Bitmonero::WalletManager * wmgr = Bitmonero::WalletManagerFactory::getWalletManager();
|
||||
EXPECT_NE(wmgr, nullptr);
|
||||
}
|
||||
|
||||
|
||||
TEST_F(WalletManagerTest, WalletManagerReturnsCreatesWallet)
|
||||
TEST_F(WalletManagerTest, WalletManagerCreatesWallet)
|
||||
{
|
||||
Bitmonero::Wallet * wallet = wmgr->createWallet("test_wallet", "password", "en_US");
|
||||
|
||||
Bitmonero::Wallet * wallet = wmgr->createWallet(WALLET_NAME, WALLET_PASS, "English");
|
||||
EXPECT_TRUE(wallet != nullptr);
|
||||
|
||||
EXPECT_TRUE(!wallet->seed().empty());
|
||||
std::vector<std::string> words;
|
||||
std::string seed = wallet->seed();
|
||||
boost::split(words, seed, boost::is_any_of(" "), boost::token_compress_on);
|
||||
EXPECT_TRUE(words.size() == 25);
|
||||
std::cout << "** seed: " << wallet->seed() << std::endl;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
|
Loading…
Reference in a new issue