From 982543da42200145f09e0b9eb8e568f09cc7d30e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 27 Nov 2020 17:18:35 +0100 Subject: [PATCH 1/3] fixed bug in getwallet_restore_info --- src/wallet/wallet_rpc_server.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index dda68d94..fef4f1a4 100644 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -215,7 +215,7 @@ namespace tools { try { - res.seed_phrase = m_wallet.get_account().get_seed_phrase(res.seed_phrase); + res.seed_phrase = m_wallet.get_account().get_seed_phrase(req.seed_password); return true; } catch (std::exception& e) From 55f3b9e185aa942cb05e9e3974ecfe396d3bb495 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 4 Dec 2020 21:34:08 +0100 Subject: [PATCH 2/3] refactoring plain api: added sync_call method --- src/wallet/plain_wallet_api.cpp | 71 ++++++++++++++++----------------- src/wallet/plain_wallet_api.h | 1 + 2 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index e7984ee7..f77c86d5 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -484,21 +484,35 @@ namespace plain_wallet LOG_PRINT_L2("[ASYNC_CALL]: Finished(result put), job id: " << job_id); } + std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params) { GET_INSTANCE_PTR(inst_ptr); std::function async_callback; uint64_t job_id = inst_ptr->gjobs_counter++; + async_callback = [job_id, instance_id, method_name, params]() + { + std::string res_str = sync_call(method_name, instance_id, params); + put_result(job_id, res_str); + }; + + std::thread t([async_callback]() {async_callback(); }); + t.detach(); + LOG_PRINT_L2("[ASYNC_CALL]: started " << method_name << ", job id: " << job_id); + return std::string("{ \"job_id\": ") + std::to_string(job_id) + "}"; + } + + + std::string sync_call(const std::string& method_name, uint64_t instance_id, const std::string& params) + { + std::string res; if (method_name == "close") { - async_callback = [job_id, instance_id]() - { close_wallet(instance_id); view::api_responce_return_code rc = AUTO_VAL_INIT(rc); rc.return_code = API_RETURN_CODE_OK; - put_result(job_id, epee::serialization::store_t_to_json(rc)); - }; + res = epee::serialization::store_t_to_json(rc); } else if (method_name == "open") { @@ -507,13 +521,11 @@ namespace plain_wallet { view::api_response ar = AUTO_VAL_INIT(ar); ar.error_code = "Wrong parameter"; - put_result(job_id, epee::serialization::store_t_to_json(ar)); - } - async_callback = [job_id, owr]() + res = epee::serialization::store_t_to_json(ar); + }else { - std::string res = open(owr.path, owr.pass); - put_result(job_id, res); - }; + res = open(owr.path, owr.pass); + } } else if (method_name == "restore") { @@ -522,46 +534,33 @@ namespace plain_wallet { view::api_response ar = AUTO_VAL_INIT(ar); ar.error_code = "Wrong parameter"; - put_result(job_id, epee::serialization::store_t_to_json(ar)); + res = epee::serialization::store_t_to_json(ar); } - async_callback = [job_id, rwr]() + else { - std::string res = restore(rwr.seed_phrase, rwr.path, rwr.pass, rwr.seed_pass); - put_result(job_id, res); - }; + res = restore(rwr.seed_phrase, rwr.path, rwr.pass, rwr.seed_pass); + } } else if (method_name == "invoke") { - 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); - }; + res = invoke(instance_id, params); } else if (method_name == "get_wallet_status") { - std::string local_params = params; - async_callback = [job_id, local_params, instance_id]() - { - std::string res = get_wallet_status(instance_id); - put_result(job_id, res); - }; - }else + res = get_wallet_status(instance_id); + } + 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::string("{ \"job_id\": ") + std::to_string(job_id) + "}";; + res = epee::serialization::store_t_to_json(ar); } - - - std::thread t([async_callback]() {async_callback(); }); - t.detach(); - LOG_PRINT_L2("[ASYNC_CALL]: started " << method_name << ", job id: " << job_id); - return std::string("{ \"job_id\": ") + std::to_string(job_id) + "}"; + return res; } + + + std::string try_pull_result(uint64_t job_id) { auto inst_ptr = std::atomic_load(&ginstance_ptr); diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 4b92939d..40873070 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -38,4 +38,5 @@ namespace plain_wallet //async api std::string async_call(const std::string& method_name, uint64_t instance_id, const std::string& params); std::string try_pull_result(uint64_t); + std::string sync_call(const std::string& method_name, uint64_t instance_id, const std::string& params); } \ No newline at end of file From c810f1f9fb4cdcee993a947ac784748316f6044a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 4 Dec 2020 22:04:57 +0100 Subject: [PATCH 3/3] added method get_seed_phrase_info to sync_call function --- src/wallet/plain_wallet_api.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index f77c86d5..b7a91e8f 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -16,6 +16,7 @@ #include "common/base58.h" #include "common/config_encrypt_helper.h" #include "static_helpers.h" +#include "wallet_helpers.h" #define ANDROID_PACKAGE_NAME "com.zano_mobile" @@ -541,6 +542,22 @@ namespace plain_wallet res = restore(rwr.seed_phrase, rwr.path, rwr.pass, rwr.seed_pass); } } + else if (method_name == "get_seed_phrase_info") + { + view::seed_info_param sip = AUTO_VAL_INIT(sip); + if (!epee::serialization::load_t_from_json(sip, params)) + { + view::api_response ar = AUTO_VAL_INIT(ar); + ar.error_code = "Wrong parameter"; + res = epee::serialization::store_t_to_json(ar); + } + else + { + view::api_response_t rsp = AUTO_VAL_INIT(rsp); + rsp.error_code = tools::get_seed_phrase_info(sip.seed_phrase, sip.seed_password, rsp.response_data); + res = epee::serialization::store_t_to_json(rsp); + } + } else if (method_name == "invoke") { res = invoke(instance_id, params);