From 56ee439642abf7eb34139372b29cf073404cb6c3 Mon Sep 17 00:00:00 2001 From: woodser Date: Sun, 5 Jan 2020 17:27:42 -0500 Subject: [PATCH] add open_wallet() test hack in get_restore_height() --- src/wallet/monero_wallet_core.cpp | 16 ++++++++++++++-- src/wallet/monero_wallet_core.h | 5 +++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 06e1e9d..5792fba 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -812,6 +812,7 @@ namespace monero { MTRACE("open_wallet(...buffers...)"); cout << "open_wallet(...buffers...)" << endl; monero_wallet_core* wallet = new monero_wallet_core(); + wallet->temp_http_client = http_client; if (http_client == nullptr) wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); else wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, http_client)); wallet->m_w2->load("", password, keys_buffer, cache_buffer); @@ -825,6 +826,7 @@ namespace monero { monero_wallet_core* monero_wallet_core::create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language, epee::net_utils::http::abstract_http_client *http_client) { MTRACE("create_wallet_random(path, password, network_type, daemon_connection, language)"); monero_wallet_core* wallet = new monero_wallet_core(); + wallet->temp_http_client = http_client; if (http_client == nullptr) wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); else wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true, http_client)); wallet->set_daemon_connection(daemon_connection); @@ -841,6 +843,8 @@ namespace monero { cout << "create_wallet_from_mnemonic(path, password, mnemonic, network_type, daemon_connection, restore_height)" << endl; monero_wallet_core* wallet = new monero_wallet_core(); + wallet->temp_http_client = http_client; + // validate mnemonic and get recovery key and language crypto::secret_key recovery_key; string language; @@ -1125,6 +1129,14 @@ namespace monero { } uint64_t monero_wallet_core::get_restore_height() const { + + cout << "TESTING RE-OPEN WALLET IN GET_RESTORE_HEIGHT" << endl; + string cache_buffer = get_cache_file_buffer("supersecretpassword123"); + string keys_buffer = get_keys_file_buffer("supersecretpassword123", false); + //http_client_wasm* http_client = new http_client_wasm(); + monero_wallet_core* wallet = monero_wallet_core::open_wallet("supersecretpassword123", monero_network_type::STAGENET, keys_buffer, cache_buffer, *get_daemon_connection(), temp_http_client); + cout << "New wallet can be created from file data!!!" << endl; + return m_w2->get_refresh_from_block_height(); } @@ -3187,7 +3199,7 @@ namespace monero { m_w2->store_to(path, password); } - std::string monero_wallet_core::get_keys_file_buffer(const epee::wipeable_string& password, bool watch_only) { + std::string monero_wallet_core::get_keys_file_buffer(const epee::wipeable_string& password, bool watch_only) const { wallet2::keys_file_data keys_file_data = {}; bool r = m_w2->get_keys_file_data(password, watch_only, keys_file_data); std::string buf; @@ -3195,7 +3207,7 @@ namespace monero { return buf; } - std::string monero_wallet_core::get_cache_file_buffer(const epee::wipeable_string& password) { + std::string monero_wallet_core::get_cache_file_buffer(const epee::wipeable_string& password) const { wallet2::cache_file_data cache_file_data = {}; bool r = m_w2->get_cache_file_data(password, cache_file_data); diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index ba080e2..6bf0c3c 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -281,12 +281,13 @@ namespace monero { /** * Wallet import and export using buffers and not the file system. */ - std::string get_keys_file_buffer(const epee::wipeable_string& password, bool watch_only); - std::string get_cache_file_buffer(const epee::wipeable_string& password); + std::string get_keys_file_buffer(const epee::wipeable_string& password, bool watch_only) const; + std::string get_cache_file_buffer(const epee::wipeable_string& password) const; // --------------------------------- PRIVATE -------------------------------- private: + epee::net_utils::http::abstract_http_client* temp_http_client; friend struct wallet2_listener; unique_ptr m_w2; // internal wallet implementation unique_ptr m_w2_listener; // internal wallet implementation listener