From 7b0a03b818ff0f99756c8d7212ee9799813bc681 Mon Sep 17 00:00:00 2001 From: woodser Date: Thu, 22 Aug 2019 22:34:47 -0400 Subject: [PATCH] implement close(bool save); cleanup --- src/wallet/monero_wallet.cpp | 57 ++++++++++++++++++------------------ src/wallet/monero_wallet.h | 54 ++++++++++++++++++---------------- 2 files changed, 57 insertions(+), 54 deletions(-) diff --git a/src/wallet/monero_wallet.cpp b/src/wallet/monero_wallet.cpp index 751a7af..81e98a4 100644 --- a/src/wallet/monero_wallet.cpp +++ b/src/wallet/monero_wallet.cpp @@ -2664,14 +2664,14 @@ namespace monero { return send_request; } - void monero_wallet::set_attribute(const string& key, const string& val) { - m_w2->set_attribute(key, val); - } - string monero_wallet::get_attribute(const string& key) const { return m_w2->get_attribute(key); } + void monero_wallet::set_attribute(const string& key, const string& val) { + m_w2->set_attribute(key, val); + } + void monero_wallet::start_mining(boost::optional num_threads, boost::optional background_mining, boost::optional ignore_battery) { MTRACE("start_mining()"); @@ -2712,11 +2712,6 @@ namespace monero { } } - void monero_wallet::save() { - MTRACE("save()"); - m_w2->store(); - } - uint64_t monero_wallet::wait_for_next_block() { // use mutex and condition variable to wait for block @@ -2749,25 +2744,6 @@ namespace monero { return block_listener.last_height; } - void monero_wallet::move_to(string path, string password) { - MTRACE("move_to(" << path << ", " << password << ")"); - m_w2->store_to(path, password); - } - - void monero_wallet::close() { - MTRACE("close()"); - m_w2->callback(NULL); - stop_syncing(); // prevent sync thread from starting again - m_w2->stop(); - m_w2->deinit(); - if (!m_syncing_thread_done) { - m_syncing_enabled = false; - m_syncing_thread_done = true; - m_sync_cv.notify_one(); - m_syncing_thread.join(); - } - } - bool monero_wallet::is_multisig_import_needed() const { return m_w2->multisig() && m_w2->has_multisig_partial_key_images(); } @@ -2955,6 +2931,31 @@ namespace monero { return tx_ids; } + void monero_wallet::save() { + MTRACE("save()"); + m_w2->store(); + } + + void monero_wallet::move_to(string path, string password) { + MTRACE("move_to(" << path << ", " << password << ")"); + m_w2->store_to(path, password); + } + + void monero_wallet::close(bool save) { + MTRACE("close()"); + if (save) save(); + m_w2->callback(NULL); + stop_syncing(); // prevent sync thread from starting again + m_w2->stop(); + m_w2->deinit(); + if (!m_syncing_thread_done) { + m_syncing_enabled = false; + m_syncing_thread_done = true; + m_sync_cv.notify_one(); + m_syncing_thread.join(); + } + } + // ------------------------------- PRIVATE HELPERS ---------------------------- void monero_wallet::init_common() { diff --git a/src/wallet/monero_wallet.h b/src/wallet/monero_wallet.h index dce24af..3b0fe7a 100644 --- a/src/wallet/monero_wallet.h +++ b/src/wallet/monero_wallet.h @@ -1239,14 +1239,6 @@ namespace monero { */ shared_ptr parse_payment_uri(const string& uri) const; - /** - * Set an arbitrary attribute. - * - * @param key is the attribute key - * @param val is the attribute value - */ - void set_attribute(const string& key, const string& val); - /** * Get an attribute. * @@ -1255,6 +1247,14 @@ namespace monero { */ string get_attribute(const string& key) const; + /** + * Set an arbitrary attribute. + * + * @param key is the attribute key + * @param val is the attribute value + */ + void set_attribute(const string& key, const string& val); + /** * Start mining. * @@ -1276,24 +1276,6 @@ namespace monero { */ uint64_t wait_for_next_block(); - /** - * Save the wallet at its current path. - */ - void save(); - - /** - * Move the wallet from its current path to the given path. - * - * @param path is the new wallet's path - * @param password is the new wallet's password - */ - void move_to(string path, string password); - - /** - * Close the wallet. - */ - void close(); - /** * Indicates if importing multisig data is needed for returning a correct balance. * @@ -1385,6 +1367,26 @@ namespace monero { */ vector submit_multisig_tx_hex(const string& signed_multisig_tx_hex); + /** + * Save the wallet at its current path. + */ + void save(); + + /** + * Move the wallet from its current path to the given path. + * + * @param path is the new wallet's path + * @param password is the new wallet's password + */ + void move_to(string path, string password); + + /** + * Optionally save then close the wallet. + * + * @param save specifies if the wallet should be saved before being closed (default true) + */ + void close(bool save = true); + // --------------------------------- PRIVATE -------------------------------- private: