aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/wallet/api')
-rw-r--r--src/wallet/api/CMakeLists.txt1
-rw-r--r--src/wallet/api/wallet.cpp132
-rw-r--r--src/wallet/api/wallet.h8
-rw-r--r--src/wallet/api/wallet2_api.h25
4 files changed, 166 insertions, 0 deletions
diff --git a/src/wallet/api/CMakeLists.txt b/src/wallet/api/CMakeLists.txt
index 1e67495f1..d6f2bf6b7 100644
--- a/src/wallet/api/CMakeLists.txt
+++ b/src/wallet/api/CMakeLists.txt
@@ -69,6 +69,7 @@ target_link_libraries(wallet_api
common
cryptonote_core
mnemonics
+ ${LMDB_LIBRARY}
${Boost_CHRONO_LIBRARY}
${Boost_SERIALIZATION_LIBRARY}
${Boost_FILESYSTEM_LIBRARY}
diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp
index fb9e8b28b..b02884f67 100644
--- a/src/wallet/api/wallet.cpp
+++ b/src/wallet/api/wallet.cpp
@@ -68,6 +68,15 @@ namespace {
static const int DEFAULT_REMOTE_NODE_REFRESH_INTERVAL_MILLIS = 1000 * 10;
// Connection timeout 30 sec
static const int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 1000 * 30;
+
+ std::string get_default_ringdb_path()
+ {
+ boost::filesystem::path dir = tools::get_default_data_dir();
+ // remove .bitmonero, replace with .shared-ringdb
+ dir = dir.remove_filename();
+ dir /= ".shared-ringdb";
+ return dir.string();
+ }
}
struct Wallet2CallbackImpl : public tools::i_wallet2_callback
@@ -590,6 +599,7 @@ bool WalletImpl::open(const std::string &path, const std::string &password)
// Rebuilding wallet cache, using refresh height from .keys file
m_rebuildWalletCache = true;
}
+ m_wallet->set_ring_database(get_default_ringdb_path());
m_wallet->load(path, password);
m_password = password;
@@ -1777,6 +1787,7 @@ void WalletImpl::doRefresh()
if (m_history->count() == 0) {
m_history->refresh();
}
+ m_wallet->find_and_save_rings(false);
} else {
LOG_PRINT_L3(__FUNCTION__ << ": skipping refresh - daemon is not synced");
}
@@ -1897,6 +1908,127 @@ bool WalletImpl::useForkRules(uint8_t version, int64_t early_blocks) const
return m_wallet->use_fork_rules(version,early_blocks);
}
+bool WalletImpl::blackballOutputs(const std::vector<std::string> &pubkeys, bool add)
+{
+ std::vector<crypto::public_key> raw_pubkeys;
+ raw_pubkeys.reserve(pubkeys.size());
+ for (const std::string &str: pubkeys)
+ {
+ crypto::public_key pkey;
+ if (!epee::string_tools::hex_to_pod(str, pkey))
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to parse output public key");
+ return false;
+ }
+ raw_pubkeys.push_back(pkey);
+ }
+ bool ret = m_wallet->set_blackballed_outputs(raw_pubkeys, add);
+ if (!ret)
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to set blackballed outputs");
+ return false;
+ }
+ return true;
+}
+
+bool WalletImpl::unblackballOutput(const std::string &pubkey)
+{
+ crypto::public_key raw_pubkey;
+ if (!epee::string_tools::hex_to_pod(pubkey, raw_pubkey))
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to parse output public key");
+ return false;
+ }
+ bool ret = m_wallet->unblackball_output(raw_pubkey);
+ if (!ret)
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to unblackball output");
+ return false;
+ }
+ return true;
+}
+
+bool WalletImpl::getRing(const std::string &key_image, std::vector<uint64_t> &ring) const
+{
+ crypto::key_image raw_key_image;
+ if (!epee::string_tools::hex_to_pod(key_image, raw_key_image))
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to parse key image");
+ return false;
+ }
+ bool ret = m_wallet->get_ring(raw_key_image, ring);
+ if (!ret)
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to get ring");
+ return false;
+ }
+ return true;
+}
+
+bool WalletImpl::getRings(const std::string &txid, std::vector<std::pair<std::string, std::vector<uint64_t>>> &rings) const
+{
+ crypto::hash raw_txid;
+ if (!epee::string_tools::hex_to_pod(txid, raw_txid))
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to parse txid");
+ return false;
+ }
+ std::vector<std::pair<crypto::key_image, std::vector<uint64_t>>> raw_rings;
+ bool ret = m_wallet->get_rings(raw_txid, raw_rings);
+ if (!ret)
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to get rings");
+ return false;
+ }
+ for (const auto &r: raw_rings)
+ {
+ rings.push_back(std::make_pair(epee::string_tools::pod_to_hex(r.first), r.second));
+ }
+ return true;
+}
+
+bool WalletImpl::setRing(const std::string &key_image, const std::vector<uint64_t> &ring, bool relative)
+{
+ crypto::key_image raw_key_image;
+ if (!epee::string_tools::hex_to_pod(key_image, raw_key_image))
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to parse key image");
+ return false;
+ }
+ bool ret = m_wallet->set_ring(raw_key_image, ring, relative);
+ if (!ret)
+ {
+ m_status = Status_Error;
+ m_errorString = tr("Failed to set ring");
+ return false;
+ }
+ return true;
+}
+
+void WalletImpl::segregatePreForkOutputs(bool segregate)
+{
+ m_wallet->segregate_pre_fork_outputs(segregate);
+}
+
+void WalletImpl::segregationHeight(uint64_t height)
+{
+ m_wallet->segregation_height(height);
+}
+
+void WalletImpl::keyReuseMitigation2(bool mitigation)
+{
+ m_wallet->key_reuse_mitigation2(mitigation);
+}
+
} // namespace
namespace Bitmonero = Monero;
diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h
index 9b4a0cc12..4929c9673 100644
--- a/src/wallet/api/wallet.h
+++ b/src/wallet/api/wallet.h
@@ -163,6 +163,14 @@ public:
virtual std::string getDefaultDataDir() const;
virtual bool lightWalletLogin(bool &isNewWallet) const;
virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status);
+ virtual bool blackballOutputs(const std::vector<std::string> &pubkeys, bool add);
+ virtual bool unblackballOutput(const std::string &pubkey);
+ virtual bool getRing(const std::string &key_image, std::vector<uint64_t> &ring) const;
+ virtual bool getRings(const std::string &txid, std::vector<std::pair<std::string, std::vector<uint64_t>>> &rings) const;
+ virtual bool setRing(const std::string &key_image, const std::vector<uint64_t> &ring, bool relative);
+ virtual void segregatePreForkOutputs(bool segregate);
+ virtual void segregationHeight(uint64_t height);
+ virtual void keyReuseMitigation2(bool mitigation);
private:
void clearStatus() const;
diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h
index 87c1cccfa..d4e41c5aa 100644
--- a/src/wallet/api/wallet2_api.h
+++ b/src/wallet/api/wallet2_api.h
@@ -33,6 +33,7 @@
#include <string>
#include <vector>
+#include <list>
#include <set>
#include <ctime>
#include <iostream>
@@ -756,6 +757,30 @@ struct Wallet
*/
virtual bool rescanSpent() = 0;
+ //! blackballs a set of outputs
+ virtual bool blackballOutputs(const std::vector<std::string> &pubkeys, bool add) = 0;
+
+ //! unblackballs an output
+ virtual bool unblackballOutput(const std::string &pubkey) = 0;
+
+ //! gets the ring used for a key image, if any
+ virtual bool getRing(const std::string &key_image, std::vector<uint64_t> &ring) const = 0;
+
+ //! gets the rings used for a txid, if any
+ virtual bool getRings(const std::string &txid, std::vector<std::pair<std::string, std::vector<uint64_t>>> &rings) const = 0;
+
+ //! sets the ring used for a key image
+ virtual bool setRing(const std::string &key_image, const std::vector<uint64_t> &ring, bool relative) = 0;
+
+ //! sets whether pre-fork outs are to be segregated
+ virtual void segregatePreForkOutputs(bool segregate) = 0;
+
+ //! sets the height where segregation should occur
+ virtual void segregationHeight(uint64_t height) = 0;
+
+ //! secondary key reuse mitigation
+ virtual void keyReuseMitigation2(bool mitigation) = 0;
+
//! Light wallet authenticate and login
virtual bool lightWalletLogin(bool &isNewWallet) const = 0;