From f2e6a11703a903a096b847a7a372f7c48d113d27 Mon Sep 17 00:00:00 2001 From: moneromooo-monero Date: Wed, 21 Mar 2018 14:29:49 +0000 Subject: [PATCH] wallet: catch exceptions dealing with ringdb and warn --- src/simplewallet/simplewallet.cpp | 3 +++ src/wallet/wallet2.cpp | 44 +++++++++++++++++++++---------- src/wallet/wallet2.h | 2 +- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/src/simplewallet/simplewallet.cpp b/src/simplewallet/simplewallet.cpp index 11fd5cc5f..45e9058c9 100755 --- a/src/simplewallet/simplewallet.cpp +++ b/src/simplewallet/simplewallet.cpp @@ -3063,6 +3063,9 @@ bool simple_wallet::init(const boost::program_options::variables_map& vm) if (!m_trusted_daemon) message_writer() << (boost::format(tr("Warning: using an untrusted daemon at %s, privacy will be lessened")) % m_wallet->get_daemon_address()).str(); + if (m_wallet->get_ring_database().empty()) + fail_msg_writer() << tr("Failed to initialize ring database: privacy enhancing features will be inactive"); + m_wallet->callback(this); return true; diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index 0df17925e..b28539c18 100755 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp @@ -5497,21 +5497,33 @@ std::vector wallet2::create_transactions(std::vectoradd_rings(key, tx); } catch (const std::exception &e) { return false; } } @@ -5520,7 +5532,8 @@ bool wallet2::add_rings(const cryptonote::transaction_prefix &tx) { crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); - return add_rings(key, tx); + try { return add_rings(key, tx); } + catch (const std::exception &e) { return false; } } bool wallet2::remove_rings(const cryptonote::transaction_prefix &tx) @@ -5529,13 +5542,14 @@ bool wallet2::remove_rings(const cryptonote::transaction_prefix &tx) return false; crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); - return m_ringdb->remove_rings(key, tx); + try { return m_ringdb->remove_rings(key, tx); } + catch (const std::exception &e) { return false; } } bool wallet2::get_ring(const crypto::chacha_key &key, const crypto::key_image &key_image, std::vector &outs) { if (!m_ringdb) - return false; + return true; try { return m_ringdb->get_ring(key, key_image, outs); } catch (const std::exception &e) { return false; } } @@ -5568,7 +5582,8 @@ bool wallet2::get_ring(const crypto::key_image &key_image, std::vector crypto::chacha_key key; generate_chacha_key_from_secret_keys(key); - return get_ring(key, key_image, outs); + try { return get_ring(key, key_image, outs); } + catch (const std::exception &e) { return false; } } bool wallet2::set_ring(const crypto::key_image &key_image, const std::vector &outs, bool relative) @@ -5579,7 +5594,8 @@ bool wallet2::set_ring(const crypto::key_image &key_image, const std::vectorset_ring(key, key_image, outs, relative); + try { return m_ringdb->set_ring(key, key_image, outs, relative); } + catch (const std::exception &e) { return false; } } bool wallet2::find_and_save_rings(bool force) @@ -5674,7 +5690,7 @@ bool wallet2::find_and_save_rings(bool force) bool wallet2::blackball_output(const crypto::public_key &output) { if (!m_ringdb) - return false; + return true; try { return m_ringdb->blackball(output); } catch (const std::exception &e) { return false; } } @@ -5682,7 +5698,7 @@ bool wallet2::blackball_output(const crypto::public_key &output) bool wallet2::set_blackballed_outputs(const std::vector &outputs, bool add) { if (!m_ringdb) - return false; + return true; try { bool ret = true; @@ -5698,7 +5714,7 @@ bool wallet2::set_blackballed_outputs(const std::vector &out bool wallet2::unblackball_output(const crypto::public_key &output) { if (!m_ringdb) - return false; + return true; try { return m_ringdb->unblackball(output); } catch (const std::exception &e) { return false; } } @@ -5706,7 +5722,7 @@ bool wallet2::unblackball_output(const crypto::public_key &output) bool wallet2::is_output_blackballed(const crypto::public_key &output) const { if (!m_ringdb) - return false; + return true; try { return m_ringdb->blackballed(output); } catch (const std::exception &e) { return false; } } diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index 275d06ed8..b9f124e32 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h @@ -1059,7 +1059,7 @@ namespace tools return epee::net_utils::invoke_http_json_rpc(uri, method_name, req, res, m_http_client, timeout, http_method, req_id); } - void set_ring_database(const std::string &filename); + bool set_ring_database(const std::string &filename); const std::string get_ring_database() const { return m_ring_database; } bool get_ring(const crypto::key_image &key_image, std::vector &outs); bool get_rings(const crypto::hash &txid, std::vector>> &outs);