diff --git a/src/common/util.cpp b/src/common/util.cpp index 6fa15854..f5d4baa9 100644 --- a/src/common/util.cpp +++ b/src/common/util.cpp @@ -695,4 +695,60 @@ std::string get_nix_version_display_string() return true; } + //this code was taken from https://stackoverflow.com/a/8594696/5566653 + //credits goes to @nijansen: https://stackoverflow.com/users/1056003/nijansen + bool copy_dir( boost::filesystem::path const & source, boost::filesystem::path const & destination) + { + namespace fs = boost::filesystem; + try + { + // Check whether the function call is valid + if (!fs::exists(source) ||!fs::is_directory(source)) + { + LOG_ERROR("Source directory " << source.string() << " does not exist or is not a directory."); + return false; + } + if (!fs::exists(destination)) + { + if (!fs::create_directory(destination)) + { + LOG_ERROR("Unable to create destination directory" << destination.string()); + return false; + } + } + // Create the destination directory + } + catch (fs::filesystem_error const & e) + { + LOG_ERROR("Exception: " << e.what()); + return false; + } + // Iterate through the source directory + for (fs::directory_iterator file(source); file != fs::directory_iterator(); ++file) + { + try + { + fs::path current(file->path()); + if (fs::is_directory(current)) + { + // Found directory: Recursion + if (!copy_dir(current, destination / current.filename())) + { + return false; + } + } + else + { + // Found file: Copy + fs::copy_file( current, destination / current.filename()); + } + } + catch (fs::filesystem_error const & e) + { + LOG_ERROR("Exception: " << e.what()); + } + } + return true; + } + } // namespace tools diff --git a/src/common/util.h b/src/common/util.h index 1f31d263..6b683082 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -30,6 +30,7 @@ namespace tools std::string get_default_user_dir(); std::string get_current_username(); std::string get_os_version_string(); + bool copy_dir(boost::filesystem::path const & source, boost::filesystem::path const & destination); bool check_remote_client_version(const std::string& client_ver); bool create_directories_if_necessary(const std::string& path); diff --git a/src/wallet/plain_wallet_api.cpp b/src/wallet/plain_wallet_api.cpp index 259fa4cb..90b34f17 100644 --- a/src/wallet/plain_wallet_api.cpp +++ b/src/wallet/plain_wallet_api.cpp @@ -324,6 +324,31 @@ namespace plain_wallet return epee::serialization::store_t_to_json(sl); } + std::string get_export_private_info(const std::string& target_dir) + { + const std::string src_folder_path = get_bundle_working_dir(); + boost::system::error_code ec; + const std::string full_target_path = target_dir + "/Zano_export" + std::to_string(epee::misc_utils::get_tick_count()); + boost::filesystem::create_directory(full_target_path, ec); + if (ec) + { + LOG_ERROR("Failed to create target directory"); + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + ok_response.result.return_code = API_RETURN_CODE_FAIL; + return epee::serialization::store_t_to_json(ok_response); + } + if(!tools::copy_dir(src_folder_path, full_target_path)) + { + LOG_ERROR("Failed to copy target directory"); + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + ok_response.result.return_code = API_RETURN_CODE_FAIL; + return epee::serialization::store_t_to_json(ok_response); + } + epee::json_rpc::response ok_response = AUTO_VAL_INIT(ok_response); + ok_response.result.return_code = API_RETURN_CODE_OK; + return epee::serialization::store_t_to_json(ok_response); + } + std::string delete_wallet(const std::string& file_name) { std::string wallet_files_path = get_wallets_folder(); diff --git a/src/wallet/plain_wallet_api.h b/src/wallet/plain_wallet_api.h index c938ff30..610a96a3 100644 --- a/src/wallet/plain_wallet_api.h +++ b/src/wallet/plain_wallet_api.h @@ -15,6 +15,7 @@ namespace plain_wallet std::string set_log_level(int log_level); std::string get_version(); std::string get_wallet_files(); + std::string get_export_private_info(const std::string& target_dir); std::string delete_wallet(const std::string& file_name); std::string get_address_info(const std::string& addr); diff --git a/tests/core_tests/chaingen_helpers.h b/tests/core_tests/chaingen_helpers.h index 2e35652e..56cf4696 100644 --- a/tests/core_tests/chaingen_helpers.h +++ b/tests/core_tests/chaingen_helpers.h @@ -8,6 +8,7 @@ #include "currency_core/miner.h" #include "wallet/wallet2.h" #include "test_core_time.h" +#include "chaingen.h" // chaingen-independent helpers that may be used outside of core_tests (for ex. in functional_tests) diff --git a/tests/functional_tests/core_concurrency_test.cpp b/tests/functional_tests/core_concurrency_test.cpp index 52ff1b8c..42dd7d9a 100644 --- a/tests/functional_tests/core_concurrency_test.cpp +++ b/tests/functional_tests/core_concurrency_test.cpp @@ -26,7 +26,7 @@ std::atomic test_core_time::m_time_shift; #include "../core_tests/chaingen_helpers.h" #include "../core_tests/core_state_helper.h" -#define TESTS_DEFAULT_FEE TX_DEFAULT_FEE +//#define TESTS_DEFAULT_FEE TX_DEFAULT_FEE static std::atomic s_generated_money_total(0); // TODO: consiger changing to boost::multiprecision::uint128_t static size_t s_wallets_total_count = 10; // total number of wallet that will be randomly used to generate transactions @@ -40,8 +40,8 @@ typedef std::vector cct_events_t; typedef std::vector cct_accounts_t; typedef std::vector> cct_wallets_t; -static const std::vector empty_extra; -static const std::vector empty_attachment; +//static const std::vector empty_extra; +//static const std::vector empty_attachment; bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector& txs, const currency::account_public_address& miner_addr, currency::block& result) { diff --git a/tests/functional_tests/plain_wallet_tests.cpp b/tests/functional_tests/plain_wallet_tests.cpp index ad31d0f1..457dcefc 100644 --- a/tests/functional_tests/plain_wallet_tests.cpp +++ b/tests/functional_tests/plain_wallet_tests.cpp @@ -32,6 +32,7 @@ void run_plain_wallet_api_test() { LOG_PRINT_L0("Creating instance..."); std::string s = plain_wallet::init("195.201.107.230", "11211", boost::dll::program_location().parent_path().string(), 1); + s = plain_wallet::get_export_private_info("E:\\tmp\\check_export"); std::string key = plain_wallet::generate_random_key(10); std::string test_data = "1234567890 test test ";