forked from lthn/blockchain
implemented export of mobile app data
This commit is contained in:
parent
0ce0d49641
commit
1c92def934
7 changed files with 88 additions and 3 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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<view::api_responce_return_code, epee::json_rpc::dummy_error> 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<view::api_responce_return_code, epee::json_rpc::dummy_error> 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<view::api_responce_return_code, epee::json_rpc::dummy_error> 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();
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ std::atomic<int64_t> 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<uint64_t> 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_event_t> cct_events_t;
|
|||
typedef std::vector<currency::account_base> cct_accounts_t;
|
||||
typedef std::vector<std::shared_ptr<tools::wallet2>> cct_wallets_t;
|
||||
|
||||
static const std::vector<currency::extra_v> empty_extra;
|
||||
static const std::vector<currency::attachment_v> empty_attachment;
|
||||
//static const std::vector<currency::extra_v> empty_extra;
|
||||
//static const std::vector<currency::attachment_v> empty_attachment;
|
||||
|
||||
bool create_block_template_manually(const currency::block& prev_block, boost::multiprecision::uint128_t already_generated_coins, const std::vector<const currency::transaction*>& txs, const currency::account_public_address& miner_addr, currency::block& result)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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 ";
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue