1
0
Fork 0
forked from lthn/blockchain

bundle working folder now passed throught configuration

This commit is contained in:
cryptozoidberg 2020-03-26 04:34:09 +01:00
parent 324673c1d3
commit 7d99128a21
No known key found for this signature in database
GPG key ID: 22DEB97A54C6FDEC
3 changed files with 31 additions and 29 deletions

View file

@ -3,7 +3,6 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <boost/dll.hpp>
#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<bool> initialized(false);
std::atomic<uint64_t> gjobs_counter(1);
std::map<uint64_t, std::string> gjobs;
epee::critical_section gjobs_lock;
std::string gconfig_folder;
namespace plain_wallet
{
typedef epee::json_rpc::response<epee::json_rpc::dummy_result, error> 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;

View file

@ -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();

View file

@ -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 <boost/dll.hpp>
#include <iostream>
#include <vector>
#include <algorithm>
@ -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 ";