aboutsummaryrefslogtreecommitdiff
path: root/src/wallet
diff options
context:
space:
mode:
authorRiccardo Spagni <ric@spagni.net>2019-04-11 13:05:42 +0200
committerRiccardo Spagni <ric@spagni.net>2019-04-11 13:05:43 +0200
commit5db72d12b428e21ad1cd292df4d13aee5c273b95 (patch)
tree517e7df6a38e956ba9e31395ec8c7025d2c42469 /src/wallet
parentMerge pull request #5382 (diff)
parentsimplewallet: new unset_ring command (diff)
downloadmonero-5db72d12b428e21ad1cd292df4d13aee5c273b95.tar.xz
Merge pull request #5388
0be5b2ee simplewallet: new unset_ring command (moneromooo-monero)
Diffstat (limited to 'src/wallet')
-rw-r--r--src/wallet/ringdb.cpp32
-rw-r--r--src/wallet/ringdb.h1
-rw-r--r--src/wallet/wallet2.cpp37
-rw-r--r--src/wallet/wallet2.h2
4 files changed, 61 insertions, 11 deletions
diff --git a/src/wallet/ringdb.cpp b/src/wallet/ringdb.cpp
index b69022af4..8da95de7b 100644
--- a/src/wallet/ringdb.cpp
+++ b/src/wallet/ringdb.cpp
@@ -281,7 +281,7 @@ bool ringdb::add_rings(const crypto::chacha_key &chacha_key, const cryptonote::t
return true;
}
-bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const cryptonote::transaction_prefix &tx)
+bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const std::vector<crypto::key_image> &key_images)
{
MDB_txn *txn;
int dbr;
@@ -294,17 +294,10 @@ bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const cryptonote
epee::misc_utils::auto_scope_leave_caller txn_dtor = epee::misc_utils::create_scope_leave_handler([&](){if (tx_active) mdb_txn_abort(txn);});
tx_active = true;
- for (const auto &in: tx.vin)
+ for (const crypto::key_image &key_image: key_images)
{
- if (in.type() != typeid(cryptonote::txin_to_key))
- continue;
- const auto &txin = boost::get<cryptonote::txin_to_key>(in);
- const uint32_t ring_size = txin.key_offsets.size();
- if (ring_size == 1)
- continue;
-
MDB_val key, data;
- std::string key_ciphertext = encrypt(txin.k_image, chacha_key);
+ std::string key_ciphertext = encrypt(key_image, chacha_key);
key.mv_data = (void*)key_ciphertext.data();
key.mv_size = key_ciphertext.size();
@@ -314,7 +307,7 @@ bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const cryptonote
continue;
THROW_WALLET_EXCEPTION_IF(data.mv_size <= 0, tools::error::wallet_internal_error, "Invalid ring data size");
- MDEBUG("Removing ring data for key image " << txin.k_image);
+ MDEBUG("Removing ring data for key image " << key_image);
dbr = mdb_del(txn, dbi_rings, &key, NULL);
THROW_WALLET_EXCEPTION_IF(dbr, tools::error::wallet_internal_error, "Failed to remove ring to database: " + std::string(mdb_strerror(dbr)));
}
@@ -325,6 +318,23 @@ bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const cryptonote
return true;
}
+bool ringdb::remove_rings(const crypto::chacha_key &chacha_key, const cryptonote::transaction_prefix &tx)
+{
+ std::vector<crypto::key_image> key_images;
+ key_images.reserve(tx.vin.size());
+ for (const auto &in: tx.vin)
+ {
+ if (in.type() != typeid(cryptonote::txin_to_key))
+ continue;
+ const auto &txin = boost::get<cryptonote::txin_to_key>(in);
+ const uint32_t ring_size = txin.key_offsets.size();
+ if (ring_size == 1)
+ continue;
+ key_images.push_back(txin.k_image);
+ }
+ return remove_rings(chacha_key, key_images);
+}
+
bool ringdb::get_ring(const crypto::chacha_key &chacha_key, const crypto::key_image &key_image, std::vector<uint64_t> &outs)
{
MDB_txn *txn;
diff --git a/src/wallet/ringdb.h b/src/wallet/ringdb.h
index 7b448b0d7..9c7e624bc 100644
--- a/src/wallet/ringdb.h
+++ b/src/wallet/ringdb.h
@@ -45,6 +45,7 @@ namespace tools
~ringdb();
bool add_rings(const crypto::chacha_key &chacha_key, const cryptonote::transaction_prefix &tx);
+ bool remove_rings(const crypto::chacha_key &chacha_key, const std::vector<crypto::key_image> &key_images);
bool remove_rings(const crypto::chacha_key &chacha_key, const cryptonote::transaction_prefix &tx);
bool get_ring(const crypto::chacha_key &chacha_key, const crypto::key_image &key_image, std::vector<uint64_t> &outs);
bool set_ring(const crypto::chacha_key &chacha_key, const crypto::key_image &key_image, const std::vector<uint64_t> &outs, bool relative);
diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp
index 39fe4608c..dfcc61426 100644
--- a/src/wallet/wallet2.cpp
+++ b/src/wallet/wallet2.cpp
@@ -7094,6 +7094,43 @@ bool wallet2::set_ring(const crypto::key_image &key_image, const std::vector<uin
catch (const std::exception &e) { return false; }
}
+bool wallet2::unset_ring(const std::vector<crypto::key_image> &key_images)
+{
+ if (!m_ringdb)
+ return false;
+
+ try { return m_ringdb->remove_rings(get_ringdb_key(), key_images); }
+ catch (const std::exception &e) { return false; }
+}
+
+bool wallet2::unset_ring(const crypto::hash &txid)
+{
+ if (!m_ringdb)
+ return false;
+
+ COMMAND_RPC_GET_TRANSACTIONS::request req;
+ COMMAND_RPC_GET_TRANSACTIONS::response res;
+ req.txs_hashes.push_back(epee::string_tools::pod_to_hex(txid));
+ req.decode_as_json = false;
+ req.prune = true;
+ m_daemon_rpc_mutex.lock();
+ bool ok = epee::net_utils::invoke_http_json("/gettransactions", req, res, m_http_client);
+ m_daemon_rpc_mutex.unlock();
+ THROW_WALLET_EXCEPTION_IF(!ok, error::wallet_internal_error, "Failed to get transaction from daemon");
+ if (res.txs.empty())
+ return false;
+ THROW_WALLET_EXCEPTION_IF(res.txs.size(), error::wallet_internal_error, "Failed to get transaction from daemon");
+
+ cryptonote::transaction tx;
+ crypto::hash tx_hash;
+ if (!get_pruned_tx(res.txs.front(), tx, tx_hash))
+ return false;
+ THROW_WALLET_EXCEPTION_IF(tx_hash != txid, error::wallet_internal_error, "Failed to get the right transaction from daemon");
+
+ try { return m_ringdb->remove_rings(get_ringdb_key(), tx); }
+ catch (const std::exception &e) { return false; }
+}
+
bool wallet2::find_and_save_rings(bool force)
{
if (!force && m_ring_history_saved)
diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h
index f4b1233e0..c8ac7d429 100644
--- a/src/wallet/wallet2.h
+++ b/src/wallet/wallet2.h
@@ -1251,6 +1251,8 @@ namespace tools
bool get_ring(const crypto::key_image &key_image, std::vector<uint64_t> &outs);
bool get_rings(const crypto::hash &txid, std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> &outs);
bool set_ring(const crypto::key_image &key_image, const std::vector<uint64_t> &outs, bool relative);
+ bool unset_ring(const std::vector<crypto::key_image> &key_images);
+ bool unset_ring(const crypto::hash &txid);
bool find_and_save_rings(bool force = true);
bool blackball_output(const std::pair<uint64_t, uint64_t> &output);