1
0
Fork 0
forked from lthn/blockchain

implemented restore and generate wallet

This commit is contained in:
cryptozoidberg 2020-01-16 23:52:29 +01:00
parent e4dfa7d519
commit 068bda9052
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
3 changed files with 59 additions and 7 deletions

View file

@ -8,12 +8,19 @@ namespace plain_wallet
{
typedef epee::json_rpc::response<epee::json_rpc::dummy_result, error> error_response;
plain_wallet_api_impl::plain_wallet_api_impl(const std::string ip, const std::string port)
plain_wallet_api_impl::plain_wallet_api_impl(const std::string ip, const std::string port):m_stop(false)
{
m_wallet.reset(new tools::wallet2());
m_wallet->init(ip + ":" + port);
m_rpc_wrapper.reset(new tools::wallet_rpc_server(*m_wallet));
}
plain_wallet_api_impl::~plain_wallet_api_impl()
{
if (m_sync_thread.joinable())
m_sync_thread.join();
}
std::string plain_wallet_api_impl::open(const std::string& path, const std::string password)
{
error_response err_result = AUTO_VAL_INIT(err_result);
@ -39,18 +46,61 @@ namespace plain_wallet
tools::get_wallet_info(*m_wallet, ok_response.result.wi);
return epee::serialization::store_t_to_json(ok_response);
}
std::string plain_wallet_api_impl::restore(const std::string& seed, const std::string& path, const std::string password)
{
error_response err_result = AUTO_VAL_INIT(err_result);
try
{
m_wallet->restore(epee::string_encoding::utf8_to_wstring(path), password, seed);
}
catch (const tools::error::wallet_load_notice_wallet_restored& e)
{
LOG_ERROR("Wallet initialize was with problems, but still worked : " << e.what());
err_result.error.code = API_RETURN_CODE_FILE_RESTORED;
return epee::serialization::store_t_to_json(err_result);
}
catch (const std::exception& e)
{
LOG_ERROR("Wallet initialize failed: " << e.what());
err_result.error.code = API_RETURN_CODE_FAIL;
return epee::serialization::store_t_to_json(err_result);
}
epee::json_rpc::response<open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
tools::get_wallet_info(*m_wallet, ok_response.result.wi);
return epee::serialization::store_t_to_json(ok_response);
}
std::string plain_wallet_api_impl::generate(const std::string& path, const std::string password)
{
error_response err_result = AUTO_VAL_INIT(err_result);
try
{
m_wallet->generate(epee::string_encoding::utf8_to_wstring(path), password);
}
catch (const tools::error::wallet_load_notice_wallet_restored& e)
{
LOG_ERROR("Wallet initialize was with problems, but still worked : " << e.what());
err_result.error.code = API_RETURN_CODE_FILE_RESTORED;
return epee::serialization::store_t_to_json(err_result);
}
catch (const std::exception& e)
{
LOG_ERROR("Wallet initialize failed: " << e.what());
err_result.error.code = API_RETURN_CODE_FAIL;
return epee::serialization::store_t_to_json(err_result);
}
epee::json_rpc::response<open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
tools::get_wallet_info(*m_wallet, ok_response.result.wi);
return epee::serialization::store_t_to_json(ok_response);
}
bool plain_wallet_api_impl::start_sync_thread()
{
m_sync_thread = std::thread([&]()
{
});
}
std::string plain_wallet_api_impl::get_sync_status()
{

View file

@ -27,7 +27,9 @@ namespace plain_wallet
std::string invoke(const std::string& params);
private:
bool get_wallet_info(view::wallet_info& wi);
std::thread m_sync_thread;
std::atomic<bool> m_stop;
std::atomic<bool> m_sync_finished;
std::shared_ptr<tools::wallet2> m_wallet;
std::shared_ptr<tools::wallet_rpc_server> m_rpc_wrapper;
};

View file

@ -452,9 +452,9 @@ namespace tools
END_SERIALIZE()
};
void assign_account(const currency::account_base& acc);
void generate(const std::wstring& wallet, const std::string& password);
void generate(const std::wstring& path, const std::string& password);
void restore(const std::wstring& path, const std::string& pass, const std::string& restore_key);
void load(const std::wstring& wallet, const std::string& password);
void load(const std::wstring& path, const std::string& password);
void store();
void store(const std::wstring& path);
void store(const std::wstring& path, const std::string& password);