diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 516a912..eb81243 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -50,7 +50,7 @@ * Parts of this file are originally copyright (c) 2012-2013 The Cryptonote developers */ -#include "monero_wallet_w2.h" +#include "monero_wallet_core.h" #include "utils/monero_utils.h" #include @@ -664,7 +664,7 @@ namespace monero { * @param wallet provides context to notify external listeners * @param wallet2 provides source notifications which this listener propagates to external listeners */ - wallet2_listener(monero_wallet_w2& wallet, tools::wallet2& m_w2) : m_wallet(wallet), m_w2(m_w2) { + wallet2_listener(monero_wallet_core& wallet, tools::wallet2& m_w2) : m_wallet(wallet), m_w2(m_w2) { this->m_sync_start_height = boost::none; this->m_sync_end_height = boost::none; } @@ -768,7 +768,7 @@ namespace monero { } private: - monero_wallet_w2& m_wallet; // wallet to provide context for notifications + monero_wallet_core& m_wallet; // wallet to provide context for notifications tools::wallet2& m_w2; // internal wallet implementation to listen to boost::optional m_sync_start_height; boost::optional m_sync_end_height; @@ -789,7 +789,7 @@ namespace monero { // ---------------------------- WALLET MANAGEMENT --------------------------- - bool monero_wallet_w2::wallet_exists(const string& path) { + bool monero_wallet_core::wallet_exists(const string& path) { MTRACE("wallet_exists(" << path << ")"); bool key_file_exists; bool wallet_file_exists; @@ -797,9 +797,9 @@ namespace monero { return wallet_file_exists; } - monero_wallet_w2* monero_wallet_w2::open_wallet(const string& path, const string& password, const monero_network_type network_type) { + monero_wallet_core* monero_wallet_core::open_wallet(const string& path, const string& password, const monero_network_type network_type) { MTRACE("open_wallet(" << path << ", " << password << ", " << network_type << ")"); - monero_wallet_w2* wallet = new monero_wallet_w2(); + monero_wallet_core* wallet = new monero_wallet_core(); wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); wallet->m_w2->load(path, password); wallet->m_w2->init(""); @@ -807,15 +807,10 @@ namespace monero { return wallet; } - monero_wallet_w2* monero_wallet_w2::create_wallet_random(const string& path, const string& password) { - MTRACE("create_wallet_random(path, password)"); - throw runtime_error("Not implemented"); - } - // TODO: ensure that wallet does not already exist - monero_wallet_w2* monero_wallet_w2::create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language) { + 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) { MTRACE("create_wallet_random(path, password, network_type, daemon_connection, language)"); - monero_wallet_w2* wallet = new monero_wallet_w2(); + monero_wallet_core* wallet = new monero_wallet_core(); wallet->m_w2 = unique_ptr(new tools::wallet2(static_cast(network_type), 1, true)); wallet->set_daemon_connection(daemon_connection); wallet->m_w2->set_seed_language(language); @@ -826,14 +821,14 @@ namespace monero { return wallet; } - monero_wallet_w2* monero_wallet_w2::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic) { + monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic) { MTRACE("create_wallet_from_mnemonic(path, password, network_type, mnemonic)"); throw runtime_error("Not implemented"); } - monero_wallet_w2* monero_wallet_w2::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height) { + monero_wallet_core* monero_wallet_core::create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height) { MTRACE("create_wallet_from_mnemonic(path, password, mnemonic, network_type, daemon_connection, restore_height)"); - monero_wallet_w2* wallet = new monero_wallet_w2(); + monero_wallet_core* wallet = new monero_wallet_core(); // validate mnemonic and get recovery key and language crypto::secret_key recoveryKey; @@ -852,19 +847,19 @@ namespace monero { return wallet; } - monero_wallet_w2* monero_wallet_w2::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key) { + monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key) { MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type)"); throw runtime_error("Not implemented"); } - monero_wallet_w2* monero_wallet_w2::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height) { + monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height) { MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height)"); throw runtime_error("Not implemented"); } - monero_wallet_w2* monero_wallet_w2::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language) { + monero_wallet_core* monero_wallet_core::create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language) { MTRACE("create_wallet_from_keys(path, password, address, view_key, spend_key, network_type, daemon_connection, restore_height, language)"); - monero_wallet_w2* wallet = new monero_wallet_w2(); + monero_wallet_core* wallet = new monero_wallet_core(); // validate and parse address cryptonote::address_parse_info info; @@ -920,14 +915,14 @@ namespace monero { return wallet; } - monero_wallet_w2::~monero_wallet_w2() { - MTRACE("~monero_wallet_w2()"); + monero_wallet_core::~monero_wallet_core() { + MTRACE("~monero_wallet_core()"); close(false); } // ----------------------------- WALLET METHODS ----------------------------- - void monero_wallet_w2::set_daemon_connection(const string& uri, const string& username, const string& password) { + void monero_wallet_core::set_daemon_connection(const string& uri, const string& username, const string& password) { MTRACE("set_daemon_connection(" << uri << ", " << username << ", " << password << ")"); // prepare uri, login, and is_trusted for wallet2 @@ -942,12 +937,12 @@ namespace monero { is_connected(); // update m_is_connected cache // TODO: better naming? } - void monero_wallet_w2::set_daemon_connection(const monero_rpc_connection& connection) { + void monero_wallet_core::set_daemon_connection(const monero_rpc_connection& connection) { set_daemon_connection(connection.m_uri, connection.m_username == boost::none ? "" : connection.m_username.get(), connection.m_password == boost::none ? "" : connection.m_password.get()); } - shared_ptr monero_wallet_w2::get_daemon_connection() const { - MTRACE("monero_wallet_w2::get_daemon_connection()"); + shared_ptr monero_wallet_core::get_daemon_connection() const { + MTRACE("monero_wallet_core::get_daemon_connection()"); if (m_w2->get_daemon_address().empty()) return nullptr; shared_ptr connection = make_shared(); if (!m_w2->get_daemon_address().empty()) connection->m_uri = m_w2->get_daemon_address(); @@ -961,7 +956,7 @@ namespace monero { } // TODO: could return Wallet::ConnectionStatus_Disconnected, Wallet::ConnectionStatus_WrongVersion, Wallet::ConnectionStatus_Connected like wallet.cpp::connected() - bool monero_wallet_w2::is_connected() const { + bool monero_wallet_core::is_connected() const { uint32_t version = 0; m_is_connected = m_w2->check_connection(&version, NULL, DEFAULT_CONNECTION_TIMEOUT_MILLIS); // TODO: should this be updated elsewhere? if (!m_is_connected) return false; @@ -969,79 +964,79 @@ namespace monero { return m_is_connected; } - bool monero_wallet_w2::is_daemon_synced() const { + bool monero_wallet_core::is_daemon_synced() const { if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); uint64_t daemonHeight = get_daemon_height(); return daemonHeight >= get_daemon_max_peer_height() && daemonHeight > 1; } - bool monero_wallet_w2::is_daemon_trusted() const { + bool monero_wallet_core::is_daemon_trusted() const { if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); return m_w2->is_trusted_daemon(); } - bool monero_wallet_w2::is_synced() const { + bool monero_wallet_core::is_synced() const { return m_is_synced; } - monero_version monero_wallet_w2::get_version() const { + monero_version monero_wallet_core::get_version() const { monero_version version; version.m_number = 65552; // same as monero-wallet-rpc v0.15.0.1 release version.m_is_release = false; // TODO: could pull from MONERO_VERSION_IS_RELEASE in version.cpp return version; } - string monero_wallet_w2::get_path() const { + string monero_wallet_core::get_path() const { return m_w2->path(); } - monero_network_type monero_wallet_w2::get_network_type() const { + monero_network_type monero_wallet_core::get_network_type() const { return static_cast(m_w2->nettype()); } - string monero_wallet_w2::get_language() const { + string monero_wallet_core::get_language() const { return m_w2->get_seed_language(); } - vector monero_wallet_w2::get_languages() const { + vector monero_wallet_core::get_languages() const { vector languages; crypto::ElectrumWords::get_language_list(languages, true); return languages; } - string monero_wallet_w2::get_mnemonic() const { + string monero_wallet_core::get_mnemonic() const { epee::wipeable_string wipeable_mnemonic; m_w2->get_seed(wipeable_mnemonic); return string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); } - string monero_wallet_w2::get_public_view_key() const { + string monero_wallet_core::get_public_view_key() const { MTRACE("get_private_view_key()"); return epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_account_address.m_view_public_key); } - string monero_wallet_w2::get_private_view_key() const { + string monero_wallet_core::get_private_view_key() const { MTRACE("get_private_view_key()"); return epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_view_secret_key); } - string monero_wallet_w2::get_public_spend_key() const { + string monero_wallet_core::get_public_spend_key() const { MTRACE("get_public_spend_key()"); return epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_account_address.m_spend_public_key); } - string monero_wallet_w2::get_private_spend_key() const { + string monero_wallet_core::get_private_spend_key() const { MTRACE("get_private_spend_key()"); string spend_key = epee::string_tools::pod_to_hex(m_w2->get_account().get_keys().m_spend_secret_key); if (spend_key == "0000000000000000000000000000000000000000000000000000000000000000") spend_key = ""; return spend_key; } - string monero_wallet_w2::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { + string monero_wallet_core::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { return m_w2->get_subaddress_as_str({account_idx, subaddress_idx}); } - monero_subaddress monero_wallet_w2::get_address_index(const string& address) const { + monero_subaddress monero_wallet_core::get_address_index(const string& address) const { MTRACE("get_address_index(" << address << ")"); // validate address @@ -1062,7 +1057,7 @@ namespace monero { return subaddress; } - monero_integrated_address monero_wallet_w2::get_integrated_address(const string& standard_address, const string& payment_id) const { + monero_integrated_address monero_wallet_core::get_integrated_address(const string& standard_address, const string& payment_id) const { MTRACE("get_integrated_address(" << standard_address << ", " << payment_id << ")"); // TODO monero-core: this logic is based on wallet_rpc_server::on_make_integrated_address() and should be moved to wallet so this is unecessary for api users @@ -1092,7 +1087,7 @@ namespace monero { } } - monero_integrated_address monero_wallet_w2::decode_integrated_address(const string& integrated_address) const { + monero_integrated_address monero_wallet_core::decode_integrated_address(const string& integrated_address) const { MTRACE("decode_integrated_address(" << integrated_address << ")"); // validate integrated address @@ -1108,19 +1103,19 @@ namespace monero { return result; } - uint64_t monero_wallet_w2::get_height() const { + uint64_t monero_wallet_core::get_height() const { return m_w2->get_blockchain_current_height(); } - uint64_t monero_wallet_w2::get_restore_height() const { + uint64_t monero_wallet_core::get_restore_height() const { return m_w2->get_refresh_from_block_height(); } - void monero_wallet_w2::set_restore_height(uint64_t restore_height) { + void monero_wallet_core::set_restore_height(uint64_t restore_height) { m_w2->set_refresh_from_block_height(restore_height); } - uint64_t monero_wallet_w2::get_daemon_height() const { + uint64_t monero_wallet_core::get_daemon_height() const { if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); std::string err; uint64_t result = m_w2->get_daemon_blockchain_height(err); @@ -1128,7 +1123,7 @@ namespace monero { return result; } - uint64_t monero_wallet_w2::get_daemon_max_peer_height() const { + uint64_t monero_wallet_core::get_daemon_max_peer_height() const { if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); std::string err; uint64_t result = m_w2->get_daemon_blockchain_target_height(err); @@ -1137,30 +1132,30 @@ namespace monero { return result; } - void monero_wallet_w2::add_listener(monero_wallet_listener& listener) { + void monero_wallet_core::add_listener(monero_wallet_listener& listener) { MTRACE("add_listener()"); m_listeners.insert(&listener); m_w2_listener->update_listening(); } - void monero_wallet_w2::remove_listener(monero_wallet_listener& listener) { + void monero_wallet_core::remove_listener(monero_wallet_listener& listener) { MTRACE("remove_listener()"); m_listeners.erase(&listener); m_w2_listener->update_listening(); } - set monero_wallet_w2::get_listeners() { + set monero_wallet_core::get_listeners() { MTRACE("get_listeners()"); return m_listeners; } - monero_sync_result monero_wallet_w2::sync() { + monero_sync_result monero_wallet_core::sync() { MTRACE("sync()"); if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); return lock_and_sync(); } - monero_sync_result monero_wallet_w2::sync(monero_sync_listener& listener) { + monero_sync_result monero_wallet_core::sync(monero_sync_listener& listener) { MTRACE("sync(listener)"); if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); @@ -1178,13 +1173,13 @@ namespace monero { return result; } - monero_sync_result monero_wallet_w2::sync(uint64_t start_height) { + monero_sync_result monero_wallet_core::sync(uint64_t start_height) { MTRACE("sync(" << start_height << ")"); if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); return lock_and_sync(start_height); } - monero_sync_result monero_wallet_w2::sync(uint64_t start_height, monero_sync_listener& listener) { + monero_sync_result monero_wallet_core::sync(uint64_t start_height, monero_sync_listener& listener) { MTRACE("sync(" << start_height << ", listener)"); if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); @@ -1205,7 +1200,7 @@ namespace monero { /** * Start automatic syncing as its own thread. */ - void monero_wallet_w2::start_syncing() { + void monero_wallet_core::start_syncing() { if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); if (!m_syncing_enabled) { m_syncing_enabled = true; @@ -1216,13 +1211,13 @@ namespace monero { /** * Stop automatic syncing as its own thread. */ - void monero_wallet_w2::stop_syncing() { + void monero_wallet_core::stop_syncing() { if (!m_syncing_thread_done) { m_syncing_enabled = false; } } - void monero_wallet_w2::rescan_spent() { + void monero_wallet_core::rescan_spent() { MTRACE("rescan_spent()"); if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); if (!is_daemon_trusted()) throw runtime_error("Rescan spent can only be used with a trusted daemon"); @@ -1230,7 +1225,7 @@ namespace monero { } // TODO: support arguments bool hard, bool refresh = true, bool keep_key_images = false - void monero_wallet_w2::rescan_blockchain() { + void monero_wallet_core::rescan_blockchain() { MTRACE("rescan_blockchain()"); if (!m_is_connected) throw runtime_error("Wallet is not connected to daemon"); m_rescan_on_sync = true; @@ -1239,35 +1234,35 @@ namespace monero { // isMultisigImportNeeded - uint64_t monero_wallet_w2::get_balance() const { + uint64_t monero_wallet_core::get_balance() const { return m_w2->balance_all(STRICT); } - uint64_t monero_wallet_w2::get_balance(uint32_t account_idx) const { + uint64_t monero_wallet_core::get_balance(uint32_t account_idx) const { return m_w2->balance(account_idx, STRICT); } - uint64_t monero_wallet_w2::get_balance(uint32_t account_idx, uint32_t subaddress_idx) const { + uint64_t monero_wallet_core::get_balance(uint32_t account_idx, uint32_t subaddress_idx) const { map balance_per_subaddress = m_w2->balance_per_subaddress(account_idx, STRICT); auto iter = balance_per_subaddress.find(subaddress_idx); return iter == balance_per_subaddress.end() ? 0 : iter->second; } - uint64_t monero_wallet_w2::get_unlocked_balance() const { + uint64_t monero_wallet_core::get_unlocked_balance() const { return m_w2->unlocked_balance_all(STRICT); } - uint64_t monero_wallet_w2::get_unlocked_balance(uint32_t account_idx) const { + uint64_t monero_wallet_core::get_unlocked_balance(uint32_t account_idx) const { return m_w2->unlocked_balance(account_idx, STRICT); } - uint64_t monero_wallet_w2::get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const { + uint64_t monero_wallet_core::get_unlocked_balance(uint32_t account_idx, uint32_t subaddress_idx) const { map> unlocked_balance_per_subaddress = m_w2->unlocked_balance_per_subaddress(account_idx, STRICT); auto iter = unlocked_balance_per_subaddress.find(subaddress_idx); return iter == unlocked_balance_per_subaddress.end() ? 0 : iter->second.first; } - vector monero_wallet_w2::get_accounts(bool include_subaddresses, const string& tag) const { + vector monero_wallet_core::get_accounts(bool include_subaddresses, const string& tag) const { MTRACE("get_accounts(" << include_subaddresses << ", " << tag << ")"); // need transfers to inform if subaddresses used @@ -1289,7 +1284,7 @@ namespace monero { return accounts; } - monero_account monero_wallet_w2::get_account(uint32_t account_idx, bool include_subaddresses) const { + monero_account monero_wallet_core::get_account(uint32_t account_idx, bool include_subaddresses) const { MTRACE("get_account(" << account_idx << ", " << include_subaddresses << ")"); // need transfers to inform if subaddresses used @@ -1306,7 +1301,7 @@ namespace monero { return account; } - monero_account monero_wallet_w2::create_account(const string& label) { + monero_account monero_wallet_core::create_account(const string& label) { MTRACE("create_account(" << label << ")"); // create account @@ -1321,7 +1316,7 @@ namespace monero { return account; } - vector monero_wallet_w2::get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const { + vector monero_wallet_core::get_subaddresses(const uint32_t account_idx, const vector& subaddress_indices) const { MTRACE("get_subaddresses(" << account_idx << ", ...)"); MTRACE("Subaddress indices size: " << subaddress_indices.size()); @@ -1332,7 +1327,7 @@ namespace monero { // get_subaddresses - monero_subaddress monero_wallet_w2::create_subaddress(const uint32_t account_idx, const string& label) { + monero_subaddress monero_wallet_core::create_subaddress(const uint32_t account_idx, const string& label) { MTRACE("create_subaddress(" << account_idx << ", " << label << ")"); // create subaddress @@ -1352,11 +1347,11 @@ namespace monero { return subaddress; } - vector> monero_wallet_w2::get_txs() const { + vector> monero_wallet_core::get_txs() const { return get_txs(monero_tx_query()); } - vector> monero_wallet_w2::get_txs(const monero_tx_query& query) const { + vector> monero_wallet_core::get_txs(const monero_tx_query& query) const { MTRACE("get_txs(query)"); // copy and normalize tx query @@ -1467,8 +1462,8 @@ namespace monero { return txs; } - vector> monero_wallet_w2::get_transfers(const monero_transfer_query& query) const { - MTRACE("monero_wallet_w2::get_transfers(query)"); + vector> monero_wallet_core::get_transfers(const monero_transfer_query& query) const { + MTRACE("monero_wallet_core::get_transfers(query)"); // LOG query if (query.m_tx_query != boost::none) { @@ -1608,13 +1603,13 @@ namespace monero { tx->m_block.get()->m_txs.erase(std::remove(tx->m_block.get()->m_txs.begin(), tx->m_block.get()->m_txs.end(), tx), tx->m_block.get()->m_txs.end()); // TODO, no way to use const_iterator? } } - MTRACE("monero_wallet_w2.cpp get_transfers() returning " << transfers.size() << " transfers"); + MTRACE("monero_wallet_core.cpp get_transfers() returning " << transfers.size() << " transfers"); return transfers; } - vector> monero_wallet_w2::get_outputs(const monero_output_query& query) const { - MTRACE("monero_wallet_w2::get_outputs(query)"); + vector> monero_wallet_core::get_outputs(const monero_output_query& query) const { + MTRACE("monero_wallet_core::get_outputs(query)"); // print query MTRACE("Output query: " << query.serialize()); @@ -1688,11 +1683,11 @@ namespace monero { return vouts; } - string monero_wallet_w2::get_outputs_hex() const { + string monero_wallet_core::get_outputs_hex() const { return epee::string_tools::buff_to_hex_nodelimer(m_w2->export_outputs_to_str(true)); } - int monero_wallet_w2::import_outputs_hex(const string& outputs_hex) { + int monero_wallet_core::import_outputs_hex(const string& outputs_hex) { // validate and parse hex data cryptonote::blobdata blob; @@ -1704,8 +1699,8 @@ namespace monero { return m_w2->import_outputs_from_str(blob); } - vector> monero_wallet_w2::get_key_images() const { - MTRACE("monero_wallet_w2::get_key_images()"); + vector> monero_wallet_core::get_key_images() const { + MTRACE("monero_wallet_core::get_key_images()"); // build key images from wallet2 types vector> key_images; @@ -1719,8 +1714,8 @@ namespace monero { return key_images; } - shared_ptr monero_wallet_w2::import_key_images(const vector>& key_images) { - MTRACE("monero_wallet_w2::import_key_images()"); + shared_ptr monero_wallet_core::import_key_images(const vector>& key_images) { + MTRACE("monero_wallet_core::import_key_images()"); // validate and prepare key images for wallet2 std::vector> ski; @@ -1746,17 +1741,17 @@ namespace monero { return result; } - monero_tx_set monero_wallet_w2::create_tx(monero_send_request& request) { + monero_tx_set monero_wallet_core::create_tx(monero_send_request& request) { if (request.m_can_split != boost::none && request.m_can_split.get()) throw runtime_error("Cannot request split transactions with create_tx() which prevents splitting; use create_txs() instead"); request.m_can_split = false; return create_txs(request); } - monero_tx_set monero_wallet_w2::create_tx(uint32_t account_index, string address, uint64_t amount) { + monero_tx_set monero_wallet_core::create_tx(uint32_t account_index, string address, uint64_t amount) { return create_tx(account_index, address, amount, monero_send_priority::NORMAL); } - monero_tx_set monero_wallet_w2::create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority) { + monero_tx_set monero_wallet_core::create_tx(int account_index, string address, uint64_t amount, monero_send_priority priority) { monero_send_request req; req.m_account_index = account_index; req.m_destinations.push_back(make_shared(address, amount)); @@ -1764,7 +1759,7 @@ namespace monero { return create_tx(req); } - monero_tx_set monero_wallet_w2::create_txs(monero_send_request& request) { + monero_tx_set monero_wallet_core::create_txs(monero_send_request& request) { // modify request to not relay boost::optional requested_do_not_relay = request.m_do_not_relay; @@ -1781,17 +1776,17 @@ namespace monero { return tx_set; } - string monero_wallet_w2::relay_tx(const string& tx_metadata) { + string monero_wallet_core::relay_tx(const string& tx_metadata) { vector tx_metadatas; tx_metadatas.push_back(tx_metadata); return relay_txs(tx_metadatas)[0]; } - string monero_wallet_w2::relay_tx(const monero_tx_wallet& tx) { + string monero_wallet_core::relay_tx(const monero_tx_wallet& tx) { return relay_tx(tx.m_metadata.get()); } - vector monero_wallet_w2::relay_txs(const vector& tx_metadatas) { + vector monero_wallet_core::relay_txs(const vector& tx_metadatas) { MTRACE("relay_txs()"); // relay each metadata as a tx @@ -1829,24 +1824,24 @@ namespace monero { return tx_ids; } - vector monero_wallet_w2::relay_txs(const vector>& txs) { + vector monero_wallet_core::relay_txs(const vector>& txs) { vector tx_hexes; for (const shared_ptr& tx : txs) tx_hexes.push_back(tx->m_metadata.get()); return relay_txs(tx_hexes); } - monero_tx_set monero_wallet_w2::send(const monero_send_request& request) { + monero_tx_set monero_wallet_core::send(const monero_send_request& request) { if (request.m_can_split != boost::none && request.m_can_split.get()) throw runtime_error("Cannot request split transactions with send() which prevents splitting; use sendSplit() instead"); monero_send_request copy = request.copy(); copy.m_can_split = false; return send_split(copy); } - monero_tx_set monero_wallet_w2::send(uint32_t account_index, string address, uint64_t amount) { + monero_tx_set monero_wallet_core::send(uint32_t account_index, string address, uint64_t amount) { return send(account_index, address, amount, monero_send_priority::NORMAL); } - monero_tx_set monero_wallet_w2::send(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority) { + monero_tx_set monero_wallet_core::send(uint32_t account_index, string address, uint64_t amount, monero_send_priority priority) { monero_send_request req; req.m_account_index = account_index; req.m_destinations.push_back(make_shared(address, amount)); @@ -1854,8 +1849,8 @@ namespace monero { return send(req); } - monero_tx_set monero_wallet_w2::send_split(const monero_send_request& request) { - MTRACE("monero_wallet_w2::send_split(request)"); + monero_tx_set monero_wallet_core::send_split(const monero_send_request& request) { + MTRACE("monero_wallet_core::send_split(request)"); MTRACE("monero_send_request: " << request.serialize()); // validate request @@ -1973,7 +1968,7 @@ namespace monero { return tx_set; } - vector monero_wallet_w2::sweep_unlocked(const monero_send_request& request) { + vector monero_wallet_core::sweep_unlocked(const monero_send_request& request) { // validate request if (request.m_destinations.size() != 1) throw runtime_error("Must specify exactly one destination to sweep to"); @@ -2035,7 +2030,7 @@ namespace monero { return tx_sets; } - monero_tx_set monero_wallet_w2::sweep_account(const monero_send_request& request) { + monero_tx_set monero_wallet_core::sweep_account(const monero_send_request& request) { // validate request if (request.m_account_index == boost::none) throw runtime_error("Must specify account index to sweep from"); @@ -2150,7 +2145,7 @@ namespace monero { return tx_set; } - monero_tx_set monero_wallet_w2::sweep_output(const monero_send_request& request) { + monero_tx_set monero_wallet_core::sweep_output(const monero_send_request& request) { MTRACE("sweep_output()"); MTRACE("monero_send_request: " << request.serialize()); @@ -2271,8 +2266,8 @@ namespace monero { return tx_set; } - monero_tx_set monero_wallet_w2::sweep_dust(bool do_not_relay) { - MTRACE("monero_wallet_w2::sweep_dust()"); + monero_tx_set monero_wallet_core::sweep_dust(bool do_not_relay) { + MTRACE("monero_wallet_core::sweep_dust()"); // create transaction to fill std::vector ptx_vector = m_w2->create_unmixable_sweep_transactions(); @@ -2353,7 +2348,7 @@ namespace monero { return tx_set; } - monero_tx_set monero_wallet_w2::parse_tx_set(const monero_tx_set& tx_set) { + monero_tx_set monero_wallet_core::parse_tx_set(const monero_tx_set& tx_set) { // get unsigned and multisig tx sets string unsigned_tx_hex = tx_set.m_unsigned_tx_hex == boost::none ? "" : tx_set.m_unsigned_tx_hex.get(); @@ -2512,11 +2507,11 @@ namespace monero { } } - string monero_wallet_w2::sign(const string& msg) const { + string monero_wallet_core::sign(const string& msg) const { return m_w2->sign(msg); } - bool monero_wallet_w2::verify(const string& msg, const string& address, const string& signature) const { + bool monero_wallet_core::verify(const string& msg, const string& address, const string& signature) const { // validate and parse address or url cryptonote::address_parse_info info; @@ -2541,8 +2536,8 @@ namespace monero { return m_w2->verify(msg, info.address, signature); } - string monero_wallet_w2::get_tx_key(const string& tx_id) const { - MTRACE("monero_wallet_w2::get_tx_key()"); + string monero_wallet_core::get_tx_key(const string& tx_id) const { + MTRACE("monero_wallet_core::get_tx_key()"); // validate and parse tx id hash crypto::hash tx_hash; @@ -2566,8 +2561,8 @@ namespace monero { return std::string(s.data(), s.size()); } - shared_ptr monero_wallet_w2::check_tx_key(const string& tx_id, const string& txKey, const string& address) const { - MTRACE("monero_wallet_w2::check_tx_key()"); + shared_ptr monero_wallet_core::check_tx_key(const string& tx_id, const string& txKey, const string& address) const { + MTRACE("monero_wallet_core::check_tx_key()"); // validate and parse tx id crypto::hash tx_hash; @@ -2616,7 +2611,7 @@ namespace monero { return checkTx; } - string monero_wallet_w2::get_tx_proof(const string& tx_id, const string& address, const string& message) const { + string monero_wallet_core::get_tx_proof(const string& tx_id, const string& address, const string& message) const { // validate and parse tx id hash crypto::hash tx_hash; @@ -2634,8 +2629,8 @@ namespace monero { return m_w2->get_tx_proof(tx_hash, info.address, info.is_subaddress, message); } - shared_ptr monero_wallet_w2::check_tx_proof(const string& tx_id, const string& address, const string& message, const string& signature) const { - MTRACE("monero_wallet_w2::check_tx_proof()"); + shared_ptr monero_wallet_core::check_tx_proof(const string& tx_id, const string& address, const string& message, const string& signature) const { + MTRACE("monero_wallet_core::check_tx_proof()"); // validate and parse tx id crypto::hash tx_hash; @@ -2663,8 +2658,8 @@ namespace monero { return checkTx; } - string monero_wallet_w2::get_spend_proof(const string& tx_id, const string& message) const { - MTRACE("monero_wallet_w2::get_spend_proof()"); + string monero_wallet_core::get_spend_proof(const string& tx_id, const string& message) const { + MTRACE("monero_wallet_core::get_spend_proof()"); // validate and parse tx id crypto::hash tx_hash; @@ -2676,8 +2671,8 @@ namespace monero { return m_w2->get_spend_proof(tx_hash, message); } - bool monero_wallet_w2::check_spend_proof(const string& tx_id, const string& message, const string& signature) const { - MTRACE("monero_wallet_w2::check_spend_proof()"); + bool monero_wallet_core::check_spend_proof(const string& tx_id, const string& message, const string& signature) const { + MTRACE("monero_wallet_core::check_spend_proof()"); // validate and parse tx id crypto::hash tx_hash; @@ -2689,22 +2684,22 @@ namespace monero { return m_w2->check_spend_proof(tx_hash, message, signature); } - string monero_wallet_w2::get_reserve_proof_wallet(const string& message) const { - MTRACE("monero_wallet_w2::get_reserve_proof_wallet()"); + string monero_wallet_core::get_reserve_proof_wallet(const string& message) const { + MTRACE("monero_wallet_core::get_reserve_proof_wallet()"); boost::optional> account_minreserve; return m_w2->get_reserve_proof(account_minreserve, message); } - string monero_wallet_w2::get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const { - MTRACE("monero_wallet_w2::get_reserve_proof_account()"); + string monero_wallet_core::get_reserve_proof_account(uint32_t account_idx, uint64_t amount, const string& message) const { + MTRACE("monero_wallet_core::get_reserve_proof_account()"); boost::optional> account_minreserve; if (account_idx >= m_w2->get_num_subaddress_accounts()) throw runtime_error("Account index is out of bound"); account_minreserve = std::make_pair(account_idx, amount); return m_w2->get_reserve_proof(account_minreserve, message); } - shared_ptr monero_wallet_w2::check_reserve_proof(const string& address, const string& message, const string& signature) const { - MTRACE("monero_wallet_w2::check_reserve_proof()"); + shared_ptr monero_wallet_core::check_reserve_proof(const string& address, const string& message, const string& signature) const { + MTRACE("monero_wallet_core::check_reserve_proof()"); // validate and parse input cryptonote::address_parse_info info; @@ -2723,8 +2718,8 @@ namespace monero { return checkReserve; } - string monero_wallet_w2::get_tx_note(const string& tx_id) const { - MTRACE("monero_wallet_w2::get_tx_note()"); + string monero_wallet_core::get_tx_note(const string& tx_id) const { + MTRACE("monero_wallet_core::get_tx_note()"); cryptonote::blobdata tx_blob; if (!epee::string_tools::parse_hexstr_to_binbuff(tx_id, tx_blob) || tx_blob.size() != sizeof(crypto::hash)) { throw runtime_error("TX ID has invalid format"); @@ -2733,15 +2728,15 @@ namespace monero { return m_w2->get_tx_note(tx_hash); } - vector monero_wallet_w2::get_tx_notes(const vector& tx_ids) const { - MTRACE("monero_wallet_w2::get_tx_notes()"); + vector monero_wallet_core::get_tx_notes(const vector& tx_ids) const { + MTRACE("monero_wallet_core::get_tx_notes()"); vector notes; for (const auto& tx_id : tx_ids) notes.push_back(get_tx_note(tx_id)); return notes; } - void monero_wallet_w2::set_tx_note(const string& tx_id, const string& note) { - MTRACE("monero_wallet_w2::set_tx_note()"); + void monero_wallet_core::set_tx_note(const string& tx_id, const string& note) { + MTRACE("monero_wallet_core::set_tx_note()"); cryptonote::blobdata tx_blob; if (!epee::string_tools::parse_hexstr_to_binbuff(tx_id, tx_blob) || tx_blob.size() != sizeof(crypto::hash)) { throw runtime_error("TX ID has invalid format"); @@ -2750,16 +2745,16 @@ namespace monero { m_w2->set_tx_note(tx_hash, note); } - void monero_wallet_w2::set_tx_notes(const vector& tx_ids, const vector& notes) { - MTRACE("monero_wallet_w2::set_tx_notes()"); + void monero_wallet_core::set_tx_notes(const vector& tx_ids, const vector& notes) { + MTRACE("monero_wallet_core::set_tx_notes()"); if (tx_ids.size() != notes.size()) throw runtime_error("Different amount of txids and notes"); for (int i = 0; i < tx_ids.size(); i++) { set_tx_note(tx_ids[i], notes[i]); } } - vector monero_wallet_w2::get_address_book_entries(const vector& indices) const { - MTRACE("monero_wallet_w2::get_address_book_entries()"); + vector monero_wallet_core::get_address_book_entries(const vector& indices) const { + MTRACE("monero_wallet_core::get_address_book_entries()"); // get wallet2 address book entries const auto w2_entries = m_w2->get_address_book(); @@ -2784,7 +2779,7 @@ namespace monero { return entries; } - uint64_t monero_wallet_w2::add_address_book_entry(const string& address, const string& description, const string& payment_id) { + uint64_t monero_wallet_core::add_address_book_entry(const string& address, const string& description, const string& payment_id) { MTRACE("add_address_book_entry()"); cryptonote::address_parse_info info; crypto::hash payment_id_hash = crypto::null_hash; @@ -2814,7 +2809,7 @@ namespace monero { return m_w2->get_address_book().size() - 1; } - void monero_wallet_w2::edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description, bool set_payment_id, const string& payment_id) { + void monero_wallet_core::edit_address_book_entry(uint64_t index, bool set_address, const string& address, bool set_description, const string& description, bool set_payment_id, const string& payment_id) { MTRACE("edit_address_book_entry()"); const auto ab = m_w2->get_address_book(); @@ -2865,13 +2860,13 @@ namespace monero { } } - void monero_wallet_w2::delete_address_book_entry(uint64_t index) { + void monero_wallet_core::delete_address_book_entry(uint64_t index) { const auto w2_entries = m_w2->get_address_book(); if (index >= w2_entries.size()) throw runtime_error("Index out of range: " + std::to_string(index)); if (!m_w2->delete_address_book_row(index)) throw runtime_error("Failed to delete address book entry"); } - string monero_wallet_w2::create_payment_uri(const monero_send_request& request) const { + string monero_wallet_core::create_payment_uri(const monero_send_request& request) const { MTRACE("create_payment_uri()"); // validate request @@ -2893,7 +2888,7 @@ namespace monero { return uri; } - shared_ptr monero_wallet_w2::parse_payment_uri(const string& uri) const { + shared_ptr monero_wallet_core::parse_payment_uri(const string& uri) const { MTRACE("parse_payment_uri(" << uri << ")"); // decode uri to parameters @@ -2917,19 +2912,19 @@ namespace monero { if (!payment_id.empty()) send_request->m_payment_id = payment_id; if (!note.empty()) send_request->m_note = note; if (!m_recipient_name.empty()) send_request->m_recipient_name = m_recipient_name; - if (!unknown_parameters.empty()) MWARNING("WARNING in monero_wallet_w2::parse_payment_uri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters? + if (!unknown_parameters.empty()) MWARNING("WARNING in monero_wallet_core::parse_payment_uri: URI contains unknown parameters which are discarded"); // TODO: return unknown parameters? return send_request; } - bool monero_wallet_w2::get_attribute(const string& key, string& value) const { + bool monero_wallet_core::get_attribute(const string& key, string& value) const { return m_w2->get_attribute(key, value); } - void monero_wallet_w2::set_attribute(const string& key, const string& val) { + void monero_wallet_core::set_attribute(const string& key, const string& val) { m_w2->set_attribute(key, val); } - void monero_wallet_w2::start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery) { + void monero_wallet_core::start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery) { MTRACE("start_mining()"); // only mine on trusted daemon @@ -2959,7 +2954,7 @@ namespace monero { } } - void monero_wallet_w2::stop_mining() { + void monero_wallet_core::stop_mining() { MTRACE("stop_mining()"); cryptonote::COMMAND_RPC_STOP_MINING::request daemon_req; cryptonote::COMMAND_RPC_STOP_MINING::response daemon_res; @@ -2969,7 +2964,7 @@ namespace monero { } } - uint64_t monero_wallet_w2::wait_for_next_block() { + uint64_t monero_wallet_core::wait_for_next_block() { // use mutex and condition variable to wait for block boost::mutex temp; @@ -3001,23 +2996,23 @@ namespace monero { return block_listener.last_height; } - bool monero_wallet_w2::is_multisig_import_needed() const { + bool monero_wallet_core::is_multisig_import_needed() const { return m_w2->multisig() && m_w2->has_multisig_partial_key_images(); } - monero_multisig_info monero_wallet_w2::get_multisig_info() { + monero_multisig_info monero_wallet_core::get_multisig_info() { monero_multisig_info info; info.m_is_multisig = m_w2->multisig(&info.m_is_ready, &info.m_threshold, &info.m_num_participants); return info; } - string monero_wallet_w2::prepare_multisig() { + string monero_wallet_core::prepare_multisig() { if (m_w2->multisig()) throw runtime_error("This wallet is already multisig"); if (m_w2->watch_only()) throw runtime_error("This wallet is watch-only and cannot be made multisig"); return m_w2->get_multisig_info(); } - monero_multisig_init_result monero_wallet_w2::make_multisig(const vector& multisig_hexes, int threshold, const string& password) { + monero_multisig_init_result monero_wallet_core::make_multisig(const vector& multisig_hexes, int threshold, const string& password) { if (m_w2->multisig()) throw runtime_error("This wallet is already multisig"); if (m_w2->watch_only()) throw runtime_error("This wallet is watch-only and cannot be made multisig"); boost::lock_guard guarg(m_sync_mutex); // do not refresh while making multisig @@ -3027,7 +3022,7 @@ namespace monero { return result; } - monero_multisig_init_result monero_wallet_w2::exchange_multisig_keys(const vector& multisig_hexes, const string& password) { + monero_multisig_init_result monero_wallet_core::exchange_multisig_keys(const vector& multisig_hexes, const string& password) { // validate state and args bool ready; @@ -3049,14 +3044,14 @@ namespace monero { return result; } - string monero_wallet_w2::get_multisig_hex() { + string monero_wallet_core::get_multisig_hex() { bool ready; if (!m_w2->multisig(&ready)) throw runtime_error("This wallet is not multisig"); if (!ready) throw runtime_error("This wallet is multisig, but not yet finalized"); return epee::string_tools::buff_to_hex_nodelimer(m_w2->export_multisig()); } - int monero_wallet_w2::import_multisig_hex(const vector& multisig_hexes) { + int monero_wallet_core::import_multisig_hex(const vector& multisig_hexes) { // validate state and args bool ready; @@ -3084,7 +3079,7 @@ namespace monero { return num_outputs; } - monero_multisig_sign_result monero_wallet_w2::sign_multisig_tx_hex(const string& multisig_tx_hex) { + monero_multisig_sign_result monero_wallet_core::sign_multisig_tx_hex(const string& multisig_tx_hex) { // validate state and args bool ready; @@ -3127,7 +3122,7 @@ namespace monero { return result; } - vector monero_wallet_w2::submit_multisig_tx_hex(const string& signed_multisig_tx_hex) { + vector monero_wallet_core::submit_multisig_tx_hex(const string& signed_multisig_tx_hex) { // validate state and args bool ready; @@ -3168,17 +3163,17 @@ namespace monero { return tx_ids; } - void monero_wallet_w2::save() { + void monero_wallet_core::save() { MTRACE("save()"); m_w2->store(); } - void monero_wallet_w2::move_to(string path, string password) { + void monero_wallet_core::move_to(string path, string password) { MTRACE("move_to(" << path << ", " << password << ")"); m_w2->store_to(path, password); } - void monero_wallet_w2::close(bool save) { + void monero_wallet_core::close(bool save) { MTRACE("close()"); if (save) this->save(); m_w2->callback(NULL); @@ -3195,8 +3190,8 @@ namespace monero { // ------------------------------- PRIVATE HELPERS ---------------------------- - void monero_wallet_w2::init_common() { - MTRACE("monero_wallet_w2.cpp init_common()"); + void monero_wallet_core::init_common() { + MTRACE("monero_wallet_core.cpp init_common()"); m_w2_listener = unique_ptr(new wallet2_listener(*this, *m_w2)); if (get_daemon_connection() == nullptr) m_is_connected = false; m_is_synced = false; @@ -3212,7 +3207,7 @@ namespace monero { } // private helper to initialize subaddresses using transfer details - vector monero_wallet_w2::get_subaddresses_aux(const uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const { + vector monero_wallet_core::get_subaddresses_aux(const uint32_t account_idx, const vector& subaddress_indices, const vector& transfers) const { vector subaddresses; // get balances per subaddress as maps @@ -3251,7 +3246,7 @@ namespace monero { return subaddresses; } - void monero_wallet_w2::sync_thread_func() { + void monero_wallet_core::sync_thread_func() { MTRACE("sync_thread_func()"); while (true) { boost::mutex::scoped_lock lock(m_syncing_mutex); @@ -3268,7 +3263,7 @@ namespace monero { } } - monero_sync_result monero_wallet_w2::lock_and_sync(boost::optional start_height) { + monero_sync_result monero_wallet_core::lock_and_sync(boost::optional start_height) { bool rescan = m_rescan_on_sync.exchange(false); boost::lock_guard guarg(m_sync_mutex); // synchronize sync() and syncAsync() monero_sync_result result; @@ -3292,7 +3287,7 @@ namespace monero { return result; } - monero_sync_result monero_wallet_w2::sync_aux(boost::optional start_height) { + monero_sync_result monero_wallet_core::sync_aux(boost::optional start_height) { MTRACE("sync_aux()"); // determine sync start height diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index 4484ac3..58ef6ad 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -78,7 +78,7 @@ namespace monero { /** * Monero wallet implmentation which uses monero-project's wallet2. */ - class monero_wallet_w2 : public monero_wallet { + class monero_wallet_core : public monero_wallet { public: @@ -97,7 +97,7 @@ namespace monero { * @param password is the password of the wallet file to open * @param network_type is the wallet's network type */ - static monero_wallet_w2* open_wallet(const string& path, const string& password, const monero_network_type network_type); + static monero_wallet_core* open_wallet(const string& path, const string& password, const monero_network_type network_type); /** * Create a new wallet with a randomly generated seed. @@ -108,8 +108,7 @@ namespace monero { * @param daemon_connection is connection information to a daemon (default = an unconnected wallet) * @param language is the wallet and mnemonic's language (default = "English") */ - static monero_wallet_w2* create_wallet_random(const string& path, const string& password); - static monero_wallet_w2* create_wallet_random(const string& path, const string& password, const monero_network_type network_type, const monero_rpc_connection& daemon_connection, const string& language); + static monero_wallet_core* create_wallet_random(const string& path, const string& password, const monero_network_type network_type = monero_network_type.MAINNET, const monero_rpc_connection& daemon_connection = monero_rpc_connection, const string& language = "English"); /** * Create a wallet from an existing mnemonic phrase. @@ -121,8 +120,8 @@ namespace monero { * @param daemon_connection is connection information to a daemon (default = an unconnected wallet) * @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0) */ - static monero_wallet_w2* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic); - static monero_wallet_w2* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height); + static monero_wallet_core* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic); + static monero_wallet_core* create_wallet_from_mnemonic(const string& path, const string& password, const monero_network_type network_type, const string& mnemonic, const monero_rpc_connection& daemon_connection, uint64_t restore_height); /** * Create a wallet from an address, view key, and spend key. @@ -137,14 +136,14 @@ namespace monero { * @param restore_height is the block height to restore (i.e. scan the chain) from (default = 0) * @param language is the wallet and mnemonic's language (default = "English") */ - static monero_wallet_w2* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key); - static monero_wallet_w2* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height); - static monero_wallet_w2* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language); + static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key); + static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height); + static monero_wallet_core* create_wallet_from_keys(const string& path, const string& password, const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const monero_rpc_connection& daemon_connection, uint64_t restore_height, const string& language); /** * Destruct the wallet. */ - ~monero_wallet_w2(); + ~monero_wallet_core(); /** * Supported wallet methods. diff --git a/src/wallet/monero_wallet_keys.cpp b/src/wallet/monero_wallet_keys.cpp index c662672..3cd01e6 100644 --- a/src/wallet/monero_wallet_keys.cpp +++ b/src/wallet/monero_wallet_keys.cpp @@ -75,12 +75,25 @@ namespace monero { // ---------------------------- WALLET MANAGEMENT --------------------------- monero_wallet_keys* monero_wallet_keys::create_wallet_random(const monero_network_type network_type, const string& language) { - cout << "monero_wallet_keys::create_wallet_random(...)" << endl; - throw runtime_error("create_wallet_random(...) not implemented"); + + // initialize random wallet account + monero_wallet_keys* wallet = new monero_wallet_keys(); + crypto::secret_key spend_key_sk = wallet->m_account.generate(); + + // initialize remaining wallet + wallet->m_network_type = network_type; + wallet->m_language = language; + epee::wipeable_string wipeable_mnemonic; + if (!crypto::ElectrumWords::bytes_to_words(spend_key_sk, wipeable_mnemonic, wallet->m_language)) { + throw runtime_error("Failed to create mnemonic from private spend key for language: " + string(wallet->m_language)); + } + wallet->m_mnemonic = string(wipeable_mnemonic.data(), wipeable_mnemonic.size()); + wallet->init_common(); + + return wallet; } monero_wallet_keys* monero_wallet_keys::create_wallet_from_mnemonic(const monero_network_type network_type, const string& mnemonic) { - cout << "monero_wallet_keys::create_wallet_from_mnemonic()" << endl; // validate mnemonic and get recovery key and language crypto::secret_key recovery_key; @@ -104,7 +117,6 @@ namespace monero { } monero_wallet_keys* monero_wallet_keys::create_wallet_from_keys(const monero_network_type network_type, const string& address, const string& view_key, const string& spend_key, const string& language) { - cout << "monero_wallet_keys::create_wallet_from_keys(...)" << endl; // validate and parse address cryptonote::address_parse_info info;