forked from lthn/blockchain
fixed bug with unknown wallet
This commit is contained in:
parent
3284ca95c4
commit
83f42ef10f
3 changed files with 83 additions and 21 deletions
|
|
@ -219,7 +219,7 @@ namespace plain_wallet
|
|||
std::function<void()> async_callback;
|
||||
|
||||
uint64_t job_id = gjobs_counter++;
|
||||
if (method_name == "close_wallet")
|
||||
if (method_name == "close")
|
||||
{
|
||||
async_callback = [job_id, instance_id]()
|
||||
{
|
||||
|
|
@ -261,18 +261,28 @@ namespace plain_wallet
|
|||
}
|
||||
else if (method_name == "invoke")
|
||||
{
|
||||
std::string local_params = params;
|
||||
std::string local_params = params;
|
||||
async_callback = [job_id, local_params, instance_id]()
|
||||
{
|
||||
std::string res = invoke(instance_id, local_params);
|
||||
put_result(job_id, res);
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
view::api_response ar = AUTO_VAL_INIT(ar);
|
||||
ar.error_code = "UNKNOWN METHOD";
|
||||
put_result(job_id, epee::serialization::store_t_to_json(ar));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::thread t([async_callback]() {async_callback(); });
|
||||
t.detach();
|
||||
LOG_PRINT_L0("[ASYNC_CALL]: started " << method_name << ", job id: " << job_id);
|
||||
return std::string("{ \"job_id\": ") + std::to_string(job_id) + "}";
|
||||
}
|
||||
|
||||
std::string try_pull_result(uint64_t job_id)
|
||||
{
|
||||
//TODO: need refactoring
|
||||
|
|
|
|||
|
|
@ -68,11 +68,11 @@ int main(int argc, char* argv[])
|
|||
currency::get_block_reward(false, 500000, 589313, 10300000000000000, reward, 11030);
|
||||
|
||||
//set up logging options
|
||||
log_space::get_set_log_detalisation_level(true, LOG_LEVEL_1);
|
||||
log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
|
||||
log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
log_space::log_singletone::get_default_log_file().c_str(),
|
||||
log_space::log_singletone::get_default_log_folder().c_str());
|
||||
//log_space::get_set_log_detalisation_level(true, LOG_LEVEL_1);
|
||||
//log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL, LOG_LEVEL_2);
|
||||
//log_space::log_singletone::add_logger(LOGGER_FILE,
|
||||
// log_space::log_singletone::get_default_log_file().c_str(),
|
||||
// log_space::log_singletone::get_default_log_folder().c_str());
|
||||
|
||||
|
||||
po::options_description desc_options("Allowed options");
|
||||
|
|
|
|||
|
|
@ -16,6 +16,17 @@ using namespace epee;
|
|||
#include "wallet/plain_wallet_api_defs.h"
|
||||
|
||||
|
||||
struct try_pull_result_open_response
|
||||
{
|
||||
bool delivered;
|
||||
epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> result;
|
||||
BEGIN_KV_SERIALIZE_MAP()
|
||||
KV_SERIALIZE(delivered)
|
||||
KV_SERIALIZE(result)
|
||||
END_KV_SERIALIZE_MAP()
|
||||
};
|
||||
|
||||
|
||||
void run_plain_wallet_api_test()
|
||||
{
|
||||
LOG_PRINT_L0("Creating instance...");
|
||||
|
|
@ -25,31 +36,72 @@ void run_plain_wallet_api_test()
|
|||
view::open_wallet_request owr = AUTO_VAL_INIT(owr);
|
||||
owr.path = "E:\\tmp\\zano_testwallet_745ss65030.zan";
|
||||
owr.pass = "";
|
||||
uint64_t job_id = plain_wallet::async_call("open", 0, epee::serialization::store_t_to_json(owr));
|
||||
std::string job_id_str = plain_wallet::async_call("open", 0, epee::serialization::store_t_to_json(owr));
|
||||
|
||||
|
||||
try_pull_result_open_response rsp = AUTO_VAL_INIT(rsp);
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string res = plain_wallet::try_pull_result(job_id);
|
||||
std::string res = plain_wallet::try_pull_result(1);
|
||||
LOG_PRINT_L0("[try_pull_result] RESPONSE:" << ENDL << res);
|
||||
|
||||
if (!epee::serialization::load_t_from_json(rsp, res))
|
||||
{
|
||||
LOG_ERROR("Failed to parse try_pull_result response: " << res);
|
||||
return;
|
||||
}
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
if(!rsp.delivered)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//std::string rsp = plain_wallet::open(std::string("E:\\tmp\\zano_testwallet_745ss65030.zan"), "");
|
||||
//LOG_PRINT_L0("RESPONSE:" << ENDL << rsp);
|
||||
//epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
|
||||
//epee::serialization::load_t_from_json(ok_response, rsp);
|
||||
|
||||
size_t count = 0;
|
||||
while (count < 10)
|
||||
{
|
||||
std::string prog = plain_wallet::get_wallet_status(rsp.result.result.wallet_id);
|
||||
LOG_PRINT_L0("Progress: " << ENDL << prog);
|
||||
view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi);
|
||||
if (!epee::serialization::load_t_from_json(wsi, prog))
|
||||
{
|
||||
LOG_ERROR("Failed to get_wallet_status()");
|
||||
return;
|
||||
}
|
||||
if (!wsi.is_in_long_refresh)
|
||||
break;
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
}
|
||||
|
||||
std::string rsp = plain_wallet::open(std::string("E:\\tmp\\zano_testwallet_745ss65030.zan"), "");
|
||||
LOG_PRINT_L0("RESPONSE:" << ENDL << rsp);
|
||||
epee::json_rpc::response<view::open_wallet_response, epee::json_rpc::dummy_error> ok_response = AUTO_VAL_INIT(ok_response);
|
||||
epee::serialization::load_t_from_json(ok_response, rsp);
|
||||
|
||||
std::string job_id_str2 = plain_wallet::async_call("close", rsp.result.result.wallet_id, "");
|
||||
try_pull_result_open_response rsp2 = AUTO_VAL_INIT(rsp2);
|
||||
|
||||
while (true)
|
||||
{
|
||||
std::string prog = plain_wallet::get_wallet_status(ok_response.result.wallet_id);
|
||||
LOG_PRINT_L0("Progress: " << ENDL << prog);
|
||||
// view::sta ssr = AUTO_VAL_INIT(ssr);
|
||||
// epee::serialization::load_t_from_json(ssr, prog);
|
||||
// LOG_PRINT_L0("Progress: " << ssr.progress << "Finished: " << ssr.finished);
|
||||
// if (ssr.finished)
|
||||
// break;
|
||||
std::string res = plain_wallet::try_pull_result(2);
|
||||
LOG_PRINT_L0("[try_pull_result] RESPONSE:" << ENDL << res);
|
||||
|
||||
if (!epee::serialization::load_t_from_json(rsp2, res))
|
||||
{
|
||||
LOG_ERROR("Failed to parse try_pull_result response: " << res);
|
||||
return;
|
||||
}
|
||||
epee::misc_utils::sleep_no_w(1000);
|
||||
if (!rsp2.delivered)
|
||||
continue;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
LOG_PRINT_L0("OK");
|
||||
|
||||
}
|
||||
|
||||
// LOG_PRINT_L0("Creating instance..." << std::hex << hw);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue