From f64108eb6ff57f9460cb05d0a588b3c410b3d70d Mon Sep 17 00:00:00 2001 From: woodser Date: Mon, 9 Dec 2019 12:50:11 -0500 Subject: [PATCH] get_mnemonic_languages() as static wallet util --- src/wallet/monero_wallet.h | 11 +---------- src/wallet/monero_wallet_core.cpp | 18 +++++++++--------- src/wallet/monero_wallet_core.h | 14 +++++++++++--- src/wallet/monero_wallet_keys.cpp | 11 ++++++----- src/wallet/monero_wallet_keys.h | 12 +++++++++++- 5 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index c425579..e7a06ca 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -115,7 +115,7 @@ namespace monero { // forward declaration of internal wallet2 listener struct wallet2_listener; - // ---------------------------- WALLET INTERFACE ---------------------------- + // ----------------------------- WALLET METHODS ----------------------------- /** * Base wallet with default implementations. @@ -239,15 +239,6 @@ namespace monero { throw runtime_error("get_mnemonic_language() not supported"); } - /** - * Get a list of available languages for the wallet's mnemonic phrase. - * - * @return the available languages for the wallet's mnemonic phrase - */ - virtual vector get_languages() const { - throw runtime_error("get_languages() not supported"); - } - /** * Get the wallet's public view key. * diff --git a/src/wallet/monero_wallet_core.cpp b/src/wallet/monero_wallet_core.cpp index 9aef394..89d2569 100644 --- a/src/wallet/monero_wallet_core.cpp +++ b/src/wallet/monero_wallet_core.cpp @@ -787,7 +787,7 @@ namespace monero { monero_sync_listener& listener; }; - // ---------------------------- WALLET MANAGEMENT --------------------------- + // --------------------------- STATIC WALLET UTILS -------------------------- bool monero_wallet_core::wallet_exists(const string& path) { MTRACE("wallet_exists(" << path << ")"); @@ -915,13 +915,19 @@ namespace monero { return wallet; } + vector monero_wallet_core::get_mnemonic_languages() { + vector languages; + crypto::ElectrumWords::get_language_list(languages, true); + return languages; + } + + // ----------------------------- WALLET METHODS ----------------------------- + monero_wallet_core::~monero_wallet_core() { MTRACE("~monero_wallet_core()"); close(false); } - // ----------------------------- WALLET METHODS ----------------------------- - void monero_wallet_core::set_daemon_connection(const string& uri, const string& username, const string& password) { MTRACE("set_daemon_connection(" << uri << ", " << username << ", " << password << ")"); @@ -1006,12 +1012,6 @@ namespace monero { return m_w2->get_seed_language(); } - vector monero_wallet_core::get_languages() const { - vector languages; - crypto::ElectrumWords::get_language_list(languages, true); - return languages; - } - 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); diff --git a/src/wallet/monero_wallet_core.h b/src/wallet/monero_wallet_core.h index 85f0ce9..e64d6f6 100644 --- a/src/wallet/monero_wallet_core.h +++ b/src/wallet/monero_wallet_core.h @@ -68,12 +68,12 @@ using namespace monero; */ namespace monero { - // --------------------------------- LISTENERS ------------------------------ + // -------------------------------- LISTENERS ------------------------------- // forward declaration of internal wallet2 listener struct wallet2_listener; - // ---------------------------- WALLET INTERFACE ---------------------------- + // --------------------------- STATIC WALLET UTILS -------------------------- /** * Monero wallet implmentation which uses monero-project's wallet2. @@ -140,6 +140,15 @@ namespace monero { 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); + /** + * Get a list of available languages for the wallet's mnemonic phrase. + * + * @return the available languages for the wallet's mnemonic phrase + */ + static vector get_mnemonic_languages(); + + // ----------------------------- WALLET METHODS ----------------------------- + /** * Destruct the wallet. */ @@ -160,7 +169,6 @@ namespace monero { monero_network_type get_network_type() const; string get_mnemonic() const; string get_mnemonic_language() const; - vector get_languages() const; string get_public_view_key() const; string get_private_view_key() const; string get_public_spend_key() const; diff --git a/src/wallet/monero_wallet_keys.cpp b/src/wallet/monero_wallet_keys.cpp index 14321ce..2d87ba4 100644 --- a/src/wallet/monero_wallet_keys.cpp +++ b/src/wallet/monero_wallet_keys.cpp @@ -183,6 +183,12 @@ namespace monero { return wallet; } + vector monero_wallet_keys::get_mnemonic_languages() { + vector languages; + crypto::ElectrumWords::get_language_list(languages, true); + return languages; + } + // ----------------------------- WALLET METHODS ----------------------------- monero_wallet_keys::~monero_wallet_keys() { @@ -197,11 +203,6 @@ namespace monero { return version; } - vector monero_wallet_keys::get_languages() const { - cout << "monero_wallet_keys::get_languages()" << endl; - throw runtime_error("monero_wallet_keys::get_languages() not implemented"); - } - string monero_wallet_keys::get_address(uint32_t account_idx, uint32_t subaddress_idx) const { hw::device &hwdev = m_account.get_device(); cryptonote::subaddress_index index{account_idx, subaddress_idx}; diff --git a/src/wallet/monero_wallet_keys.h b/src/wallet/monero_wallet_keys.h index d86426e..1a44e03 100644 --- a/src/wallet/monero_wallet_keys.h +++ b/src/wallet/monero_wallet_keys.h @@ -70,6 +70,8 @@ namespace monero { public: + // --------------------------- STATIC WALLET UTILS -------------------------- + /** * Create a new wallet with a randomly generated seed. * @@ -97,6 +99,15 @@ namespace monero { */ static 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 = "English"); + /** + * Get a list of available languages for the wallet's mnemonic phrase. + * + * @return the available languages for the wallet's mnemonic phrase + */ + static vector get_mnemonic_languages(); + + // ----------------------------- WALLET METHODS ----------------------------- + /** * Destruct the wallet. */ @@ -109,7 +120,6 @@ namespace monero { monero_network_type get_network_type() const { return m_network_type; } string get_mnemonic() const { return m_mnemonic; } string get_mnemonic_language() const { return m_language; } - vector get_languages() const; string get_private_view_key() const { return m_prv_view_key; } string get_private_spend_key() const { return m_prv_spend_key; } string get_public_view_key() const { return m_pub_view_key; }