diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index c76ef533..ca0f4dca 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -3,7 +3,6 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. -#include #include "plain_wallet_api.h" #include "plain_wallet_api_impl.h" #include "currency_core/currency_config.h" @@ -15,13 +14,9 @@ #include "common/config_encrypt_helper.h" #define ANDROID_PACKAGE_NAME "com.zano_mobile" -#ifdef IOS_BUILD - #define HOME_FOLDER "Documents" -#elif ANDROID_BUILD - #define HOME_FOLDER "files" -#else - #define HOME_FOLDER "logs" -#endif + +#define LOGS_FOLDER "logs" + #define WALLETS_FOLDER_NAME "wallets" #define APP_CONFIG_FOLDER "app_config" #define APP_CONFIG_FILENAME "app_cfg.bin" @@ -31,31 +26,37 @@ #define GENERAL_INTERNAL_ERRROR_INSTANCE "GENERAL_INTERNAL_ERROR: WALLET INSTNACE NOT FOUND" #define GENERAL_INTERNAL_ERRROR_INIT "Failed to intialize library" -//TODO: global object, subject to refactoring +//TODO: global objects, subject to refactoring wallets_manager gwm; std::atomic initialized(false); std::atomic gjobs_counter(1); std::map gjobs; epee::critical_section gjobs_lock; +std::string gconfig_folder; namespace plain_wallet { typedef epee::json_rpc::response error_response; - std::string get_bundle_root_dir() + std::string get_bundle_working_dir() { -#ifdef WIN32 - return boost::dll::program_location().parent_path().string(); -#elif IOS_BUILD - char* env = getenv("HOME"); - return env ? env : ""; -#elif ANDROID_BUILD - /// data/data/com.zano_mobile/files - return "/data/data/" ANDROID_PACKAGE_NAME; -#else - return ""; -#endif + return gconfig_folder; +// #ifdef WIN32 +// return boost::dll::program_location().parent_path().string(); +// #elif IOS_BUILD +// char* env = getenv("HOME"); +// return env ? env : ""; +// #elif ANDROID_BUILD +// /// data/data/com.zano_mobile/files +// return "/data/data/" ANDROID_PACKAGE_NAME; +// #else +// return ""; +// #endif + } + void set_bundle_working_dir(const std::string& dir) + { + gconfig_folder = dir; } std::string get_wallets_folder() @@ -63,7 +64,7 @@ namespace plain_wallet #ifdef WIN32 return ""; #else - std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + WALLETS_FOLDER_NAME + "/"; + std::string path = get_bundle_working_dir() + "/" + WALLETS_FOLDER_NAME + "/"; return path; #endif // WIN32 } @@ -73,7 +74,7 @@ namespace plain_wallet #ifdef WIN32 return ""; #else - std::string path = get_bundle_root_dir() + "/" + HOME_FOLDER + "/" + APP_CONFIG_FOLDER + "/"; + std::string path = get_bundle_working_dir() + "/" + APP_CONFIG_FOLDER + "/"; return path; #endif // WIN32 } @@ -82,8 +83,8 @@ namespace plain_wallet void initialize_logs(int log_level) { - std::string log_dir = get_bundle_root_dir(); - log_dir += "/" HOME_FOLDER; + std::string log_dir = get_bundle_working_dir(); + log_dir += "/" LOGS_FOLDER; log_space::get_set_need_thread_id(true, true); log_space::log_singletone::enable_channels("core,currency_protocol,tx_pool,p2p,wallet"); @@ -101,7 +102,7 @@ namespace plain_wallet return "{}"; } - std::string init(const std::string& ip, const std::string& port, int log_level) + std::string init(const std::string& ip, const std::string& port, const std::string& working_dir, int log_level) { if (initialized) { @@ -110,7 +111,7 @@ namespace plain_wallet ok_response.result.return_code = API_RETURN_CODE_ALREADY_EXISTS; return epee::serialization::store_t_to_json(ok_response); } - + set_bundle_working_dir(working_dir); initialize_logs(log_level); std::string argss_1 = std::string("--remote-node=") + ip + ":" + port; diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index 45abefde..0e964697 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -10,7 +10,7 @@ namespace plain_wallet { typedef int64_t hwallet; - std::string init(const std::string& ip, const std::string& port, int log_level); + std::string init(const std::string& ip, const std::string& port, const std::string& working_dir, int log_level); std::string set_log_level(int log_level); std::string get_version(); std::string get_wallet_files(); diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index 00f1047d..ad31d0f1 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -2,6 +2,7 @@ // Distributed under the MIT/X11 software license, see the accompanying // file COPYING or http://www.opensource.org/licenses/mit-license.php. +#include #include #include #include @@ -30,7 +31,7 @@ struct try_pull_result_open_response void run_plain_wallet_api_test() { LOG_PRINT_L0("Creating instance..."); - std::string s = plain_wallet::init("195.201.107.230", "11211", 1); + std::string s = plain_wallet::init("195.201.107.230", "11211", boost::dll::program_location().parent_path().string(), 1); std::string key = plain_wallet::generate_random_key(10); std::string test_data = "1234567890 test test ";