1
0
Fork 0
forked from lthn/blockchain

implemented invoke for plain_wallet amd fixed return codes to json

This commit is contained in:
cryptozoidberg 2020-01-18 23:23:47 +01:00
parent cbce45285c
commit e6dd2d28a5
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
5 changed files with 76 additions and 17 deletions

View file

@ -6,9 +6,9 @@
#pragma once
#include <stdint.h>
#include <QObject>
#ifndef Q_MOC_RUN
// #include <stdint.h>
// #include <QObject>
// #ifndef Q_MOC_RUN
#include "warnings.h"
PUSH_VS_WARNINGS
@ -22,7 +22,7 @@ DISABLE_VS_WARNINGS(4503)
#include "currency_core/basic_api_response_codes.h"
POP_VS_WARNINGS
#endif
//#endif
namespace view
{

View file

@ -24,9 +24,27 @@ namespace plain_wallet
view::transfers_array recent_history;
view::wallet_info wi;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(wallet_id)
KV_SERIALIZE(recent_history)
KV_SERIALIZE(wi)
END_KV_SERIALIZE_MAP()
}
};
struct sync_status_response
{
bool finished;
uint64_t progress;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(finished)
KV_SERIALIZE(progress)
END_KV_SERIALIZE_MAP()
};
struct basic_status_response
{
std::string status;
BEGIN_KV_SERIALIZE_MAP()
KV_SERIALIZE(status)
END_KV_SERIALIZE_MAP()
};
} // namespace tools

View file

@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include "plain_wallet_api_impl.h"
#include "wallet/wallet_helpers.h"
namespace plain_wallet
{
@ -95,32 +96,71 @@ namespace plain_wallet
return epee::serialization::store_t_to_json(ok_response);
}
bool plain_wallet_api_impl::start_sync_thread()
std::string plain_wallet_api_impl::start_sync_thread()
{
m_sync_thread = std::thread([&]()
{
m_wallet->refresh(m_stop);
try
{
m_wallet->refresh(m_stop);
}
catch (const std::exception& e)
{
LOG_ERROR("Wallet refresh failed: " << e.what());
return;
}
m_sync_finished = true;
});
basic_status_response bsr = AUTO_VAL_INIT(bsr);
bsr.status = API_RETURN_CODE_OK;
return epee::serialization::store_t_to_json(bsr);
}
bool plain_wallet_api_impl::cancel_sync_thread()
std::string plain_wallet_api_impl::cancel_sync_thread()
{
m_stop = true;
if (m_sync_thread.joinable())
m_sync_thread.join();
basic_status_response bsr = AUTO_VAL_INIT(bsr);
bsr.status = API_RETURN_CODE_OK;
return epee::serialization::store_t_to_json(bsr);
}
std::string plain_wallet_api_impl::get_sync_status()
{
m_wallet->get_sync_progress();
sync_status_response ssr = AUTO_VAL_INIT(ssr);
ssr.finished = m_sync_finished;
ssr.progress = m_wallet->get_sync_progress();
return epee::serialization::store_t_to_json(ssr);
}
std::string plain_wallet_api_impl::sync()
{
m_wallet->refresh(m_stop);
basic_status_response bsr = AUTO_VAL_INIT(bsr);
try
{
m_wallet->refresh(m_stop);
}
catch (const std::exception& e)
{
LOG_ERROR("Wallet refresh failed: " << e.what());
bsr.status = API_RETURN_CODE_FAIL;
return epee::serialization::store_t_to_json(bsr);
}
bsr.status = API_RETURN_CODE_OK;
return epee::serialization::store_t_to_json(bsr);
}
std::string plain_wallet_api_impl::invoke(const std::string& params)
{
m_rpc_wrapper->handle_http_request_map()
epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info);
epee::net_utils::http::http_response_info response_info = AUTO_VAL_INIT(response_info);
epee::net_utils::connection_context_base stub_conn_context = AUTO_VAL_INIT(stub_conn_context);
std::string reference_stub;
bool call_found = false;
query_info.m_body = params;
m_rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found, reference_stub);
return response_info.m_body;
}
}

View file

@ -16,12 +16,13 @@ namespace plain_wallet
{
public:
plain_wallet_api_impl(const std::string ip, const std::string port);
~plain_wallet_api_impl();
std::string open(const std::string& path, const std::string password);
std::string restore(const std::string& seed, const std::string& path, const std::string password);
std::string generate(const std::string& path, const std::string password);
bool start_sync_thread();
bool cancel_sync_thread();
std::string start_sync_thread();
std::string cancel_sync_thread();
std::string get_sync_status();
std::string sync();

View file

@ -15,7 +15,7 @@ namespace tools
{
wi = AUTO_VAL_INIT_T(view::wallet_info);
wi.address = w.get_account().get_public_address_str();
wi.tracking_hey = string_tools::pod_to_hex(w.get_account().get_keys().m_view_secret_key);
wi.tracking_hey = epee::string_tools::pod_to_hex(w.get_account().get_keys().m_view_secret_key);
uint64_t fake = 0;
wi.balance = w.balance(wi.unlocked_balance, fake, fake, wi.mined_total);
wi.path = epee::string_encoding::wstring_to_utf8(w.get_wallet_path());