From c6dd8b1153b8f66aa82d6d32368d33677948cc58 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 01:14:28 +0100 Subject: [PATCH 01/44] massive changes to wallets_manager --- src/wallet/plain_wallet_api.cpp | 201 ++++++++++++++++++++------------ src/wallet/plain_wallet_api.h | 1 + src/wallet/view_iface.h | 2 + src/wallet/wallets_manager.cpp | 25 +++- src/wallet/wallets_manager.h | 7 +- 5 files changed, 158 insertions(+), 78 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 6cbde104..f575b508 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -8,36 +8,39 @@ #include "currency_core/currency_config.h" #include "version.h" #include "currency_core/currency_format_utils.h" -//#include "wallets_manager.h" +#include "wallets_manager.h" //TODO: global objects, need refactoring. Just temporary solution -std::map ginstances; -epee::critical_section ginstances_lock; -std::atomic gcounter(1); - std::atomic glogs_initialized(false); +// std::map ginstances; +// epee::critical_section ginstances_lock; +// std::atomic gcounter(1); +// std::atomic glogs_initialized(false); #define HOME_FOLDER "Documents" #define WALLETS_FOLDER_NAME "wallets" #define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND" - -#define GET_INSTANCE(var_name, instance_handle) plain_wallet_api_impl* var_name = nullptr;\ - CRITICAL_REGION_BEGIN(ginstances_lock);\ - auto it = ginstances.find(instance_handle);\ - if (it == ginstances.end())\ - {\ - LOG_ERROR("Internall error: attempt to get instance wallet with wrong id: " << instance_handle);\ - return GENERAL_INTERNAL_ERRROR_INSTANCE;\ - }\ - var_name = it->second;\ - CRITICAL_REGION_END(); +#define GENERAL_INTERNAL_ERRROR_INIT "Failed to intialize library" +// +// #define GET_INSTANCE(var_name, instance_handle) plain_wallet_api_impl* var_name = nullptr;\ +// CRITICAL_REGION_BEGIN(ginstances_lock);\ +// auto it = ginstances.find(instance_handle);\ +// if (it == ginstances.end())\ +// {\ +// LOG_ERROR("Internall error: attempt to get instance wallet with wrong id: " << instance_handle);\ +// return GENERAL_INTERNAL_ERRROR_INSTANCE;\ +// }\ +// var_name = it->second;\ +// CRITICAL_REGION_END(); //TODO: global object, subject to refactoring -//wallets_manager gwm; +wallets_manager gwm; namespace plain_wallet { + typedef epee::json_rpc::response error_response; + std::string get_bundle_root_dir() { char buffer[1000] = {0}; @@ -48,8 +51,6 @@ namespace plain_wallet std::string get_wallets_folder() { std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME; - boost::system::error_code ec; - boost::filesystem::create_directories(path, ec); return path; } @@ -58,6 +59,31 @@ namespace plain_wallet return currency::print_money(amount); } + std::string init(const std::string& ip, const std::string& port) + { + initialize_logs(); + std::string argss_1 = std::string("--remote-nodes=") + ip + ":" + port; + const char * args[] = {"", 0}; + args[1] = argss_1.c_str(); + if (!gwm.init(2, args, nullptr)) + { + LOG_ERROR("Failed to init wallets_manager"); + return GENERAL_INTERNAL_ERRROR_INIT; + } + + if(!gwm.start()) + { + LOG_ERROR("Failed to start wallets_manager"); + return GENERAL_INTERNAL_ERRROR_INIT; + } + + std::string wallet_folder = get_wallets_folder(); + boost::system::error_code ec; + boost::filesystem::create_directories(wallet_folder, ec); + + return API_RETURN_CODE_OK; + } + void initialize_logs() { std::string log_dir = get_bundle_root_dir(); @@ -67,7 +93,7 @@ namespace plain_wallet epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); - glogs_initialized = true; + //glogs_initialized = true; } std::string get_version() @@ -95,72 +121,101 @@ namespace plain_wallet hwallet create_instance(const std::string& ip, const std::string& port) { - if (!glogs_initialized) - initialize_logs(); - plain_wallet_api_impl* ptr = new plain_wallet_api_impl(ip, port); - hwallet new_h = gcounter++; - CRITICAL_REGION_BEGIN(ginstances_lock); - ginstances[new_h] = ptr; - CRITICAL_REGION_END(); - return new_h; +// plain_wallet_api_impl* ptr = new plain_wallet_api_impl(ip, port); +// hwallet new_h = gcounter++; +// CRITICAL_REGION_BEGIN(ginstances_lock); +// ginstances[new_h] = ptr; +// CRITICAL_REGION_END(); +// return new_h; } void destroy_instance(hwallet h) { - plain_wallet_api_impl* instance_ptr = nullptr; - CRITICAL_REGION_BEGIN(ginstances_lock); - auto it = ginstances.find(h); - if (it == ginstances.end()) +// plain_wallet_api_impl* instance_ptr = nullptr; +// CRITICAL_REGION_BEGIN(ginstances_lock); +// auto it = ginstances.find(h); +// if (it == ginstances.end()) +// { +// LOG_ERROR("Internal error: attempt to delete wallet with wrong instance id: " << h); +// } +// instance_ptr = it->second; +// ginstances.erase(it); +// CRITICAL_REGION_END(); +// delete instance_ptr; + } + std::string open(const std::string& path, const std::string& password) + { + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + std::string rsp = gwm.open_wallet(epee::string_encoding::convert_to_unicode(path), password, 20, ok_response.result); + if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) { - LOG_ERROR("Internall error: attempt to delete wallet with wrong instance id: " << h); + if (rsp == API_RETURN_CODE_FILE_RESTORED) + { + ok_response.result.recovered = true; + } + return epee::serialization::store_t_to_json(ok_response); } - instance_ptr = it->second; - ginstances.erase(it); - CRITICAL_REGION_END(); - delete instance_ptr; + error_response err_result = AUTO_VAL_INIT(err_result); + err_result.error.code = rsp; + return epee::serialization::store_t_to_json(err_result); } - std::string open(hwallet h, const std::string& path, const std::string& password) + std::string restore(const std::string& seed, const std::string& path, const std::string& password) { - GET_INSTANCE(pimpl, h); - std::string full_path = get_wallets_folder() + "/" + path; - return pimpl->open(full_path, password); - } - std::string restore(hwallet h, const std::string& seed, const std::string& path, const std::string& password) - { - GET_INSTANCE(pimpl, h); - std::string full_path = get_wallets_folder() + "/" + path; - return pimpl->restore(seed, full_path, password); + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + std::string rsp = gwm.restore_wallet(epee::string_encoding::convert_to_unicode(path), password, seed, ok_response.result); + if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) + { + if (rsp == API_RETURN_CODE_FILE_RESTORED) + { + ok_response.result.recovered = true; + } + return epee::serialization::store_t_to_json(ok_response); + } + error_response err_result = AUTO_VAL_INIT(err_result); + err_result.error.code = rsp; + return epee::serialization::store_t_to_json(err_result); } + std::string generate(hwallet h, const std::string& path, const std::string& password) { - GET_INSTANCE(pimpl, h); - std::string full_path = get_wallets_folder() + "/" + path; - return pimpl->generate(full_path, password); - } - std::string start_sync_thread(hwallet h) - { - GET_INSTANCE(pimpl, h); - pimpl->start_sync_thread(); - return ""; - } - std::string get_sync_status(hwallet h) - { - GET_INSTANCE(pimpl, h); - return pimpl->get_sync_status(); - } - - std::string cancel_sync_thread(hwallet h) - { - GET_INSTANCE(pimpl, h); - return pimpl->cancel_sync_thread(); - } - - std::string sync(hwallet h) - { - GET_INSTANCE(pimpl, h); - return pimpl->sync(); + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + std::string rsp = gwm.generate_wallet(epee::string_encoding::convert_to_unicode(path), password, ok_response.result); + if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) + { + if (rsp == API_RETURN_CODE_FILE_RESTORED) + { + ok_response.result.recovered = true; + } + return epee::serialization::store_t_to_json(ok_response); + } + error_response err_result = AUTO_VAL_INIT(err_result); + err_result.error.code = rsp; + return epee::serialization::store_t_to_json(err_result); } +// std::string start_sync_thread(hwallet h) +// { +// GET_INSTANCE(pimpl, h); +// pimpl->start_sync_thread(); +// return ""; +// } +// std::string get_sync_status(hwallet h) +// { +// GET_INSTANCE(pimpl, h); +// return pimpl->get_sync_status(); +// } +// +// std::string cancel_sync_thread(hwallet h) +// { +// GET_INSTANCE(pimpl, h); +// return pimpl->cancel_sync_thread(); +// } +// +// std::string sync(hwallet h) +// { +// GET_INSTANCE(pimpl, h); +// return pimpl->sync(); +// } std::string invoke(hwallet h, const std::string& params) { GET_INSTANCE(pimpl, h); diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 42e70362..28701596 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -12,6 +12,7 @@ namespace plain_wallet typedef int64_t hwallet; hwallet create_instance(const std::string& ip, const std::string& port); void destroy_instance(hwallet h); + std::string init(const std::string& ip, const std::string& port); std::string get_version(); std::string get_wallet_files(); std::string print_money(int64_t); diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index 2b814adc..a15b5713 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -424,11 +424,13 @@ public: uint64_t wallet_id; transfers_array recent_history; wallet_info wi; + bool recovered; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(wallet_id) KV_SERIALIZE(recent_history) KV_SERIALIZE(wi) + KV_SERIALIZE(recovered) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 30b16176..479d7758 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -10,7 +10,8 @@ #include "string_coding.h" #include "currency_core/core_tools.h" #include "common/callstack_helper.h" -#include "wallet/wallet_helpers.h" +#include "wallet_helpers.h" +#include "core_default_rpc_proxy.h" #define GET_WALLET_OPT_BY_ID(wallet_id, name) \ CRITICAL_REGION_LOCAL(m_wallets_lock); \ @@ -76,7 +77,7 @@ void terminate_handler_func() std::abort(); // default terminate handler's behavior } -bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) +bool wallets_manager::init(int argc, const char* argv[], view::i_view* pview_handler) { m_stop_singal_sent = false; if (pview_handler) @@ -218,7 +219,8 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) if (command_line::has_arg(m_vm, arg_remote_node)) { - // configure for remote node + m_rpc_proxy.reset(new tools::default_http_core_proxy()); + m_rpc_proxy->set_connection_addr(command_line::get_arg(m_vm, arg_remote_node)); } m_qt_logs_enbaled = command_line::get_arg(m_vm, arg_enable_qt_logs); @@ -565,6 +567,7 @@ void wallets_manager::init_wallet_entry(wallet_vs_options& wo, uint64_t id) wo.plast_daemon_is_disconnected = &m_last_daemon_is_disconnected; wo.pview = m_pview; wo.has_related_alias_in_unconfirmed = false; + wo.rpc_wrapper.reset(new tools::wallet_rpc_server(*wo.w.unlocked_get().get())); if (m_remote_node_mode) wo.core_conf = currency::get_default_core_runtime_config(); else @@ -1128,6 +1131,22 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par return API_RETURN_CODE_OK; } +std::string wallets_manager::invoke(uint64_t wallet_id, std::string params) +{ + GET_WALLET_OPT_BY_ID(wallet_id, wo); + auto locker_object = wo.w.lock(); + + 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_URI = "/json_rpc"; + query_info.m_body = params; + wo.rpc_wrapper->handle_http_request_map(query_info, response_info, stub_conn_context, call_found, reference_stub); + return response_info.m_body; +} + std::string wallets_manager::get_wallet_info(size_t wallet_id, view::wallet_info& wi) { GET_WALLET_OPT_BY_ID(wallet_id, w); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index d3d39c7a..e2dc1cef 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -27,8 +27,9 @@ using namespace epee; //#include "common/miniupnp_helper.h" #include "view_iface.h" #include "core_fast_rpc_proxy.h" -#include "wallet/wallet2.h" +#include "wallet2.h" #include "wallet_id_adapter.h" +#include "wallet_rpc_server.h" POP_VS_WARNINGS @@ -55,6 +56,7 @@ public: { currency::core_runtime_config core_conf; epee::locked_object, wallet_lock_time_watching_policy> w; + std::shared_ptr rpc_wrapper; //500 bytes of extra data, we can afford it, to have rpc-like invoke map std::atomic do_mining; std::atomic major_stop; std::atomic stop_for_refresh; //use separate var for passing to "refresh" member function, @@ -80,13 +82,14 @@ public: wallets_manager(); ~wallets_manager(); - bool init(int argc, char* argv[], view::i_view* pview_handler); + bool init(int argc, const char* argv[], view::i_view* pview_handler); bool start(); bool stop(); bool send_stop_signal(); std::string open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr); std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr); std::string restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr); + std::string invoke(uint64_t wallet_id, std::string params); std::string run_wallet(uint64_t wallet_id); std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist); std::string get_wallet_info(size_t wallet_id, view::wallet_info& wi); From 1c35304d0b175608f2cce5e66aa96c8b8645b0fe Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 03:10:27 +0100 Subject: [PATCH 02/44] introduced new long-call mode for wallets_manager --- src/wallet/plain_wallet_api.cpp | 7 +++++-- src/wallet/plain_wallet_api.h | 11 ++++++----- src/wallet/view_iface.h | 1 + src/wallet/wallets_manager.cpp | 23 +++++++++++++++++++++++ src/wallet/wallets_manager.h | 4 ++++ 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index f575b508..72c5e8a8 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -216,9 +216,12 @@ namespace plain_wallet // GET_INSTANCE(pimpl, h); // return pimpl->sync(); // } + std::string get_wallet_status(hwallet h) + { + + } std::string invoke(hwallet h, const std::string& params) { - GET_INSTANCE(pimpl, h); - return pimpl->invoke(params); + return gwm.invoke(h, params); } } \ No newline at end of file diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 28701596..cfab17fd 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -15,15 +15,16 @@ namespace plain_wallet std::string init(const std::string& ip, const std::string& port); std::string get_version(); std::string get_wallet_files(); - std::string print_money(int64_t); + //std::string print_money(int64_t); std::string open(hwallet h, const std::string& path, const std::string& password); std::string restore(hwallet h, const std::string& seed, const std::string& path, const std::string& password); std::string generate(hwallet h, const std::string& path, const std::string& password); - std::string start_sync_thread(hwallet h); - std::string get_sync_status(hwallet h); - std::string cancel_sync_thread(hwallet h); - std::string sync(hwallet h); +// std::string start_sync_thread(hwallet h); +// std::string get_sync_status(hwallet h); +// std::string cancel_sync_thread(hwallet h); +// std::string sync(hwallet h); + std::string get_wallet_status(hwallet h); std::string invoke(hwallet h, const std::string& params); } \ No newline at end of file diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index a15b5713..c25cabd9 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -747,6 +747,7 @@ public: #define API_RETURN_CODE_FALSE "FALSE" #define API_RETURN_CODE_CORE_BUSY "CORE_BUSY" #define API_RETURN_CODE_OVERFLOW "OVERFLOW" +#define API_RETURN_CODE_BUSY "BUSY" #define API_MAX_ALIASES_COUNT 10000 diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 479d7758..bad50e13 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1131,9 +1131,24 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par return API_RETURN_CODE_OK; } +std::string wallets_manager::get_wallet_status(uint64_t wallet_id) +{ + +} std::string wallets_manager::invoke(uint64_t wallet_id, std::string params) { GET_WALLET_OPT_BY_ID(wallet_id, wo); + + CRITICAL_REGION_LOCAL(wo.long_refresh_in_progress_lock); + if (wo.long_refresh_in_progress) + { + epee::json_rpc::response error_response = AUTO_VAL_INIT(error_response); + error_response.error.code = -1; + error_response.error.message = API_RETURN_CODE_BUSY; + return epee::serialization::store_t_to_json(error_response); + } + + auto locker_object = wo.w.lock(); epee::net_utils::http::http_request_info query_info = AUTO_VAL_INIT(query_info); @@ -1542,6 +1557,13 @@ void wallets_manager::wallet_vs_options::worker_func() if (last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height < 3) show_progress = false; + if(last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height > 10) + { + CRITICAL_REGION_LOCAL(long_refresh_in_progress_lock); + long_refresh_in_progress = true; + } + + if (show_progress) { wallet_state = wsi.wallet_state = view::wallet_status_info::wallet_state_synchronizing; @@ -1549,6 +1571,7 @@ void wallets_manager::wallet_vs_options::worker_func() pview->update_wallet_status(wsi); } w->get()->refresh(stop_for_refresh); + long_refresh_in_progress = false; w->get()->resend_unconfirmed(); { auto w_ptr = *w; // get locked exclusive access to the wallet first (it's more likely that wallet is locked for a long time than 'offers') diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index e2dc1cef..9bb661d2 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -70,6 +70,10 @@ public: std::atomic* plast_daemon_is_disconnected; std::atomic has_related_alias_in_unconfirmed; std::atomic need_to_update_wallet_info; + + std::atomic long_refresh_in_progress; + epee::critical_section long_refresh_in_progress_lock; //secure wallet state and prevent from long wait while long refresh is in work + view::i_view* pview; uint64_t wallet_id; epee::locked_object> offers; From 88a657cbb784414eb5a700b0923ce74ba0dc31f9 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 03:46:47 +0100 Subject: [PATCH 03/44] fixed bugs and code clean up --- src/wallet/plain_wallet_api.cpp | 48 +++++++-------------------------- src/wallet/plain_wallet_api.h | 11 +++----- src/wallet/view_iface.h | 13 +++++++++ src/wallet/wallets_manager.cpp | 10 +++++-- src/wallet/wallets_manager.h | 1 + 5 files changed, 35 insertions(+), 48 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 72c5e8a8..94a6b470 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -54,9 +54,16 @@ namespace plain_wallet return path; } - std::string print_money(int64_t amount) + void initialize_logs() { - return currency::print_money(amount); + std::string log_dir = get_bundle_root_dir(); + log_dir += "/" HOME_FOLDER; + epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); + epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); + epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); + LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); + + //glogs_initialized = true; } std::string init(const std::string& ip, const std::string& port) @@ -84,17 +91,7 @@ namespace plain_wallet return API_RETURN_CODE_OK; } - void initialize_logs() - { - std::string log_dir = get_bundle_root_dir(); - log_dir += "/" HOME_FOLDER; - epee::log_space::get_set_log_detalisation_level(true, LOG_LEVEL_2); - epee::log_space::log_singletone::add_logger(LOGGER_CONSOLE, NULL, NULL); - epee::log_space::log_singletone::add_logger(LOGGER_FILE, "plain_wallet.log", log_dir.c_str()); - LOG_PRINT_L0("Plain wallet initialized: " << CURRENCY_NAME << " v" << PROJECT_VERSION_LONG << ", log location: " << log_dir + "/plain_wallet.log"); - //glogs_initialized = true; - } std::string get_version() { @@ -119,31 +116,6 @@ namespace plain_wallet return epee::serialization::store_t_to_json(sl); } - hwallet create_instance(const std::string& ip, const std::string& port) - { - -// plain_wallet_api_impl* ptr = new plain_wallet_api_impl(ip, port); -// hwallet new_h = gcounter++; -// CRITICAL_REGION_BEGIN(ginstances_lock); -// ginstances[new_h] = ptr; -// CRITICAL_REGION_END(); -// return new_h; - } - - void destroy_instance(hwallet h) - { -// plain_wallet_api_impl* instance_ptr = nullptr; -// CRITICAL_REGION_BEGIN(ginstances_lock); -// auto it = ginstances.find(h); -// if (it == ginstances.end()) -// { -// LOG_ERROR("Internal error: attempt to delete wallet with wrong instance id: " << h); -// } -// instance_ptr = it->second; -// ginstances.erase(it); -// CRITICAL_REGION_END(); -// delete instance_ptr; - } std::string open(const std::string& path, const std::string& password) { epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); @@ -218,7 +190,7 @@ namespace plain_wallet // } std::string get_wallet_status(hwallet h) { - + return gwm.get_wallet_status(h); } std::string invoke(hwallet h, const std::string& params) { diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index cfab17fd..4b42c948 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -15,16 +15,11 @@ namespace plain_wallet std::string init(const std::string& ip, const std::string& port); std::string get_version(); std::string get_wallet_files(); - //std::string print_money(int64_t); - std::string open(hwallet h, const std::string& path, const std::string& password); - std::string restore(hwallet h, const std::string& seed, const std::string& path, const std::string& password); - std::string generate(hwallet h, const std::string& path, const std::string& password); + 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); -// std::string start_sync_thread(hwallet h); -// std::string get_sync_status(hwallet h); -// std::string cancel_sync_thread(hwallet h); -// std::string sync(hwallet h); std::string get_wallet_status(hwallet h); std::string invoke(hwallet h, const std::string& params); } \ No newline at end of file diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index c25cabd9..ccdfe1e6 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -520,6 +520,19 @@ public: END_KV_SERIALIZE_MAP() }; + struct wallet_sync_status_info + { + uint64_t wallet_state; + bool is_in_long_refresh; + uint64_t progress; + + BEGIN_KV_SERIALIZE_MAP() + KV_SERIALIZE(wallet_state) + KV_SERIALIZE(is_in_long_refresh) + KV_SERIALIZE(progress) + END_KV_SERIALIZE_MAP() + }; + struct get_restore_info_response { std::string restore_key; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index bad50e13..1b9a3f6f 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1133,13 +1133,19 @@ std::string wallets_manager::transfer(size_t wallet_id, const view::transfer_par std::string wallets_manager::get_wallet_status(uint64_t wallet_id) { - + GET_WALLET_OPT_BY_ID(wallet_id, wo); + view::wallet_sync_status_info wsi = AUTO_VAL_INIT(wsi); + wsi.is_in_long_refresh = wo.long_refresh_in_progress; + wsi.progress = wo.w.unlocked_get().get()->get_sync_progress(); + wsi.wallet_state = wo.wallet_state; + return epee::serialization::store_t_to_json(wsi); } + std::string wallets_manager::invoke(uint64_t wallet_id, std::string params) { GET_WALLET_OPT_BY_ID(wallet_id, wo); - CRITICAL_REGION_LOCAL(wo.long_refresh_in_progress_lock); + CRITICAL_REGION_LOCAL1(wo.long_refresh_in_progress_lock); if (wo.long_refresh_in_progress) { epee::json_rpc::response error_response = AUTO_VAL_INIT(error_response); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 9bb661d2..0e3e8e27 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -94,6 +94,7 @@ public: std::string generate_wallet(const std::wstring& path, const std::string& password, view::open_wallet_response& owr); std::string restore_wallet(const std::wstring& path, const std::string& password, const std::string& restore_key, view::open_wallet_response& owr); std::string invoke(uint64_t wallet_id, std::string params); + std::string get_wallet_status(uint64_t wallet_id); std::string run_wallet(uint64_t wallet_id); std::string get_recent_transfers(size_t wallet_id, uint64_t offset, uint64_t count, view::transfers_array& tr_hist); std::string get_wallet_info(size_t wallet_id, view::wallet_info& wi); From 29945bfd1534d2467f1453f2457bb5c4f15888f5 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 04:07:32 +0100 Subject: [PATCH 04/44] fixed wallets_manager init signature --- src/wallet/plain_wallet_api.cpp | 4 ++-- src/wallet/wallets_manager.cpp | 2 +- src/wallet/wallets_manager.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 94a6b470..931e7a86 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -70,8 +70,8 @@ namespace plain_wallet { initialize_logs(); std::string argss_1 = std::string("--remote-nodes=") + ip + ":" + port; - const char * args[] = {"", 0}; - args[1] = argss_1.c_str(); + char * args[] = {"", 0}; + args[1] = const_cast(argss_1.c_str()); if (!gwm.init(2, args, nullptr)) { LOG_ERROR("Failed to init wallets_manager"); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 1b9a3f6f..f84184bb 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -77,7 +77,7 @@ void terminate_handler_func() std::abort(); // default terminate handler's behavior } -bool wallets_manager::init(int argc, const char* argv[], view::i_view* pview_handler) +bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) { m_stop_singal_sent = false; if (pview_handler) diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 0e3e8e27..d04c61e6 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -86,7 +86,7 @@ public: wallets_manager(); ~wallets_manager(); - bool init(int argc, const char* argv[], view::i_view* pview_handler); + bool init(int argc, char* argv[], view::i_view* pview_handler); bool start(); bool stop(); bool send_stop_signal(); From 056d77d9c3aed331e0c0c51e60b558f308a272dd Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 17:06:14 +0100 Subject: [PATCH 05/44] added close wallet to plain wallet --- src/wallet/plain_wallet_api.cpp | 41 +++++---------------------------- src/wallet/plain_wallet_api.h | 3 +-- 2 files changed, 7 insertions(+), 37 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 931e7a86..6291aef2 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -21,18 +21,6 @@ #define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND" #define GENERAL_INTERNAL_ERRROR_INIT "Failed to intialize library" -// -// #define GET_INSTANCE(var_name, instance_handle) plain_wallet_api_impl* var_name = nullptr;\ -// CRITICAL_REGION_BEGIN(ginstances_lock);\ -// auto it = ginstances.find(instance_handle);\ -// if (it == ginstances.end())\ -// {\ -// LOG_ERROR("Internall error: attempt to get instance wallet with wrong id: " << instance_handle);\ -// return GENERAL_INTERNAL_ERRROR_INSTANCE;\ -// }\ -// var_name = it->second;\ -// CRITICAL_REGION_END(); - //TODO: global object, subject to refactoring wallets_manager gwm; @@ -165,29 +153,12 @@ namespace plain_wallet err_result.error.code = rsp; return epee::serialization::store_t_to_json(err_result); } -// std::string start_sync_thread(hwallet h) -// { -// GET_INSTANCE(pimpl, h); -// pimpl->start_sync_thread(); -// return ""; -// } -// std::string get_sync_status(hwallet h) -// { -// GET_INSTANCE(pimpl, h); -// return pimpl->get_sync_status(); -// } -// -// std::string cancel_sync_thread(hwallet h) -// { -// GET_INSTANCE(pimpl, h); -// return pimpl->cancel_sync_thread(); -// } -// -// std::string sync(hwallet h) -// { -// GET_INSTANCE(pimpl, h); -// return pimpl->sync(); -// } + + std::string close_wallet(hwallet h) + { + return gwm.close_wallet(h); + } + std::string get_wallet_status(hwallet h) { return gwm.get_wallet_status(h); diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 4b42c948..9c2e8fb0 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -10,8 +10,6 @@ namespace plain_wallet { typedef int64_t hwallet; - hwallet create_instance(const std::string& ip, const std::string& port); - void destroy_instance(hwallet h); std::string init(const std::string& ip, const std::string& port); std::string get_version(); std::string get_wallet_files(); @@ -21,5 +19,6 @@ namespace plain_wallet std::string generate(const std::string& path, const std::string& password); std::string get_wallet_status(hwallet h); + std::string close_wallet(hwallet h); std::string invoke(hwallet h, const std::string& params); } \ No newline at end of file From abd1d47aa3f5fc4fed4c7993ccaef61b53b26b0b Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 17:13:03 +0100 Subject: [PATCH 06/44] check for wrong initialization code on app level --- src/wallet/plain_wallet_api.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 6291aef2..2790692d 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -10,11 +10,7 @@ #include "currency_core/currency_format_utils.h" #include "wallets_manager.h" -//TODO: global objects, need refactoring. Just temporary solution -// std::map ginstances; -// epee::critical_section ginstances_lock; -// std::atomic gcounter(1); -// std::atomic glogs_initialized(false); +std::atomic initialized(false); #define HOME_FOLDER "Documents" #define WALLETS_FOLDER_NAME "wallets" @@ -56,6 +52,13 @@ namespace plain_wallet std::string init(const std::string& ip, const std::string& port) { + if (initialized) + { + LOG_ERROR("Double-initialization in plain_wallet detected."); + throw std::runtime_error("Double-initialization in plain_wallet detected."); + } + + initialize_logs(); std::string argss_1 = std::string("--remote-nodes=") + ip + ":" + port; char * args[] = {"", 0}; From c3296d4603f9cb39fbfa5684c0b74429ca348fd2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 23:12:31 +0100 Subject: [PATCH 07/44] put core and other heavy core-dependent code under conditional compilation --- src/wallet/wallets_manager.cpp | 42 ++++++++++++++++++++++++++++------ src/wallet/wallets_manager.h | 2 ++ 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index f84184bb..d00e1049 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -31,10 +31,12 @@ auto& name = it->second.w; wallets_manager::wallets_manager():m_pview(&m_view_stub), m_stop_singal_sent(false), +#ifndef IOS_BUILD m_ccore(&m_cprotocol), m_cprotocol(m_ccore, &m_p2psrv), m_p2psrv(m_cprotocol), m_rpc_server(m_ccore, m_p2psrv, m_offers_service), +#endif m_rpc_proxy(new tools::core_fast_rpc_proxy(m_rpc_server)), m_last_daemon_height(0), m_last_daemon_is_disconnected(false), @@ -288,6 +290,7 @@ std::string wallets_manager::get_config_folder() bool wallets_manager::init_local_daemon() { +#ifndef IOS_BUILD view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.pos_difficulty = dsi.pos_difficulty = "---"; dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_loading_core; @@ -356,12 +359,13 @@ bool wallets_manager::init_local_daemon() res = m_p2psrv.run(false); CHECK_AND_ASSERT_AND_SET_GUI(res, "Failed to run p2p loop."); LOG_PRINT_L0("p2p net loop stopped"); - +#endif return true; } bool wallets_manager::deinit_local_daemon() { +#ifndef IOS_BUILD view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_unloading_core; m_pview->update_daemon_status(dsi); @@ -417,7 +421,7 @@ bool wallets_manager::deinit_local_daemon() //dsi.text_state = "Deinitializing core"; m_pview->update_daemon_status(dsi); m_ccore.deinit(); - +#endif return true; } @@ -570,8 +574,15 @@ void wallets_manager::init_wallet_entry(wallet_vs_options& wo, uint64_t id) wo.rpc_wrapper.reset(new tools::wallet_rpc_server(*wo.w.unlocked_get().get())); if (m_remote_node_mode) wo.core_conf = currency::get_default_core_runtime_config(); - else + else + { +#ifndef IOS_BUILD wo.core_conf = m_ccore.get_blockchain_storage().get_core_runtime_config(); +#else + LOG_ERROR("Unexpected location reached"); +#endif + } + // update wallet log prefix for further usage { @@ -603,19 +614,22 @@ std::string wallets_manager::get_fav_offers(const std::list& offers) { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; - +#ifndef IOS_BUILD CRITICAL_REGION_LOCAL(m_wallets_lock); while (true) { @@ -657,6 +671,9 @@ std::string wallets_manager::get_my_offers(const bc_services::core_offers_filter LOG_PRINT("get_my_offers(): " << offers.size() << " offers returned (" << offers_count_before_filtering << " was before filter)", LOG_LEVEL_1); return API_RETURN_CODE_OK; +#else + return API_RETURN_CODE_FAIL; +#endif } std::string wallets_manager::open_wallet(const std::wstring& path, const std::string& password, uint64_t txs_to_return, view::open_wallet_response& owr) @@ -780,9 +797,12 @@ std::string wallets_manager::get_mining_estimate(uint64_t amuont_coins, { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; - +#ifndef IOS_BUILD m_ccore.get_blockchain_storage().get_pos_mining_estimate(amuont_coins, time, estimate_result, pos_coins_and_pos_diff_rate, days); return API_RETURN_CODE_OK; +#else + return API_RETURN_CODE_FAIL; +#endif } std::string wallets_manager::is_pos_allowed() @@ -802,8 +822,10 @@ std::string wallets_manager::is_valid_brain_restore_data(const std::string& brai } void wallets_manager::subscribe_to_core_events(currency::i_core_event_handler* pevents_handler) { +#ifndef IOS_BUILD if(!m_remote_node_mode) m_ccore.get_blockchain_storage().set_event_handler(pevents_handler); +#endif } void wallets_manager::get_gui_options(view::gui_options& opt) { @@ -883,6 +905,7 @@ std::string wallets_manager::get_aliases(view::alias_set& al_set) if (m_remote_node_mode) return API_RETURN_CODE_OVERFLOW; +#ifndef IOS_BUILD if (m_ccore.get_blockchain_storage().get_aliases_count() > API_MAX_ALIASES_COUNT) return API_RETURN_CODE_OVERFLOW; @@ -893,8 +916,9 @@ std::string wallets_manager::get_aliases(view::alias_set& al_set) al_set.aliases = aliases.aliases; return API_RETURN_CODE_OK; } - +#endif return API_RETURN_CODE_FAIL; + } std::string wallets_manager::get_alias_info_by_address(const std::string& addr, currency::alias_rpc_details& res_details) { @@ -1471,10 +1495,14 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; +#ifndef IOS_BUILD //TODO: make it proxy-like call //m_ccore.get_blockchain_storage().get_offers_ex(cof, offers, total_count); m_offers_service.get_offers_ex(cof, offers, total_count, m_ccore.get_blockchain_storage().get_core_runtime_config().get_core_time()); return API_RETURN_CODE_OK; +#else + return API_RETURN_CODE_FAIL; +#endif } diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index d04c61e6..f8238257 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -184,12 +184,14 @@ private: std::string m_data_dir; view::gui_options m_ui_opt; +#ifndef IOS_BUILD //daemon stuff bc_services::bc_offers_service m_offers_service; currency::core m_ccore; currency::t_currency_protocol_handler m_cprotocol; nodetool::node_server > m_p2psrv; currency::core_rpc_server m_rpc_server; +#endif bool m_remote_node_mode; bool m_qt_logs_enbaled; From b84949295bd44be6ec138ba87f2862b5d7288692 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 23:34:16 +0100 Subject: [PATCH 08/44] cut other core-related code from IOS_BUILD --- src/wallet/wallets_manager.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index d00e1049..a5d8f0bb 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -36,18 +36,23 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub), m_cprotocol(m_ccore, &m_p2psrv), m_p2psrv(m_cprotocol), m_rpc_server(m_ccore, m_p2psrv, m_offers_service), -#endif m_rpc_proxy(new tools::core_fast_rpc_proxy(m_rpc_server)), + m_offers_service(nullptr), +#else + m_rpc_proxy(new tools::default_http_core_proxy()), +#endif + m_last_daemon_height(0), m_last_daemon_is_disconnected(false), m_wallet_id_counter(0), - m_offers_service(nullptr), m_ui_opt(AUTO_VAL_INIT(m_ui_opt)), m_remote_node_mode(false), m_is_pos_allowed(false), m_qt_logs_enbaled(false) { +#ifndef IOS_BUILD m_offers_service.set_disabled(true); +#endif //m_ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&m_offers_service); } @@ -688,7 +693,11 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st } else { +#ifndef IOS_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); +#else + LOG_ERROR("Unexpected location reached"); +#endif } std::string return_code = API_RETURN_CODE_OK; @@ -763,7 +772,12 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std } else { +#ifndef IOS_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); +#else + LOG_ERROR("Unexpected location reached"); +#endif + } @@ -842,7 +856,12 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: } else { +#ifndef IOS_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); +#else + LOG_ERROR("Unexpected location reached"); +#endif + } currency::account_base acc; From 79902a2a165891911f2c3c38f2131f2e2ff2c41f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 23:51:35 +0100 Subject: [PATCH 09/44] surgery continued: cut headers --- src/wallet/wallets_manager.cpp | 8 +++++--- src/wallet/wallets_manager.h | 12 +++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index a5d8f0bb..4b318f7d 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -6,10 +6,12 @@ #include "wallets_manager.h" #include "currency_core/alias_helper.h" -#include "core_fast_rpc_proxy.h" -#include "string_coding.h" -#include "currency_core/core_tools.h" +#ifndef IOS_BUILD + #include "core_fast_rpc_proxy.h" + #include "currency_core/core_tools.h" +#endif #include "common/callstack_helper.h" +#include "string_coding.h" #include "wallet_helpers.h" #include "core_default_rpc_proxy.h" diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index f8238257..4f24848f 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -19,14 +19,16 @@ using namespace epee; #include "console_handler.h" #include "p2p/net_node.h" #include "currency_core/checkpoints_create.h" -#include "currency_core/currency_core.h" -#include "currency_core/bc_offers_service.h" -#include "rpc/core_rpc_server.h" -#include "currency_protocol/currency_protocol_handler.h" +#ifndef IOS_BUILD + #include "currency_core/currency_core.h" + #include "currency_core/bc_offers_service.h" + #include "rpc/core_rpc_server.h" + #include "currency_protocol/currency_protocol_handler.h" + #include "core_fast_rpc_proxy.h" +#endif #include "daemon/daemon_commands_handler.h" //#include "common/miniupnp_helper.h" #include "view_iface.h" -#include "core_fast_rpc_proxy.h" #include "wallet2.h" #include "wallet_id_adapter.h" #include "wallet_rpc_server.h" From fd14a990e038c3142a58a661d8f1bb9a987df912 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 11 Feb 2020 23:58:44 +0100 Subject: [PATCH 10/44] cut //#include daemon/daemon_commands_handler.h --- src/wallet/wallets_manager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 4f24848f..59ea9c5a 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -26,7 +26,7 @@ using namespace epee; #include "currency_protocol/currency_protocol_handler.h" #include "core_fast_rpc_proxy.h" #endif -#include "daemon/daemon_commands_handler.h" +//#include "daemon/daemon_commands_handler.h" //#include "common/miniupnp_helper.h" #include "view_iface.h" #include "wallet2.h" From 8865c0c270b517e5ecd4a8fb304287fb642bdfe5 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 00:10:31 +0100 Subject: [PATCH 11/44] why BOOST_CLASS_VERSION was there?? --- src/wallet/wallets_manager.h | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index 59ea9c5a..f8476851 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -41,8 +41,6 @@ namespace po = boost::program_options; #include #endif -//TODO: need refactoring here. (template classes can't be used in BOOST_CLASS_VERSION) -BOOST_CLASS_VERSION(nodetool::node_server >, CURRENT_P2P_STORAGE_ARCHIVE_VER); struct wallet_lock_time_watching_policy { From 545288f393f3b3f3d3d47d332be3a29abc490240 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 00:14:47 +0100 Subject: [PATCH 12/44] cut subscribe_to_core_events --- src/wallet/wallets_manager.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index f8476851..f9b6c47f 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -142,8 +142,10 @@ public: std::string transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx); std::string get_config_folder(); std::string is_valid_brain_restore_data(const std::string& brain_text); +#ifndef IOS_BUILD void subscribe_to_core_events(currency::i_core_event_handler* pevents_handler); - void unsubscribe_to_core_events(); + //void unsubscribe_to_core_events(); +#endif void get_gui_options(view::gui_options& opt); std::string get_wallet_log_prefix(size_t wallet_id) const; bool is_qt_logs_enabled() const { return m_qt_logs_enbaled; } From b43a09b6e4039c3d06184d22d4df6ffc5a6b5257 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 00:19:30 +0100 Subject: [PATCH 13/44] removed static init of core components from ios build --- src/wallet/wallets_manager.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 4b318f7d..2d137f66 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -139,12 +139,13 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) command_line::add_arg(desc_cmd_sett, arg_remote_node); command_line::add_arg(desc_cmd_sett, arg_enable_qt_logs); - +#ifndef IOS_BUILD currency::core::init_options(desc_cmd_sett); currency::core_rpc_server::init_options(desc_cmd_sett); nodetool::node_server >::init_options(desc_cmd_sett); currency::miner::init_options(desc_cmd_sett); bc_services::bc_offers_service::init_options(desc_cmd_sett); +#endif po::options_description desc_options("Allowed options"); desc_options.add(desc_cmd_only).add(desc_cmd_sett); @@ -836,13 +837,15 @@ std::string wallets_manager::is_valid_brain_restore_data(const std::string& brai else return API_RETURN_CODE_FALSE; } +#ifndef IOS_BUILD void wallets_manager::subscribe_to_core_events(currency::i_core_event_handler* pevents_handler) { -#ifndef IOS_BUILD + if(!m_remote_node_mode) m_ccore.get_blockchain_storage().set_event_handler(pevents_handler); -#endif + } +#endif void wallets_manager::get_gui_options(view::gui_options& opt) { opt = m_ui_opt; From 480c1a0bdc7f5992df4d9d57e98f3ed7c35d2a3d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 00:30:04 +0100 Subject: [PATCH 14/44] fixed param for generate --- src/wallet/plain_wallet_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 2790692d..713636e1 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -140,7 +140,7 @@ namespace plain_wallet return epee::serialization::store_t_to_json(err_result); } - std::string generate(hwallet h, const std::string& path, const std::string& password) + std::string generate(const std::string& path, const std::string& password) { epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); std::string rsp = gwm.generate_wallet(epee::string_encoding::convert_to_unicode(path), password, ok_response.result); From b931199386f86624609ba0a71c3f831fd9e97f42 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 20:36:54 +0100 Subject: [PATCH 15/44] fixed initialization --- src/wallet/plain_wallet_api.cpp | 10 +- src/wallet/wallets_manager.cpp | 2 +- .../core_concurrency_test.cpp | 2 +- tests/functional_tests/plain_wallet_tests.cpp | 278 +++++++++--------- 4 files changed, 149 insertions(+), 143 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 713636e1..3e261269 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -27,6 +27,10 @@ namespace plain_wallet std::string get_bundle_root_dir() { +#ifdef WIN32 + return "undefined"; +#endif // WIN32 + char buffer[1000] = {0}; strcpy(buffer, getenv("HOME")); return buffer; @@ -60,9 +64,11 @@ namespace plain_wallet initialize_logs(); - std::string argss_1 = std::string("--remote-nodes=") + ip + ":" + port; - char * args[] = {"", 0}; + std::string argss_1 = std::string("--remote-node=") + ip + ":" + port; + char * args[3]; + args[0] = "stub"; args[1] = const_cast(argss_1.c_str()); + args[2] = nullptr; if (!gwm.init(2, args, nullptr)) { LOG_ERROR("Failed to init wallets_manager"); diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 2d137f66..cb3ee4dc 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -94,7 +94,7 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.pos_difficulty = dsi.pow_difficulty = "---"; - pview_handler->update_daemon_status(dsi); + m_pview->update_daemon_status(dsi); log_space::get_set_log_detalisation_level(true, LOG_LEVEL_0); log_space::get_set_need_thread_id(true, true); diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index d72cf983..52ff1b8c 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -13,7 +13,7 @@ using namespace epee; #include "currency_core/currency_core.h" #include "rpc/core_rpc_server.h" -#include "gui/qt-daemon/application/core_fast_rpc_proxy.h" +#include "wallet/core_fast_rpc_proxy.h" #include "version.h" #include "common/command_line.h" #include "common/boost_serialization_helper.h" diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index c843c3fe..caf30eec 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -19,143 +19,143 @@ using namespace epee; void run_plain_wallet_api_test() { LOG_PRINT_L0("Creating instance..."); - plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211"); - LOG_PRINT_L0("Creating instance..." << std::hex << hw); - - LOG_PRINT_L0("Generating wallet..."); - std::string rsp = plain_wallet::open(hw, std::string("E:\\tmp\\zano_testwallet_74565030.zan"), ""); - LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); - epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); - epee::serialization::load_t_from_json(ok_response, rsp); - - plain_wallet::start_sync_thread(hw); - LOG_PRINT_L0("Started sync thread."); - - while (true) - { - std::string prog = plain_wallet::get_sync_status(hw); - plain_wallet::sync_status_response 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; - epee::misc_utils::sleep_no_w(1000); - } - LOG_PRINT_L0("Sync finished OK"); - - { - //request get wallet info: - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "get_wallet_info"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "getbalance"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " - << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "store"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - - plain_wallet::destroy_instance(hw); - - - return; - //------- - { - LOG_PRINT_L0("Creating instance..."); - plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211"); - LOG_PRINT_L0("Creating instance..." << std::hex << hw); - - LOG_PRINT_L0("Generating wallet..."); - std::string rsp = plain_wallet::generate(hw, std::string("E:\\tmp\\zano_testwallet_") + std::to_string(epee::misc_utils::get_tick_count()) + ".zan", ""); - LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); - epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); - epee::serialization::load_t_from_json(ok_response, rsp); - - plain_wallet::start_sync_thread(hw); - LOG_PRINT_L0("Started sync thread."); - - while (true) - { - std::string prog = plain_wallet::get_sync_status(hw); - plain_wallet::sync_status_response 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; - epee::misc_utils::sleep_no_w(1000); - } - LOG_PRINT_L0("Sync finished OK"); - - { - //request get wallet info: - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "get_wallet_info"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "getbalance"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " - << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); - } - - { - //request balance - epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); - gbreq.method = "store"; - epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); - std::string req_str = epee::serialization::store_t_to_json(gbreq); - - std::string res = plain_wallet::invoke(hw, req_str); - epee::serialization::load_t_from_json(gbres, res); - - LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " - << ENDL << res); - } - } + std::string s = plain_wallet::init("127.0.0.1", "11211"); +// LOG_PRINT_L0("Creating instance..." << std::hex << hw); +// +// LOG_PRINT_L0("Generating wallet..."); +// std::string rsp = plain_wallet::open(hw, std::string("E:\\tmp\\zano_testwallet_74565030.zan"), ""); +// LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); +// epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); +// epee::serialization::load_t_from_json(ok_response, rsp); +// +// plain_wallet::start_sync_thread(hw); +// LOG_PRINT_L0("Started sync thread."); +// +// while (true) +// { +// std::string prog = plain_wallet::get_sync_status(hw); +// plain_wallet::sync_status_response 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; +// epee::misc_utils::sleep_no_w(1000); +// } +// LOG_PRINT_L0("Sync finished OK"); +// +// { +// //request get wallet info: +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "get_wallet_info"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "getbalance"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " +// << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "store"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// +// plain_wallet::destroy_instance(hw); +// +// +// return; +// //------- +// { +// LOG_PRINT_L0("Creating instance..."); +// plain_wallet::hwallet hw = plain_wallet::create_instance("127.0.0.1", "11211"); +// LOG_PRINT_L0("Creating instance..." << std::hex << hw); +// +// LOG_PRINT_L0("Generating wallet..."); +// std::string rsp = plain_wallet::generate(hw, std::string("E:\\tmp\\zano_testwallet_") + std::to_string(epee::misc_utils::get_tick_count()) + ".zan", ""); +// LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); +// epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); +// epee::serialization::load_t_from_json(ok_response, rsp); +// +// plain_wallet::start_sync_thread(hw); +// LOG_PRINT_L0("Started sync thread."); +// +// while (true) +// { +// std::string prog = plain_wallet::get_sync_status(hw); +// plain_wallet::sync_status_response 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; +// epee::misc_utils::sleep_no_w(1000); +// } +// LOG_PRINT_L0("Sync finished OK"); +// +// { +// //request get wallet info: +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "get_wallet_info"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "getbalance"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], balance: " +// << gbres.result.balance << ", unlocked_balance: " << gbres.result.unlocked_balance); +// } +// +// { +// //request balance +// epee::json_rpc::request gbreq = AUTO_VAL_INIT(gbreq); +// gbreq.method = "store"; +// epee::json_rpc::response gbres = AUTO_VAL_INIT(gbres); +// std::string req_str = epee::serialization::store_t_to_json(gbreq); +// +// std::string res = plain_wallet::invoke(hw, req_str); +// epee::serialization::load_t_from_json(gbres, res); +// +// LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " +// << ENDL << res); +// } +// } } \ No newline at end of file From 92cce9628c82ed87b72cc55a18a8b6f37ac2e22e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 20:55:11 +0100 Subject: [PATCH 16/44] enebale remote node flag --- src/wallet/wallets_manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index cb3ee4dc..4dd2e046 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -229,6 +229,7 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) if (command_line::has_arg(m_vm, arg_remote_node)) { + m_remote_node_mode = true; m_rpc_proxy.reset(new tools::default_http_core_proxy()); m_rpc_proxy->set_connection_addr(command_line::get_arg(m_vm, arg_remote_node)); } From 34b823308702869b28eb6b9a5188183803b53e62 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Wed, 12 Feb 2020 20:58:36 +0100 Subject: [PATCH 17/44] fixed wallet path bug --- src/wallet/plain_wallet_api.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 3e261269..014f1a9d 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -115,8 +115,9 @@ namespace plain_wallet std::string open(const std::string& path, const std::string& password) { + std::string full_path = get_wallets_folder() + "/" + path; epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); - std::string rsp = gwm.open_wallet(epee::string_encoding::convert_to_unicode(path), password, 20, ok_response.result); + std::string rsp = gwm.open_wallet(epee::string_encoding::convert_to_unicode(full_path), password, 20, ok_response.result); if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) { if (rsp == API_RETURN_CODE_FILE_RESTORED) @@ -131,8 +132,9 @@ namespace plain_wallet } std::string restore(const std::string& seed, const std::string& path, const std::string& password) { + std::string full_path = get_wallets_folder() + "/" + path; epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); - std::string rsp = gwm.restore_wallet(epee::string_encoding::convert_to_unicode(path), password, seed, ok_response.result); + std::string rsp = gwm.restore_wallet(epee::string_encoding::convert_to_unicode(full_path), password, seed, ok_response.result); if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) { if (rsp == API_RETURN_CODE_FILE_RESTORED) @@ -148,8 +150,9 @@ namespace plain_wallet std::string generate(const std::string& path, const std::string& password) { + std::string full_path = get_wallets_folder() + "/" + path; epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); - std::string rsp = gwm.generate_wallet(epee::string_encoding::convert_to_unicode(path), password, ok_response.result); + std::string rsp = gwm.generate_wallet(epee::string_encoding::convert_to_unicode(full_path), password, ok_response.result); if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) { if (rsp == API_RETURN_CODE_FILE_RESTORED) From c4a423f6f57e9e0e6959856775fe95416f4fd31d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Feb 2020 01:44:30 +0100 Subject: [PATCH 18/44] fixed native library for auto-start of sync process in wallet thread --- src/wallet/plain_wallet_api.cpp | 15 +++++++---- src/wallet/wallets_manager.cpp | 2 +- tests/functional_tests/plain_wallet_tests.cpp | 26 ++++++++++++++++--- 3 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 014f1a9d..dd06f183 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -28,7 +28,7 @@ namespace plain_wallet std::string get_bundle_root_dir() { #ifdef WIN32 - return "undefined"; + return ""; #endif // WIN32 char buffer[1000] = {0}; @@ -38,7 +38,10 @@ namespace plain_wallet std::string get_wallets_folder() { - std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME; +#ifdef WIN32 + return ""; +#endif // WIN32 + std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME + "/"; return path; } @@ -115,7 +118,7 @@ namespace plain_wallet std::string open(const std::string& path, const std::string& password) { - std::string full_path = get_wallets_folder() + "/" + path; + std::string full_path = get_wallets_folder() + path; epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); std::string rsp = gwm.open_wallet(epee::string_encoding::convert_to_unicode(full_path), password, 20, ok_response.result); if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) @@ -124,6 +127,8 @@ namespace plain_wallet { ok_response.result.recovered = true; } + gwm.run_wallet(ok_response.result.wallet_id); + return epee::serialization::store_t_to_json(ok_response); } error_response err_result = AUTO_VAL_INIT(err_result); @@ -132,7 +137,7 @@ namespace plain_wallet } std::string restore(const std::string& seed, const std::string& path, const std::string& password) { - std::string full_path = get_wallets_folder() + "/" + path; + std::string full_path = get_wallets_folder() + path; epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); std::string rsp = gwm.restore_wallet(epee::string_encoding::convert_to_unicode(full_path), password, seed, ok_response.result); if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) @@ -150,7 +155,7 @@ namespace plain_wallet std::string generate(const std::string& path, const std::string& password) { - std::string full_path = get_wallets_folder() + "/" + path; + std::string full_path = get_wallets_folder() + path; epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); std::string rsp = gwm.generate_wallet(epee::string_encoding::convert_to_unicode(full_path), password, ok_response.result); if (rsp == API_RETURN_CODE_OK || rsp == API_RETURN_CODE_FILE_RESTORED) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 4dd2e046..9da7eaf6 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -1616,7 +1616,7 @@ void wallets_manager::wallet_vs_options::worker_func() if (last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height < 3) show_progress = false; - if(last_wallet_synch_height && *plast_daemon_height - last_wallet_synch_height > 10) + if(*plast_daemon_height - last_wallet_synch_height > 10) { CRITICAL_REGION_LOCAL(long_refresh_in_progress_lock); long_refresh_in_progress = true; diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index caf30eec..82ccc75c 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -19,7 +19,28 @@ using namespace epee; void run_plain_wallet_api_test() { LOG_PRINT_L0("Creating instance..."); - std::string s = plain_wallet::init("127.0.0.1", "11211"); + std::string s = plain_wallet::init("195.201.107.230", "11211"); + + LOG_PRINT_L0("Generating wallet..."); + std::string rsp = plain_wallet::open(std::string("E:\\tmp\\zano_testwallet_745ss65030.zan"), ""); + LOG_PRINT_L0("RESPONSE:" << ENDL << rsp); + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + epee::serialization::load_t_from_json(ok_response, rsp); + + + 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; + epee::misc_utils::sleep_no_w(1000); + } +} + // LOG_PRINT_L0("Creating instance..." << std::hex << hw); // // LOG_PRINT_L0("Generating wallet..."); @@ -157,5 +178,4 @@ void run_plain_wallet_api_test() // LOG_PRINT_L0("Balance request returned: code [" << gbres.error.code << "], str_response: " // << ENDL << res); // } -// } -} \ No newline at end of file +// }} \ No newline at end of file From 74092e500b8d3b8b68522daa3f714646ad0f5cf6 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Feb 2020 21:29:07 +0100 Subject: [PATCH 19/44] fixed bug in generate/restore api --- src/wallet/plain_wallet_api.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index dd06f183..6b0f8ee6 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -146,6 +146,7 @@ namespace plain_wallet { ok_response.result.recovered = true; } + gwm.run_wallet(ok_response.result.wallet_id); return epee::serialization::store_t_to_json(ok_response); } error_response err_result = AUTO_VAL_INIT(err_result); @@ -164,6 +165,7 @@ namespace plain_wallet { ok_response.result.recovered = true; } + gwm.run_wallet(ok_response.result.wallet_id); return epee::serialization::store_t_to_json(ok_response); } error_response err_result = AUTO_VAL_INIT(err_result); From 5cc30aa01df3411fa717b76cf6e4abfdcde882a3 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Feb 2020 22:28:17 +0100 Subject: [PATCH 20/44] added seed data to inital api calls --- src/wallet/view_iface.h | 2 ++ src/wallet/wallets_manager.cpp | 3 +++ 2 files changed, 5 insertions(+) diff --git a/src/wallet/view_iface.h b/src/wallet/view_iface.h index ccdfe1e6..48a87459 100644 --- a/src/wallet/view_iface.h +++ b/src/wallet/view_iface.h @@ -424,12 +424,14 @@ public: uint64_t wallet_id; transfers_array recent_history; wallet_info wi; + std::string seed; bool recovered; BEGIN_KV_SERIALIZE_MAP() KV_SERIALIZE(wallet_id) KV_SERIALIZE(recent_history) KV_SERIALIZE(wi) + KV_SERIALIZE(seed) KV_SERIALIZE(recovered) END_KV_SERIALIZE_MAP() }; diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 9da7eaf6..61a46d3d 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -717,6 +717,7 @@ std::string wallets_manager::open_wallet(const std::wstring& path, const std::st //w->get_unconfirmed_transfers(owr.recent_history.unconfirmed); w->get_unconfirmed_transfers(owr.recent_history.history); //workaround for missed fee + owr.seed = w->get_account().get_restore_braindata(); break; } catch (const tools::error::file_not_found& /**/) @@ -790,6 +791,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std try { w->generate(path, password); + owr.seed = w->get_account().get_restore_braindata(); } catch (const tools::error::file_exists/*& e*/) { @@ -877,6 +879,7 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: try { w->restore(path, password, restore_key); + owr.seed = w->get_account().get_restore_braindata(); } catch (const tools::error::file_exists/*& e*/) { From b695238f47f0b5e816c195307178a5707449dc4a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 13 Feb 2020 23:58:44 +0100 Subject: [PATCH 21/44] disabled terminate handler --- src/wallet/wallets_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 61a46d3d..85cb5477 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -107,10 +107,10 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) // setup custom callstack retrieving function epee::misc_utils::get_callstack(tools::get_callstack); - +#ifndef IOS_BUILD // setup custom terminate functions std::set_terminate(&terminate_handler_func); - +#endif //#if !defined(NDEBUG) // log_space::log_singletone::add_logger(LOGGER_DEBUGGER, nullptr, nullptr); //#endif From 0a1f87bc1400d9be65bd104edad639d8a2aefb40 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 14 Feb 2020 22:02:20 +0100 Subject: [PATCH 22/44] returned terminate handler --- src/wallet/wallets_manager.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 85cb5477..54c8b4f5 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -107,10 +107,10 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) // setup custom callstack retrieving function epee::misc_utils::get_callstack(tools::get_callstack); -#ifndef IOS_BUILD +//#ifndef IOS_BUILD // setup custom terminate functions std::set_terminate(&terminate_handler_func); -#endif +//#endif //#if !defined(NDEBUG) // log_space::log_singletone::add_logger(LOGGER_DEBUGGER, nullptr, nullptr); //#endif From fa3c922c6fb088fa0d43563e1bb44116a89db127 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 07:05:02 +0100 Subject: [PATCH 23/44] Android-related changes(dirty) for native library --- CMakeLists.txt | 44 ++++++++++++++++++++++++--------------- contrib/CMakeLists.txt | 2 +- contrib/db/CMakeLists.txt | 2 +- src/CMakeLists.txt | 2 +- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index dae368fd..76161820 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,8 +13,13 @@ set(VERSION "1.0") # cmake_policy(SET CMP0020 OLD) # endif() -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") add_definitions(-DIOS_BUILD) + if(CMAKE_SYSTEM_NAME STREQUAL "Android") + message("Android sdk prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}") + message("Android CMAKE_CXX_COMPILER prefix: ${CMAKE_CXX_COMPILER}") + message("Android ANDROID_LD: ${ANDROID_LD}") + endif() endif() @@ -28,7 +33,7 @@ if (UNIX AND NOT APPLE) endif() else() # multi configurations for MSVC and XCode - if(CMAKE_SYSTEM_NAME STREQUAL "iOS") + if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") set(CMAKE_CONFIGURATION_TYPES "Release") else() set(CMAKE_CONFIGURATION_TYPES "Debug;Release") @@ -97,12 +102,12 @@ else() endif() # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0)) - set(CMAKE_AR "gcc-ar") - set(CMAKE_RANLIB "gcc-ranlib") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE) - set(CMAKE_AR "llvm-ar") - set(CMAKE_RANLIB "llvm-ranlib") + if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) + ## set(CMAKE_AR "gcc-ar") + ## set(CMAKE_RANLIB "gcc-ranlib") + elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) + ## set(CMAKE_AR "llvm-ar") + ## set(CMAKE_RANLIB "llvm-ranlib") endif() @@ -170,15 +175,20 @@ if(STATIC) set(Boost_USE_STATIC_RUNTIME ON) endif() - -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") - set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/include") - set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/ios/") - set(Boost_LIBRARIES "libboost.a") - set(Boost_VERSION "ofxiOSBoost 1.60.0") -else() - find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) -endif() +#message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") +#if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +# set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/include") +# set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/ios/") +# set(Boost_LIBRARIES "libboost.a") +# set(Boost_VERSION "ofxiOSBoost 1.60.0") +#elseif(MAKE_SYSTEM_NAME STREQUAL "Android") + set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") + set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/armeabi-v7a/lib") + set(Boost_LIBRARIES "libboost_system.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") + set(Boost_VERSION "PurpleI2PBoost 1.68.0") +# else() +# find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) +#endif() diff --git a/contrib/CMakeLists.txt b/contrib/CMakeLists.txt index 60de2c34..779876a1 100644 --- a/contrib/CMakeLists.txt +++ b/contrib/CMakeLists.txt @@ -6,7 +6,7 @@ add_subdirectory(db) add_subdirectory(ethereum) -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") message("excluded upnp support for IOS build") return() endif() diff --git a/contrib/db/CMakeLists.txt b/contrib/db/CMakeLists.txt index ad19848c..6f2213b4 100644 --- a/contrib/db/CMakeLists.txt +++ b/contrib/db/CMakeLists.txt @@ -1,6 +1,6 @@ -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") message("excluded db support for IOS build") return() endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b11fa25d..a488e07d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -106,7 +106,7 @@ add_library(currency_core ${CURRENCY_CORE}) add_dependencies(currency_core version ${PCH_LIB_NAME}) ENABLE_SHARED_PCH(CURRENCY_CORE) -if(CMAKE_SYSTEM_NAME STREQUAL "iOS") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" ) install(TARGETS wallet currency_core crypto common DESTINATION lib) message("Generating for iOS: finished") return() From 89b15a9dc2a5896e6acb6106dee3edc5ff0587f1 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 07:45:59 +0100 Subject: [PATCH 24/44] adjusted macros for both android and ios --- CMakeLists.txt | 2 +- src/wallet/plain_wallet_api.cpp | 10 +++++++++- src/wallet/wallets_manager.cpp | 34 ++++++++++++++++----------------- src/wallet/wallets_manager.h | 6 +++--- 4 files changed, 30 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 76161820..736210f3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ set(VERSION "1.0") # endif() if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") - add_definitions(-DIOS_BUILD) + add_definitions(-DMOBILE_WALLET_BUILD) if(CMAKE_SYSTEM_NAME STREQUAL "Android") message("Android sdk prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}") message("Android CMAKE_CXX_COMPILER prefix: ${CMAKE_CXX_COMPILER}") diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 6b0f8ee6..8bcf2ff0 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -12,7 +12,12 @@ std::atomic initialized(false); +#define ANDROID_PACKAGE_NAME "zano_mobile" +#ifdef IOS_BUILD #define HOME_FOLDER "Documents" +#elif ANDROID_BUILD +#define HOME_FOLDER "files" +#endif #define WALLETS_FOLDER_NAME "wallets" #define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND" @@ -30,10 +35,13 @@ namespace plain_wallet #ifdef WIN32 return ""; #endif // WIN32 - +#ifdef IOS_BUILD char buffer[1000] = {0}; strcpy(buffer, getenv("HOME")); return buffer; +#elif ANDROID_BUILD + return "/data/data/ "ANDROID_PACKAGE_NAME +#endif } std::string get_wallets_folder() diff --git a/src/wallet/wallets_manager.cpp b/src/wallet/wallets_manager.cpp index 54c8b4f5..7651e237 100644 --- a/src/wallet/wallets_manager.cpp +++ b/src/wallet/wallets_manager.cpp @@ -6,7 +6,7 @@ #include "wallets_manager.h" #include "currency_core/alias_helper.h" -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD #include "core_fast_rpc_proxy.h" #include "currency_core/core_tools.h" #endif @@ -33,7 +33,7 @@ auto& name = it->second.w; wallets_manager::wallets_manager():m_pview(&m_view_stub), m_stop_singal_sent(false), -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD m_ccore(&m_cprotocol), m_cprotocol(m_ccore, &m_p2psrv), m_p2psrv(m_cprotocol), @@ -52,7 +52,7 @@ wallets_manager::wallets_manager():m_pview(&m_view_stub), m_is_pos_allowed(false), m_qt_logs_enbaled(false) { -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD m_offers_service.set_disabled(true); #endif //m_ccore.get_blockchain_storage().get_attachment_services_manager().add_service(&m_offers_service); @@ -107,7 +107,7 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) // setup custom callstack retrieving function epee::misc_utils::get_callstack(tools::get_callstack); -//#ifndef IOS_BUILD +//#ifndef MOBILE_WALLET_BUILD // setup custom terminate functions std::set_terminate(&terminate_handler_func); //#endif @@ -139,7 +139,7 @@ bool wallets_manager::init(int argc, char* argv[], view::i_view* pview_handler) command_line::add_arg(desc_cmd_sett, arg_remote_node); command_line::add_arg(desc_cmd_sett, arg_enable_qt_logs); -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD currency::core::init_options(desc_cmd_sett); currency::core_rpc_server::init_options(desc_cmd_sett); nodetool::node_server >::init_options(desc_cmd_sett); @@ -299,7 +299,7 @@ std::string wallets_manager::get_config_folder() bool wallets_manager::init_local_daemon() { -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.pos_difficulty = dsi.pos_difficulty = "---"; dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_loading_core; @@ -374,7 +374,7 @@ bool wallets_manager::init_local_daemon() bool wallets_manager::deinit_local_daemon() { -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD view::daemon_status_info dsi = AUTO_VAL_INIT(dsi); dsi.daemon_network_state = currency::COMMAND_RPC_GET_INFO::daemon_network_state_unloading_core; m_pview->update_daemon_status(dsi); @@ -585,7 +585,7 @@ void wallets_manager::init_wallet_entry(wallet_vs_options& wo, uint64_t id) wo.core_conf = currency::get_default_core_runtime_config(); else { -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD wo.core_conf = m_ccore.get_blockchain_storage().get_core_runtime_config(); #else LOG_ERROR("Unexpected location reached"); @@ -623,7 +623,7 @@ std::string wallets_manager::get_fav_offers(const std::listset_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); #else LOG_ERROR("Unexpected location reached"); @@ -777,7 +777,7 @@ std::string wallets_manager::generate_wallet(const std::wstring& path, const std } else { -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); #else LOG_ERROR("Unexpected location reached"); @@ -817,7 +817,7 @@ std::string wallets_manager::get_mining_estimate(uint64_t amuont_coins, { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD m_ccore.get_blockchain_storage().get_pos_mining_estimate(amuont_coins, time, estimate_result, pos_coins_and_pos_diff_rate, days); return API_RETURN_CODE_OK; #else @@ -840,7 +840,7 @@ std::string wallets_manager::is_valid_brain_restore_data(const std::string& brai else return API_RETURN_CODE_FALSE; } -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD void wallets_manager::subscribe_to_core_events(currency::i_core_event_handler* pevents_handler) { @@ -864,7 +864,7 @@ std::string wallets_manager::restore_wallet(const std::wstring& path, const std: } else { -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD w->set_core_proxy(std::shared_ptr(new tools::core_fast_rpc_proxy(m_rpc_server))); #else LOG_ERROR("Unexpected location reached"); @@ -933,7 +933,7 @@ std::string wallets_manager::get_aliases(view::alias_set& al_set) if (m_remote_node_mode) return API_RETURN_CODE_OVERFLOW; -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD if (m_ccore.get_blockchain_storage().get_aliases_count() > API_MAX_ALIASES_COUNT) return API_RETURN_CODE_OVERFLOW; @@ -1523,7 +1523,7 @@ std::string wallets_manager::get_offers_ex(const bc_services::core_offers_filter { if (m_remote_node_mode) return API_RETURN_CODE_FAIL; -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD //TODO: make it proxy-like call //m_ccore.get_blockchain_storage().get_offers_ex(cof, offers, total_count); m_offers_service.get_offers_ex(cof, offers, total_count, m_ccore.get_blockchain_storage().get_core_runtime_config().get_core_time()); diff --git a/src/wallet/wallets_manager.h b/src/wallet/wallets_manager.h index f9b6c47f..8b69def2 100644 --- a/src/wallet/wallets_manager.h +++ b/src/wallet/wallets_manager.h @@ -19,7 +19,7 @@ using namespace epee; #include "console_handler.h" #include "p2p/net_node.h" #include "currency_core/checkpoints_create.h" -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD #include "currency_core/currency_core.h" #include "currency_core/bc_offers_service.h" #include "rpc/core_rpc_server.h" @@ -142,7 +142,7 @@ public: std::string transfer(size_t wallet_id, const view::transfer_params& tp, currency::transaction& res_tx); std::string get_config_folder(); std::string is_valid_brain_restore_data(const std::string& brain_text); -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD void subscribe_to_core_events(currency::i_core_event_handler* pevents_handler); //void unsubscribe_to_core_events(); #endif @@ -186,7 +186,7 @@ private: std::string m_data_dir; view::gui_options m_ui_opt; -#ifndef IOS_BUILD +#ifndef MOBILE_WALLET_BUILD //daemon stuff bc_services::bc_offers_service m_offers_service; currency::core m_ccore; From 51eb479000faf79698605aa3e756adce34b7038e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 08:15:18 +0100 Subject: [PATCH 25/44] disabled call stack extracting for android --- contrib/epee/include/misc_os_dependent.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/contrib/epee/include/misc_os_dependent.h b/contrib/epee/include/misc_os_dependent.h index c755d70c..c06e5d94 100644 --- a/contrib/epee/include/misc_os_dependent.h +++ b/contrib/epee/include/misc_os_dependent.h @@ -109,14 +109,15 @@ namespace misc_utils #endif } -#if defined(__GNUC__) + +#if defined(__GNUC__) && !defined(__ANDROID__) #include #include #endif inline std::string print_trace_default() { std::stringstream ss; -#if defined(__GNUC__) +#if defined(__GNUC__) && !defined(__ANDROID__) ss << std::endl << "STACK" << std::endl; const size_t max_depth = 100; size_t stack_depth; From 92d4ecd654fc65a04f513bf1620123a7c3e34c07 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 08:37:31 +0100 Subject: [PATCH 26/44] disabled cmake explicit CMAKE_AR assign --- CMakeLists.txt | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 736210f3..9f914733 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -102,13 +102,13 @@ else() endif() # Since gcc 4.9 the LTO format is non-standard (slim), so we need the gcc-specific ar and ranlib binaries - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) + ##if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.9.0) AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) ## set(CMAKE_AR "gcc-ar") ## set(CMAKE_RANLIB "gcc-ranlib") - elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) + ##elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" AND NOT APPLE AND NOT (MAKE_SYSTEM_NAME STREQUAL "Android")) ## set(CMAKE_AR "llvm-ar") ## set(CMAKE_RANLIB "llvm-ranlib") - endif() + ##endif() if(MINGW) @@ -175,19 +175,19 @@ if(STATIC) set(Boost_USE_STATIC_RUNTIME ON) endif() -#message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") -#if(CMAKE_SYSTEM_NAME STREQUAL "iOS") -# set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/include") -# set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/ios/") -# set(Boost_LIBRARIES "libboost.a") -# set(Boost_VERSION "ofxiOSBoost 1.60.0") -#elseif(MAKE_SYSTEM_NAME STREQUAL "Android") +message("CMAKE_SYSTEM_NAME: ${CMAKE_SYSTEM_NAME}") +if(CMAKE_SYSTEM_NAME STREQUAL "iOS") + set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/include") + set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/ios/") + set(Boost_LIBRARIES "libboost.a") + set(Boost_VERSION "ofxiOSBoost 1.60.0") +elseif(MAKE_SYSTEM_NAME STREQUAL "Android") set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/armeabi-v7a/lib") set(Boost_LIBRARIES "libboost_system.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") set(Boost_VERSION "PurpleI2PBoost 1.68.0") -# else() -# find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) +else() + find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) #endif() From 410e241bdd3ada00f132e6f0d2c0745370257a74 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 08:43:27 +0100 Subject: [PATCH 27/44] uncommented forgoten endif --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9f914733..757a50e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,7 +188,7 @@ elseif(MAKE_SYSTEM_NAME STREQUAL "Android") set(Boost_VERSION "PurpleI2PBoost 1.68.0") else() find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) -#endif() +endif() From 5e7f42231d8a43e701b8c5b03447c1ab57476377 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 08:45:50 +0100 Subject: [PATCH 28/44] fixed type in cmake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 757a50e5..99bb38e5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,7 +181,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/ofxiOSBoost/libs/boost/ios/") set(Boost_LIBRARIES "libboost.a") set(Boost_VERSION "ofxiOSBoost 1.60.0") -elseif(MAKE_SYSTEM_NAME STREQUAL "Android") +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/armeabi-v7a/lib") set(Boost_LIBRARIES "libboost_system.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") From 6d81ff7f6d08ac2a583f73954cc4e624a7f41fac Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 09:01:42 +0100 Subject: [PATCH 29/44] added ios and android macro definition --- CMakeLists.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 99bb38e5..037ba50c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,14 +15,17 @@ set(VERSION "1.0") if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") add_definitions(-DMOBILE_WALLET_BUILD) + if(CMAKE_SYSTEM_NAME STREQUAL "iOS" ) + add_definitions(-DIOS_BUILD) + endif() if(CMAKE_SYSTEM_NAME STREQUAL "Android") + add_definitions(-DANDROID_BUILD) message("Android sdk prefix: ${CMAKE_CXX_ANDROID_TOOLCHAIN_PREFIX}") message("Android CMAKE_CXX_COMPILER prefix: ${CMAKE_CXX_COMPILER}") message("Android ANDROID_LD: ${ANDROID_LD}") endif() endif() - set_property(GLOBAL PROPERTY USE_FOLDERS ON) # build types From 0dec06b271648734de793283d6dc24dc1cea3902 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 09:08:53 +0100 Subject: [PATCH 30/44] fixed compilation issue with literal --- src/wallet/plain_wallet_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 8bcf2ff0..ab095828 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -40,7 +40,7 @@ namespace plain_wallet strcpy(buffer, getenv("HOME")); return buffer; #elif ANDROID_BUILD - return "/data/data/ "ANDROID_PACKAGE_NAME + return "/data/data/" ANDROID_PACKAGE_NAME #endif } From da0c01a953d8c2a2f026cf01d74abb9b73d6113e Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Tue, 18 Feb 2020 09:14:56 +0100 Subject: [PATCH 31/44] no comments! :) --- src/wallet/plain_wallet_api.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index ab095828..059f4952 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -40,7 +40,7 @@ namespace plain_wallet strcpy(buffer, getenv("HOME")); return buffer; #elif ANDROID_BUILD - return "/data/data/" ANDROID_PACKAGE_NAME + return "/data/data/" ANDROID_PACKAGE_NAME; #endif } From 0c6b813c0508a661601a74a1feca8db7ba06e28f Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 20 Feb 2020 02:54:45 +0100 Subject: [PATCH 32/44] paindroid version fixes --- CMakeLists.txt | 8 +++++--- src/CMakeLists.txt | 29 ++++++++++++++++++++++------- src/common/int-util.h | 6 +++--- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 037ba50c..d7e18190 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -186,8 +186,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(Boost_VERSION "ofxiOSBoost 1.60.0") elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") - set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/armeabi-v7a/lib") - set(Boost_LIBRARIES "libboost_system.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") + set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/${CMAKE_ANDROID_ARCH_ABI}/lib/") + link_directories("${Boost_LIBRARY_DIRS}") + set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a;${Boost_LIBRARY_DIRS}libboost_locale.a") + # set(Boost_LIBRARIES "libboost_system_w.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") set(Boost_VERSION "PurpleI2PBoost 1.68.0") else() find_package(Boost 1.55 REQUIRED COMPONENTS system filesystem thread timer date_time chrono regex serialization atomic program_options locale) @@ -203,7 +205,7 @@ if(MINGW) set(Boost_LIBRARIES "${Boost_LIBRARIES};ws2_32;mswsock") elseif(NOT MSVC) if(NOT APPLE) - set(Boost_LIBRARIES "${Boost_LIBRARIES};rt") + set(Boost_LIBRARIES "${Boost_LIBRARIES};") if(STATIC) message("NOTICE: Including static ICU libraries") set(Boost_LIBRARIES "${Boost_LIBRARIES};icui18n.a;icuuc.a;icudata.a;dl") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a488e07d..9c60eaf0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -98,17 +98,32 @@ endif() add_library(crypto ${CRYPTO}) -add_library(wallet ${WALLET}) -add_dependencies(wallet version ${PCH_LIB_NAME}) -ENABLE_SHARED_PCH(WALLET) - add_library(currency_core ${CURRENCY_CORE}) add_dependencies(currency_core version ${PCH_LIB_NAME}) ENABLE_SHARED_PCH(CURRENCY_CORE) -if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android" ) +if(CMAKE_SYSTEM_NAME STREQUAL "Android" ) + add_library(wallet SHARED ${WALLET}) + add_dependencies(wallet version ${PCH_LIB_NAME}) + target_link_libraries(wallet currency_core crypto common zlibstatic ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) +else() + add_library(wallet ${WALLET}) + add_dependencies(wallet version ${PCH_LIB_NAME}) + ENABLE_SHARED_PCH(WALLET) +endif() + + + + + + +if(CMAKE_SYSTEM_NAME STREQUAL "iOS") install(TARGETS wallet currency_core crypto common DESTINATION lib) - message("Generating for iOS: finished") + message("Generating install for iOS") + return() +elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + install(TARGETS wallet DESTINATION "${CMAKE_ANDROID_ARCH_ABI}/lib") + message("Generating install for Android") return() endif() @@ -125,7 +140,7 @@ target_link_libraries(currency_core lmdb mdbx) add_executable(daemon ${DAEMON} ${P2P} ${CURRENCY_PROTOCOL}) add_dependencies(daemon version) -target_link_libraries(daemon rpc stratum currency_core crypto common libminiupnpc-static zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) + target_link_libraries(daemon rpc stratum currency_core crypto common libminiupnpc-static zlibstatic ethash ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) ENABLE_SHARED_PCH(DAEMON) ENABLE_SHARED_PCH_EXECUTABLE(daemon) diff --git a/src/common/int-util.h b/src/common/int-util.h index 9eff50be..261fb400 100644 --- a/src/common/int-util.h +++ b/src/common/int-util.h @@ -194,11 +194,11 @@ static inline void memcpy_swap64(void *dst, const void *src, size_t n) { } } -#if !defined(BYTE_ORDER) || !defined(LITTLE_ENDIAN) || !defined(BIG_ENDIAN) +#if !defined(__BYTE_ORDER__) || !defined(__ORDER_LITTLE_ENDIAN__) || !defined(__ORDER_BIG_ENDIAN__) static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled"); #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ #define SWAP32LE IDENT32 #define SWAP32BE SWAP32 #define swap32le ident32 @@ -217,7 +217,7 @@ static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not e #define memcpy_swap64be memcpy_swap64 #endif -#if BYTE_ORDER == BIG_ENDIAN +#if __BYTE_ORDER == __ORDER_BIG_ENDIAN__ #define SWAP32BE IDENT32 #define SWAP32LE SWAP32 #define swap32be ident32 From 0c54ca727011a0630ff8bfd40206167a202088d9 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 20 Feb 2020 03:07:03 +0100 Subject: [PATCH 33/44] get rid of boost.locale under paindroid --- src/currency_core/currency_format_utils.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/currency_core/currency_format_utils.cpp b/src/currency_core/currency_format_utils.cpp index 7c75dc10..0e403ebe 100644 --- a/src/currency_core/currency_format_utils.cpp +++ b/src/currency_core/currency_format_utils.cpp @@ -7,7 +7,9 @@ #include "include_base_utils.h" #include -#include +#ifndef ANDROID_BUILD + #include +#endif using namespace epee; #include "print_fixed_point_helper.h" @@ -2677,6 +2679,7 @@ namespace currency return o << "<" << r.n << ":" << r.tx_id << ">"; } //-------------------------------------------------------------------------------- +#ifndef ANDROID_BUILD const std::locale& utf8_get_conversion_locale() { static std::locale loc = boost::locale::generator().generate("en_US.UTF-8"); @@ -2696,6 +2699,7 @@ namespace currency return true; return utf8_to_lower(s).find(utf8_to_lower(match), 0) != std::string::npos; } +#endif //-------------------------------------------------------------------------------- bool operator ==(const currency::transaction& a, const currency::transaction& b) { return currency::get_transaction_hash(a) == currency::get_transaction_hash(b); From c18c6230cf1409ae5ab98ecd0ce7ae4ad5cc0225 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Thu, 20 Feb 2020 03:08:47 +0100 Subject: [PATCH 34/44] removed android lib from cmake --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d7e18190..d5f427b6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -188,7 +188,7 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/${CMAKE_ANDROID_ARCH_ABI}/lib/") link_directories("${Boost_LIBRARY_DIRS}") - set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a;${Boost_LIBRARY_DIRS}libboost_locale.a") + set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a") # set(Boost_LIBRARIES "libboost_system_w.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") set(Boost_VERSION "PurpleI2PBoost 1.68.0") else() From 7b12ce6e9fa3e558883bde01022fc2183967042a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 01:05:39 +0100 Subject: [PATCH 35/44] disabled unlinked utf8 functions for android, chaged libs to static --- src/CMakeLists.txt | 4 +- src/currency_core/currency_format_utils.h | 2 + src/currency_core/offers_services_helpers.cpp | 4 + src/currency_core/offers_services_helpers.h | 17 +++- utils/build_android_libs.sh | 78 +++++++++++++++++++ 5 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 utils/build_android_libs.sh diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9c60eaf0..d7ff6954 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -103,7 +103,7 @@ add_dependencies(currency_core version ${PCH_LIB_NAME}) ENABLE_SHARED_PCH(CURRENCY_CORE) if(CMAKE_SYSTEM_NAME STREQUAL "Android" ) - add_library(wallet SHARED ${WALLET}) + add_library(wallet ${WALLET}) add_dependencies(wallet version ${PCH_LIB_NAME}) target_link_libraries(wallet currency_core crypto common zlibstatic ${CMAKE_THREAD_LIBS_INIT} ${Boost_LIBRARIES}) else() @@ -122,7 +122,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS") message("Generating install for iOS") return() elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") - install(TARGETS wallet DESTINATION "${CMAKE_ANDROID_ARCH_ABI}/lib") + install(TARGETS wallet currency_core crypto common zlibstatic DESTINATION "${CMAKE_ANDROID_ARCH_ABI}/lib") message("Generating install for Android") return() endif() diff --git a/src/currency_core/currency_format_utils.h b/src/currency_core/currency_format_utils.h index 547c939c..01d08170 100644 --- a/src/currency_core/currency_format_utils.h +++ b/src/currency_core/currency_format_utils.h @@ -595,9 +595,11 @@ namespace currency //--------------------------------------------------------------- std::ostream& operator <<(std::ostream& o, const ref_by_id& r); //--------------------------------------------------------------- +#ifndef ANDROID_BUILD std::string utf8_to_upper(const std::string& s); std::string utf8_to_lower(const std::string& s); bool utf8_substring_test_case_insensitive(const std::string& match, const std::string& s); // Returns true is 's' contains 'match' (case-insensitive) +#endif struct difficulties { diff --git a/src/currency_core/offers_services_helpers.cpp b/src/currency_core/offers_services_helpers.cpp index 3be77927..09669340 100644 --- a/src/currency_core/offers_services_helpers.cpp +++ b/src/currency_core/offers_services_helpers.cpp @@ -56,7 +56,11 @@ namespace bc_services //------------------------------------------------------------------ bool order_offers_by_name(const offer_details_ex* a, const offer_details_ex* b) { +#ifndef ANDROID_BUILD return currency::utf8_to_lower(a->target) < currency::utf8_to_lower(b->target); +#else + return false; +#endif } //------------------------------------------------------------------ std::vector gsort_offers_predicates; diff --git a/src/currency_core/offers_services_helpers.h b/src/currency_core/offers_services_helpers.h index a6182d11..fc2203fb 100644 --- a/src/currency_core/offers_services_helpers.h +++ b/src/currency_core/offers_services_helpers.h @@ -191,8 +191,21 @@ namespace bc_services inline double extract_rate(const odeh& v) { return calculate_offer_rate(v); } inline size_t extract_payment_types(const odeh& v) { return v.payment_types.size(); } inline std::string extract_contacts(const odeh& v) { return v.contacts; } - inline std::string extract_location(const odeh& v) { return currency::utf8_to_lower(v.location_country + v.location_city); } - inline std::string extract_name(const odeh& v) { return currency::utf8_to_lower(v.target); } + inline std::string extract_location(const odeh& v) { + +#ifndef ANDROID_BUILD + return currency::utf8_to_lower(v.location_country + v.location_city); +#else + return "UNSUPORTED"; +#endif + } + inline std::string extract_name(const odeh& v) { +#ifndef ANDROID_BUILD + return currency::utf8_to_lower(v.target); +#else + return "UNSUPORTED"; +#endif + } template struct sort_id_to_type diff --git a/utils/build_android_libs.sh b/utils/build_android_libs.sh new file mode 100644 index 00000000..bde6a849 --- /dev/null +++ b/utils/build_android_libs.sh @@ -0,0 +1,78 @@ +set -x #echo on +cd .. +rm -r _builds +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Release --target install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Release --target install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + + +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Release --target install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + + +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +cmake --build _builds --config Release --target install +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + +rm -r _builds +if [ $? -ne 0 ]; then + echo "Failed to perform command" + exit 1 +fi + + From b154ce5dd73f18459d364d9f583c0c6b53059744 Mon Sep 17 00:00:00 2001 From: "cr.zoidberg" Date: Fri, 21 Feb 2020 01:10:21 +0100 Subject: [PATCH 36/44] changed addtributes --- utils/build_android_libs.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 utils/build_android_libs.sh diff --git a/utils/build_android_libs.sh b/utils/build_android_libs.sh old mode 100644 new mode 100755 From 40bedc2457c41e99da543b9f29acea4bbf4e62a3 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 01:14:58 +0100 Subject: [PATCH 37/44] removed other unlinkable in paindroid functions --- src/currency_core/offers_services_helpers.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/currency_core/offers_services_helpers.cpp b/src/currency_core/offers_services_helpers.cpp index 09669340..d99bf4de 100644 --- a/src/currency_core/offers_services_helpers.cpp +++ b/src/currency_core/offers_services_helpers.cpp @@ -150,14 +150,14 @@ namespace bc_services //check category if (!of.category.empty() && o.category.find(of.category) == std::string::npos) return false; - +#ifndef ANDROID_BUILD //check target condition if (of.target.size() && !currency::utf8_substring_test_case_insensitive(of.target, o.target)) return false; if (of.primary.size() && !currency::utf8_substring_test_case_insensitive(of.primary, o.primary)) return false; - +#endif //check payment_types condition (TODO: add more complicated algo here) if (of.payment_types.size()) @@ -173,11 +173,11 @@ namespace bc_services //check target condition if (of.location_country.size() && (of.location_country != o.location_country)) return false; - +#ifndef ANDROID_BUILD //check target condition if (of.location_city.size() && !currency::utf8_substring_test_case_insensitive(of.location_city, o.location_city)) return false; - +#endif //check amount if (of.amount_low_limit && (of.amount_low_limit > o.amount_primary)) return false; @@ -221,12 +221,12 @@ namespace bc_services //-------------------------------------------------------------------------------- bool filter_offers_list(std::list& offers, const bc_services::core_offers_filter& filter, uint64_t current_core_time) { - +#ifndef ANDROID_BUILD //filter offers.remove_if([&](bc_services::offer_details_ex& o) -> bool { return !is_offer_matched_by_filter(o, filter, current_core_time); }); - +#endif //sort CHECK_AND_ASSERT_MES(filter.order_by < gsort_offers_predicates.size(), false, "Wrong cof.order_by value"); auto cb = *gsort_offers_predicates[static_cast(filter.order_by)]; From f02be48e038ee7b9b0bba3bcdf39f84779526d37 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 02:13:58 +0100 Subject: [PATCH 38/44] fixed byte order for android --- src/common/int-util.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/int-util.h b/src/common/int-util.h index 261fb400..b60c7d97 100644 --- a/src/common/int-util.h +++ b/src/common/int-util.h @@ -198,7 +198,7 @@ static inline void memcpy_swap64(void *dst, const void *src, size_t n) { static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not enabled"); #endif -#if __BYTE_ORDER == __ORDER_LITTLE_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ #define SWAP32LE IDENT32 #define SWAP32BE SWAP32 #define swap32le ident32 @@ -217,7 +217,7 @@ static_assert(false, "BYTE_ORDER is undefined. Perhaps, GNU extensions are not e #define memcpy_swap64be memcpy_swap64 #endif -#if __BYTE_ORDER == __ORDER_BIG_ENDIAN__ +#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ #define SWAP32BE IDENT32 #define SWAP32LE SWAP32 #define swap32be ident32 From 161acc356123ba895a18a8a6602ba768446715b2 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 04:18:54 +0100 Subject: [PATCH 39/44] excluded srdout from android build --- contrib/epee/include/misc_log_ex.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 5e4d9a31..31b31e4b 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -365,6 +365,7 @@ namespace log_space inline bool is_stdout_a_tty() { +#ifndef ANDROID_BUILD static std::atomic initialized(false); static std::atomic is_a_tty(false); @@ -379,6 +380,9 @@ namespace log_space } return is_a_tty.load(std::memory_order_relaxed); +#else + return false; +#endif } inline void set_console_color(int color, bool bright) From 853e6e9484c4eba8695f0a18e859ef7f72acadbd Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 04:20:21 +0100 Subject: [PATCH 40/44] multithreaded build for android --- utils/build_android_libs.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/utils/build_android_libs.sh b/utils/build_android_libs.sh index bde6a849..81a7746b 100755 --- a/utils/build_android_libs.sh +++ b/utils/build_android_libs.sh @@ -1,13 +1,13 @@ set -x #echo on cd .. rm -r _builds -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install +cmake --build _builds --config Release --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 @@ -19,13 +19,13 @@ if [ $? -ne 0 ]; then exit 1 fi -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install +cmake --build _builds --config Release --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 @@ -38,13 +38,13 @@ if [ $? -ne 0 ]; then fi -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install +cmake --build _builds --config Release --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 @@ -57,13 +57,13 @@ if [ $? -ne 0 ]; then fi -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=28 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install +cmake --build _builds --config Release --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 From bb4e2be6d6aaa90304967556830d43b64fd3b7c7 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 09:28:45 +0100 Subject: [PATCH 41/44] disabled log channels for android, more fixes over build config --- CMakeLists.txt | 12 ++++++++---- contrib/epee/include/misc_log_ex.h | 4 ++++ utils/build_android_libs.sh | 16 ++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5f427b6..63b500de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,10 @@ if (UNIX AND NOT APPLE) endif() else() # multi configurations for MSVC and XCode - if(CMAKE_SYSTEM_NAME STREQUAL "iOS" OR CMAKE_SYSTEM_NAME STREQUAL "Android") + if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(CMAKE_CONFIGURATION_TYPES "Release") + elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") + set(CMAKE_CONFIGURATION_TYPES "Debug;Release") else() set(CMAKE_CONFIGURATION_TYPES "Debug;Release") endif() @@ -185,9 +187,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL "iOS") set(Boost_LIBRARIES "libboost.a") set(Boost_VERSION "ofxiOSBoost 1.60.0") elseif(CMAKE_SYSTEM_NAME STREQUAL "Android") - set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") - set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/${CMAKE_ANDROID_ARCH_ABI}/lib/") - link_directories("${Boost_LIBRARY_DIRS}") + #set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/include") + #set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/boost_1_68_0-clang/${CMAKE_ANDROID_ARCH_ABI}/lib/") + set(Boost_INCLUDE_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/1.69.0/include") + set(Boost_LIBRARY_DIRS "/Users/roky/projects/Zano/mobile_repo/Boost-for-Android-Prebuilt/1.69.0/libs/llvm/${CMAKE_ANDROID_ARCH_ABI}/") + #link_directories("${Boost_LIBRARY_DIRS}") set(Boost_LIBRARIES "${Boost_LIBRARY_DIRS}libboost_system.a;${Boost_LIBRARY_DIRS}libboost_filesystem.a;${Boost_LIBRARY_DIRS}libboost_thread.a;${Boost_LIBRARY_DIRS}libboost_timer.a;${Boost_LIBRARY_DIRS}libboost_date_time.a;${Boost_LIBRARY_DIRS}libboost_chrono.a;${Boost_LIBRARY_DIRS}libboost_regex.a;${Boost_LIBRARY_DIRS}libboost_serialization.a;${Boost_LIBRARY_DIRS}libboost_atomic.a;${Boost_LIBRARY_DIRS}libboost_program_options.a") # set(Boost_LIBRARIES "libboost_system_w.a libboost_filesystem.a libboost_thread.a libboost_timer.a libboost_date_time.a libboost_chrono.a libboost_regex.a libboost_serialization.a libboost_atomic.a libboost_program_options.a libboost_locale.a") set(Boost_VERSION "PurpleI2PBoost 1.68.0") diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 31b31e4b..52c0fc3a 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -113,10 +113,14 @@ DISABLE_VS_WARNINGS(4100) #endif #define LOG_DEFAULT_CHANNEL NULL +#ifndef ANDROID_BUILD #define ENABLE_CHANNEL_BY_DEFAULT(ch_name) \ static bool COMBINE(init_channel, __LINE__) UNUSED_ATTRIBUTE = epee::misc_utils::static_initializer([](){ \ epee::log_space::log_singletone::enable_channel(ch_name); return true; \ }); +#else + #define ENABLE_CHANNEL_BY_DEFAULT(ch_name) +#endif #if defined(ENABLE_LOGGING_INTERNAL) diff --git a/utils/build_android_libs.sh b/utils/build_android_libs.sh index 81a7746b..750ebf01 100755 --- a/utils/build_android_libs.sh +++ b/utils/build_android_libs.sh @@ -1,13 +1,13 @@ set -x #echo on cd .. rm -r _builds -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=armeabi-v7a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install -- -j 4 +cmake --build _builds --config Debug --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 @@ -19,13 +19,13 @@ if [ $? -ne 0 ]; then exit 1 fi -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install -- -j 4 +cmake --build _builds --config Debug --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 @@ -38,13 +38,13 @@ if [ $? -ne 0 ]; then fi -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install -- -j 4 +cmake --build _builds --config Debug --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 @@ -57,13 +57,13 @@ if [ $? -ne 0 ]; then fi -cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=16 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install +cmake -S. -B_builds -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_ARCH_ABI=x86_64 -DCMAKE_ANDROID_NDK=/Users/roky/Library/Android/sdk/ndk/18.1.5063045 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_INSTALL_PREFIX=`pwd`/_install if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 fi -cmake --build _builds --config Release --target install -- -j 4 +cmake --build _builds --config Debug --target install -- -j 4 if [ $? -ne 0 ]; then echo "Failed to perform command" exit 1 From f621740c7928ba6da55583905f1617a3395e1e5a Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 17:53:12 +0100 Subject: [PATCH 42/44] re-enabled channels on android --- contrib/epee/include/misc_log_ex.h | 8 ++++---- src/wallet/wallet2.h | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/contrib/epee/include/misc_log_ex.h b/contrib/epee/include/misc_log_ex.h index 52c0fc3a..be9f3b61 100644 --- a/contrib/epee/include/misc_log_ex.h +++ b/contrib/epee/include/misc_log_ex.h @@ -113,14 +113,12 @@ DISABLE_VS_WARNINGS(4100) #endif #define LOG_DEFAULT_CHANNEL NULL -#ifndef ANDROID_BUILD + #define ENABLE_CHANNEL_BY_DEFAULT(ch_name) \ static bool COMBINE(init_channel, __LINE__) UNUSED_ATTRIBUTE = epee::misc_utils::static_initializer([](){ \ epee::log_space::log_singletone::enable_channel(ch_name); return true; \ }); -#else - #define ENABLE_CHANNEL_BY_DEFAULT(ch_name) -#endif + #if defined(ENABLE_LOGGING_INTERNAL) @@ -1158,7 +1156,9 @@ namespace log_space std::set enabled_channels_local = genabled_channels; enabled_channels_local.insert(ch_name); genabled_channels.swap(enabled_channels_local); +#ifndef ANDROID_BUILD std::cout << "log channel '" << ch_name << "' enabled" << std::endl; +#endif } static void disable_channels(const std::string& channels_set) diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 02f0e077..cdd64fd6 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -46,7 +46,6 @@ #undef LOG_DEFAULT_CHANNEL #define LOG_DEFAULT_CHANNEL "wallet" -ENABLE_CHANNEL_BY_DEFAULT("wallet"); // wallet-specific logging functions #define WLT_LOG_L0(msg) LOG_PRINT_L0("[W:" << m_log_prefix << "] " << msg) From 181392f6412b31f00768a844b31353ed10c1eb16 Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Fri, 21 Feb 2020 19:29:46 +0100 Subject: [PATCH 43/44] fixed paindroid home dir prefix --- src/wallet/plain_wallet_api.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 059f4952..57a83d9d 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -12,7 +12,7 @@ std::atomic initialized(false); -#define ANDROID_PACKAGE_NAME "zano_mobile" +#define ANDROID_PACKAGE_NAME "com.zano_mobile" #ifdef IOS_BUILD #define HOME_FOLDER "Documents" #elif ANDROID_BUILD @@ -40,6 +40,7 @@ namespace plain_wallet strcpy(buffer, getenv("HOME")); return buffer; #elif ANDROID_BUILD + /// data/data/com.zano_mobile/files return "/data/data/" ANDROID_PACKAGE_NAME; #endif } From 211ff35e2ca8e709b8788bf9424734661256077d Mon Sep 17 00:00:00 2001 From: cryptozoidberg Date: Sun, 23 Feb 2020 03:14:35 +0100 Subject: [PATCH 44/44] fixed unhandled throw in case of double initialization --- src/wallet/plain_wallet_api.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 57a83d9d..90bb1b96 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -71,7 +71,8 @@ namespace plain_wallet if (initialized) { LOG_ERROR("Double-initialization in plain_wallet detected."); - throw std::runtime_error("Double-initialization in plain_wallet detected."); + //throw std::runtime_error("Double-initialization in plain_wallet detected."); + return "Already initialized!"; }