|
|
@ -69,6 +69,7 @@ public:
|
|
|
|
std::string errorString() const;
|
|
|
|
std::string errorString() const;
|
|
|
|
bool setPassword(const std::string &password);
|
|
|
|
bool setPassword(const std::string &password);
|
|
|
|
std::string address() const;
|
|
|
|
std::string address() const;
|
|
|
|
|
|
|
|
bool store(const std::string &path);
|
|
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
private:
|
|
|
|
void clearStatus();
|
|
|
|
void clearStatus();
|
|
|
@ -78,7 +79,7 @@ private:
|
|
|
|
tools::wallet2 * m_wallet;
|
|
|
|
tools::wallet2 * m_wallet;
|
|
|
|
int m_status;
|
|
|
|
int m_status;
|
|
|
|
std::string m_errorString;
|
|
|
|
std::string m_errorString;
|
|
|
|
|
|
|
|
std::string m_password;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
WalletImpl::WalletImpl()
|
|
|
|
WalletImpl::WalletImpl()
|
|
|
@ -118,34 +119,37 @@ bool WalletImpl::create(const std::string &path, const std::string &password, co
|
|
|
|
crypto::secret_key recovery_val, secret_key;
|
|
|
|
crypto::secret_key recovery_val, secret_key;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
recovery_val = m_wallet->generate(path, password, secret_key, false, false);
|
|
|
|
recovery_val = m_wallet->generate(path, password, secret_key, false, false);
|
|
|
|
|
|
|
|
m_password = password;
|
|
|
|
|
|
|
|
m_status = Status_Ok;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
LOG_ERROR("Error creating wallet: " << e.what());
|
|
|
|
LOG_ERROR("Error creating wallet: " << e.what());
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_errorString = e.what();
|
|
|
|
m_errorString = e.what();
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WalletImpl::open(const std::string &path, const std::string &password)
|
|
|
|
bool WalletImpl::open(const std::string &path, const std::string &password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
clearStatus();
|
|
|
|
clearStatus();
|
|
|
|
bool result = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
// TODO: handle "deprecated"
|
|
|
|
// TODO: handle "deprecated"
|
|
|
|
m_wallet->load(path, password);
|
|
|
|
m_wallet->load(path, password);
|
|
|
|
result = true;
|
|
|
|
|
|
|
|
|
|
|
|
m_password = password;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
LOG_ERROR("Error opening wallet: " << e.what());
|
|
|
|
LOG_ERROR("Error opening wallet: " << e.what());
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_errorString = e.what();
|
|
|
|
m_errorString = e.what();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return m_status == Status_Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WalletImpl::recover(const std::string &path, const std::string &seed)
|
|
|
|
bool WalletImpl::recover(const std::string &path, const std::string &seed)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
clearStatus();
|
|
|
|
m_errorString.clear();
|
|
|
|
m_errorString.clear();
|
|
|
|
if (seed.empty()) {
|
|
|
|
if (seed.empty()) {
|
|
|
|
m_errorString = "Electrum seed is empty";
|
|
|
|
m_errorString = "Electrum seed is empty";
|
|
|
@ -162,23 +166,20 @@ bool WalletImpl::recover(const std::string &path, const std::string &seed)
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
m_wallet->set_seed_language(old_language);
|
|
|
|
m_wallet->set_seed_language(old_language);
|
|
|
|
m_wallet->generate(path, "", recovery_key, true, false);
|
|
|
|
m_wallet->generate(path, "", recovery_key, true, false);
|
|
|
|
// TODO: wallet->init(daemon_address);
|
|
|
|
// TODO: wallet->init(daemon_address);
|
|
|
|
m_status = Status_Ok;
|
|
|
|
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_errorString = e.what();
|
|
|
|
m_errorString = e.what();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result = m_status == Status_Ok;
|
|
|
|
return m_status == Status_Ok;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool WalletImpl::close()
|
|
|
|
bool WalletImpl::close()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
clearStatus();
|
|
|
|
bool result = false;
|
|
|
|
bool result = false;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
m_wallet->store();
|
|
|
|
m_wallet->store();
|
|
|
@ -222,16 +223,15 @@ std::string WalletImpl::errorString() const
|
|
|
|
|
|
|
|
|
|
|
|
bool WalletImpl::setPassword(const std::string &password)
|
|
|
|
bool WalletImpl::setPassword(const std::string &password)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bool result = false;
|
|
|
|
clearStatus();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
m_wallet->rewrite(m_wallet->get_wallet_file(), password);
|
|
|
|
m_wallet->rewrite(m_wallet->get_wallet_file(), password);
|
|
|
|
result = true;
|
|
|
|
m_password = password;
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
result = false;
|
|
|
|
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_status = Status_Error;
|
|
|
|
m_errorString = e.what();
|
|
|
|
m_errorString = e.what();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
return m_status == Status_Ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string WalletImpl::address() const
|
|
|
|
std::string WalletImpl::address() const
|
|
|
@ -239,6 +239,24 @@ std::string WalletImpl::address() const
|
|
|
|
return m_wallet->get_account().get_public_address_str(m_wallet->testnet());
|
|
|
|
return m_wallet->get_account().get_public_address_str(m_wallet->testnet());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool WalletImpl::store(const std::string &path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
clearStatus();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (path.empty()) {
|
|
|
|
|
|
|
|
m_wallet->store();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
m_wallet->store_to(path, m_password);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (const std::exception &e) {
|
|
|
|
|
|
|
|
LOG_ERROR("Error storing wallet: " << e.what());
|
|
|
|
|
|
|
|
m_status = Status_Error;
|
|
|
|
|
|
|
|
m_errorString = e.what();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return m_status == Status_Ok;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void WalletImpl::clearStatus()
|
|
|
|
void WalletImpl::clearStatus()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
m_status = Status_Ok;
|
|
|
|
m_status = Status_Ok;
|
|
|
@ -316,9 +334,9 @@ std::string WalletManagerImpl::errorString() const
|
|
|
|
///////////////////// WalletManagerFactory implementation //////////////////////
|
|
|
|
///////////////////// WalletManagerFactory implementation //////////////////////
|
|
|
|
WalletManager *WalletManagerFactory::getWalletManager()
|
|
|
|
WalletManager *WalletManagerFactory::getWalletManager()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// TODO: initialize logger here
|
|
|
|
|
|
|
|
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_0);
|
|
|
|
|
|
|
|
if (!g_walletManager) {
|
|
|
|
if (!g_walletManager) {
|
|
|
|
|
|
|
|
epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_0);
|
|
|
|
g_walletManager = new WalletManagerImpl();
|
|
|
|
g_walletManager = new WalletManagerImpl();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|