From fab66493ebd2b5a52fc00debdcd4ad45c97fe747 Mon Sep 17 00:00:00 2001 From: Some Random Crypto Guy Date: Mon, 17 Mar 2025 13:21:40 +0000 Subject: [PATCH] updated a couple of patches to work against the rebased v0.18.4.0 Zero code --- ...se-proper-error-handling-in-get_seed.patch | 6 +- patches/salvium/0005-UR-functions.patch | 152 ++++++++---------- 2 files changed, 67 insertions(+), 91 deletions(-) diff --git a/patches/salvium/0004-use-proper-error-handling-in-get_seed.patch b/patches/salvium/0004-use-proper-error-handling-in-get_seed.patch index 33207f3..83ba296 100644 --- a/patches/salvium/0004-use-proper-error-handling-in-get_seed.patch +++ b/patches/salvium/0004-use-proper-error-handling-in-get_seed.patch @@ -12,7 +12,7 @@ diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 67b170e3d..89df5c517 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp -@@ -826,12 +826,19 @@ bool WalletImpl::close(bool store) +@@ -763,12 +763,19 @@ bool WalletImpl::close(bool store) std::string WalletImpl::seed(const std::string& seed_offset) const { @@ -41,7 +41,7 @@ diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index c9c2dbc82..b827b826f 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp -@@ -1449,11 +1449,13 @@ bool wallet2::get_seed(epee::wipeable_string& electrum_words, const epee::wipeab +@@ -1428,11 +1428,13 @@ bool wallet2::get_seed(epee::wipeable_string& electrum_words, const epee::wipeab bool keys_deterministic = is_deterministic(); if (!keys_deterministic) { @@ -55,7 +55,7 @@ index c9c2dbc82..b827b826f 100644 std::cout << "seed_language not set" << std::endl; return false; } -@@ -1463,8 +1465,9 @@ bool wallet2::get_seed(epee::wipeable_string& electrum_words, const epee::wipeab +@@ -1444,8 +1446,9 @@ bool wallet2::get_seed(epee::wipeable_string& electrum_words, const epee::wipeab key = cryptonote::encrypt_key(key, passphrase); if (!crypto::ElectrumWords::bytes_to_words(key, electrum_words, seed_language)) { diff --git a/patches/salvium/0005-UR-functions.patch b/patches/salvium/0005-UR-functions.patch index c3cca26..6fbf271 100644 --- a/patches/salvium/0005-UR-functions.patch +++ b/patches/salvium/0005-UR-functions.patch @@ -41,7 +41,7 @@ diff --git a/.gitmodules b/.gitmodules index ffb73fe9a..72af74d55 100644 --- a/.gitmodules +++ b/.gitmodules -@@ -15,3 +15,7 @@ +@@ -11,6 +11,10 @@ path = external/supercop url = https://github.com/monero-project/supercop branch = monero @@ -49,21 +49,22 @@ index ffb73fe9a..72af74d55 100644 + path = external/bc-ur + url = https://github.com/MrCyjaneK/bc-ur + branch = misc + [submodule "external/miniupnp"] + path = external/miniupnp + url = https://github.com/miniupnp/miniupnp diff --git a/CMakeLists.txt b/CMakeLists.txt index db69b1b04..c73b813d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -96,7 +96,8 @@ enable_language(C ASM) - set(CMAKE_C_STANDARD 11) +@@ -100,6 +100,7 @@ enable_language(C ASM) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_C_EXTENSIONS OFF) --set(CMAKE_CXX_STANDARD 14) -+set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 17) +add_definitions(-D_LIBCPP_ENABLE_CXX17_REMOVED_FEATURES) # boost: no template named 'unary_function' in namespace 'std'; did you mean '__unary_function'? set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) -@@ -364,6 +365,7 @@ if(NOT MANUAL_SUBMODULES) +@@ -367,6 +368,7 @@ if(NOT MANUAL_SUBMODULES) endfunction () message(STATUS "Checking submodules") @@ -75,7 +76,7 @@ diff --git a/external/CMakeLists.txt b/external/CMakeLists.txt index 538e4d215..074e23f16 100644 --- a/external/CMakeLists.txt +++ b/external/CMakeLists.txt -@@ -70,4 +70,5 @@ endif() +@@ -69,4 +69,5 @@ endif() add_subdirectory(db_drivers) add_subdirectory(easylogging++) add_subdirectory(qrcodegen) @@ -86,28 +87,8 @@ new file mode 160000 index 000000000..d82e7c753 --- /dev/null +++ b/external/bc-ur -@@ -0,0 +1 @@ +@@ -0,0 +1,1 @@ +Subproject commit d82e7c753e710b8000706dc3383b498438795208 -diff --git a/src/device/device_ledger.cpp b/src/device/device_ledger.cpp -index 5d0afe1ee..bb5b6f497 100644 ---- a/src/device/device_ledger.cpp -+++ b/src/device/device_ledger.cpp -@@ -313,12 +313,13 @@ namespace hw { - - /* ======================================================================= */ - /* LOCKER */ -- /* ======================================================================= */ -+ /* ======================================================================= */ - - //automatic lock one more level on device ensuring the current thread is allowed to use it -+ #pragma message ("Warning AUTO_LOCK_CMD is intentionally left broken. This is yet to be fixed.") - #define AUTO_LOCK_CMD() \ - /* lock both mutexes without deadlock*/ \ -- boost::lock(device_locker, command_locker); \ -+ /* boost::lock(device_locker, command_locker); */ \ - /* make sure both already-locked mutexes are unlocked at the end of scope */ \ - boost::lock_guard lock1(device_locker, boost::adopt_lock); \ - boost::lock_guard lock2(command_locker, boost::adopt_lock) diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 6095f99d5..b163212b7 100644 --- a/src/wallet/CMakeLists.txt @@ -259,7 +240,7 @@ diff --git a/src/wallet/api/wallet.cpp b/src/wallet/api/wallet.cpp index 89df5c517..3fcd6f332 100644 --- a/src/wallet/api/wallet.cpp +++ b/src/wallet/api/wallet.cpp -@@ -47,6 +47,7 @@ +@@ -48,6 +48,7 @@ #include #include @@ -267,11 +248,11 @@ index 89df5c517..3fcd6f332 100644 using namespace std; using namespace cryptonote; -@@ -1066,6 +1067,24 @@ uint64_t WalletImpl::unlockedBalance(uint32_t accountIndex) const - return m_wallet->unlocked_balance(accountIndex, false); +@@ -961,6 +962,24 @@ uint64_t WalletImpl::unlockedBalance(uint32_t accountIndex) const + return m_wallet->unlocked_balance(accountIndex, asset, false); } -+uint64_t WalletImpl::viewOnlyBalance(uint32_t accountIndex, const std::vector &key_images) const ++uint64_t WalletImpl::viewOnlyBalance(uint32_t accountIndex, const std::vector &key_images, const std::string& asset) const +{ + clearStatus(); + @@ -286,13 +267,13 @@ index 89df5c517..3fcd6f332 100644 + kis.push_back(ki); + } + -+ return m_wallet->view_only_balance(accountIndex, kis); ++ return m_wallet->view_only_balance(accountIndex, kis, asset); +} + uint64_t WalletImpl::blockChainHeight() const { - if(m_wallet->light_wallet()) { -@@ -1208,6 +1227,61 @@ UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_file + return m_wallet->get_blockchain_current_height(); +@@ -1139,6 +1158,61 @@ UnsignedTransaction *WalletImpl::loadUnsignedTx(const std::string &unsigned_file return transaction; } @@ -354,16 +335,7 @@ index 89df5c517..3fcd6f332 100644 bool WalletImpl::submitTransaction(const string &fileName) { clearStatus(); if (checkBackgroundSync("cannot submit tx")) -@@ -1219,7 +1293,7 @@ bool WalletImpl::submitTransaction(const string &fileName) { - setStatus(Status_Ok, tr("Failed to load transaction from file")); - return false; - } -- -+ - if(!transaction->commit()) { - setStatusError(transaction->m_errorString); - return false; -@@ -1228,6 +1302,61 @@ bool WalletImpl::submitTransaction(const string &fileName) { +@@ -1159,6 +1233,61 @@ bool WalletImpl::submitTransaction(const string &fileName) { return true; } @@ -425,7 +397,7 @@ index 89df5c517..3fcd6f332 100644 bool WalletImpl::exportKeyImages(const string &filename, bool all) { if (m_wallet->watch_only()) -@@ -1255,6 +1384,39 @@ bool WalletImpl::exportKeyImages(const string &filename, bool all) +@@ -1186,6 +1318,39 @@ bool WalletImpl::exportKeyImages(const string &filename, bool all) return true; } @@ -465,7 +437,7 @@ index 89df5c517..3fcd6f332 100644 bool WalletImpl::importKeyImages(const string &filename) { if (checkBackgroundSync("cannot import key images")) -@@ -1280,6 +1442,62 @@ bool WalletImpl::importKeyImages(const string &filename) +@@ -1211,6 +1373,62 @@ bool WalletImpl::importKeyImages(const string &filename) return true; } @@ -528,7 +500,7 @@ index 89df5c517..3fcd6f332 100644 bool WalletImpl::exportOutputs(const string &filename, bool all) { if (checkBackgroundSync("cannot export outputs")) -@@ -1312,6 +1530,40 @@ bool WalletImpl::exportOutputs(const string &filename, bool all) +@@ -1243,6 +1461,40 @@ bool WalletImpl::exportOutputs(const string &filename, bool all) return true; } @@ -569,7 +541,7 @@ index 89df5c517..3fcd6f332 100644 bool WalletImpl::importOutputs(const string &filename) { if (checkBackgroundSync("cannot import outputs")) -@@ -1346,6 +1598,61 @@ bool WalletImpl::importOutputs(const string &filename) +@@ -1277,6 +1529,61 @@ bool WalletImpl::importOutputs(const string &filename) return true; } @@ -635,16 +607,16 @@ diff --git a/src/wallet/api/wallet.h b/src/wallet/api/wallet.h index ac7ce2f6a..edf8bb8ce 100644 --- a/src/wallet/api/wallet.h +++ b/src/wallet/api/wallet.h -@@ -112,6 +112,7 @@ public: +@@ -113,6 +113,7 @@ public: bool setProxy(const std::string &address) override; - uint64_t balance(uint32_t accountIndex = 0) const override; - uint64_t unlockedBalance(uint32_t accountIndex = 0) const override; -+ uint64_t viewOnlyBalance(uint32_t accountIndex, const std::vector &key_images) const override; + uint64_t balance(const std::string& asset, uint32_t accountIndex = 0) const override; + uint64_t unlockedBalance(const std::string& asset, uint32_t accountIndex = 0) const override; ++ uint64_t viewOnlyBalance(uint32_t accountIndex, const std::vector &key_images, const std::string& asset = "SAL1") const override; uint64_t blockChainHeight() const override; uint64_t approximateBlockChainHeight() const override; uint64_t estimateBlockChainHeight() const override; -@@ -164,11 +165,18 @@ public: - std::set subaddr_indices = {}) override; +@@ -177,11 +178,18 @@ public: + std::set subaddr_indices = {}) override; virtual PendingTransaction * createSweepUnmixableTransaction() override; bool submitTransaction(const std::string &fileName) override; + bool submitTransactionUR(const std::string &input) override; @@ -666,7 +638,7 @@ diff --git a/src/wallet/api/wallet2_api.h b/src/wallet/api/wallet2_api.h index e349df176..764adbfbf 100644 --- a/src/wallet/api/wallet2_api.h +++ b/src/wallet/api/wallet2_api.h -@@ -91,6 +91,7 @@ struct PendingTransaction +@@ -92,6 +92,7 @@ struct PendingTransaction virtual std::string errorString() const = 0; // commit transaction or save to file if filename is provided. virtual bool commit(const std::string &filename = "", bool overwrite = false) = 0; @@ -674,7 +646,7 @@ index e349df176..764adbfbf 100644 virtual uint64_t amount() const = 0; virtual uint64_t dust() const = 0; virtual uint64_t fee() const = 0; -@@ -160,7 +161,8 @@ struct UnsignedTransaction +@@ -195,7 +196,8 @@ struct UnsignedTransaction * @param signedFileName * return - true on success */ @@ -684,15 +656,15 @@ index e349df176..764adbfbf 100644 }; /** -@@ -626,6 +628,7 @@ struct Wallet - result += unlockedBalance(i); +@@ -668,6 +670,7 @@ struct Wallet + result += unlockedBalance(asset, i); return result; } + virtual uint64_t viewOnlyBalance(uint32_t accountIndex, const std::vector &key_images = {}) const = 0; /** * @brief watchOnly - checks if wallet is watch only -@@ -884,13 +887,15 @@ struct Wallet +@@ -965,13 +968,15 @@ struct Wallet * after object returned */ virtual UnsignedTransaction * loadUnsignedTx(const std::string &unsigned_filename) = 0; @@ -711,7 +683,7 @@ index e349df176..764adbfbf 100644 /*! * \brief disposeTransaction - destroys transaction object -@@ -906,6 +911,8 @@ struct Wallet +@@ -987,6 +992,8 @@ struct Wallet virtual uint64_t estimateTransactionFee(const std::vector> &destinations, PendingTransaction::Priority priority) const = 0; @@ -720,7 +692,7 @@ index e349df176..764adbfbf 100644 /*! * \brief exportKeyImages - exports key images to file * \param filename -@@ -913,20 +920,22 @@ struct Wallet +@@ -994,20 +1001,22 @@ struct Wallet * \return - true on success */ virtual bool exportKeyImages(const std::string &filename, bool all = false) = 0; @@ -745,7 +717,7 @@ index e349df176..764adbfbf 100644 /*! * \brief importOutputs - imports outputs from file -@@ -934,6 +943,7 @@ struct Wallet +@@ -1015,6 +1024,7 @@ struct Wallet * \return - true on success */ virtual bool importOutputs(const std::string &filename) = 0; @@ -757,7 +729,7 @@ diff --git a/src/wallet/wallet2.cpp b/src/wallet/wallet2.cpp index b827b826f..765cefb32 100644 --- a/src/wallet/wallet2.cpp +++ b/src/wallet/wallet2.cpp -@@ -948,6 +948,16 @@ uint32_t get_subaddress_clamped_sum(uint32_t idx, uint32_t extra) +@@ -945,6 +945,16 @@ uint32_t get_subaddress_clamped_sum(uint32_t idx, uint32_t extra) return idx + extra; } @@ -774,33 +746,37 @@ index b827b826f..765cefb32 100644 static void setup_shim(hw::wallet_shim * shim, tools::wallet2 * wallet) { shim->get_tx_pub_key_from_received_outs = std::bind(&tools::wallet2::get_tx_pub_key_from_received_outs, wallet, std::placeholders::_1); -@@ -6997,6 +7007,25 @@ uint64_t wallet2::unlocked_balance(uint32_t index_major, bool strict, uint64_t * +@@ -7088,6 +7098,29 @@ uint64_t wallet2::unlocked_balance(uint32_t index_major, const std::string& asse return amount; } //---------------------------------------------------------------------------------------------------- -+uint64_t wallet2::view_only_balance(uint32_t index_major, const std::vector& selected_inputs) ++uint64_t wallet2::view_only_balance(uint32_t index_major, const std::vector& selected_inputs, const std::string& asset_type) +{ + uint64_t amount = 0; -+ for (const auto &td : m_transfers) { -+ if (is_preferred_input(selected_inputs, td.m_key_image) && -+ !is_spent(td, false) && -+ !td.m_frozen && -+ !td.m_key_image_partial && -+ td.m_key_image_known && -+ td.is_rct() && -+ is_transfer_unlocked(td) && -+ td.m_subaddr_index.major == index_major) ++ if (m_transfers_indices.count(asset_type) > 0) { ++ for (const auto& idx: m_transfers_indices.at(asset_type)) + { -+ amount += td.m_amount; ++ const transfer_details& td = m_transfers[idx]; ++ if (is_preferred_input(selected_inputs, td.m_key_image) && ++ !is_spent(td, false) && ++ !td.m_frozen && ++ !td.m_key_image_partial && ++ td.m_key_image_known && ++ td.is_rct() && ++ is_transfer_unlocked(td) && ++ td.m_subaddr_index.major == index_major) ++ { ++ amount += td.m_amount; ++ } + } + } + return amount; +} +//---------------------------------------------------------------------------------------------------- - std::map wallet2::balance_per_subaddress(uint32_t index_major, bool strict) const + std::map wallet2::balance_per_subaddress(uint32_t index_major, const std::string& asset_type, bool strict) const { std::map amount_per_subaddr; -@@ -7848,9 +7877,7 @@ bool wallet2::sign_tx(unsigned_tx_set &exported_txs, std::vector additional_derivations; @@ -811,7 +787,7 @@ index b827b826f..765cefb32 100644 std::vector additional_tx_pub_keys; for (const crypto::secret_key &skey: txs[n].additional_tx_keys) { -@@ -11246,7 +11273,7 @@ std::vector wallet2::create_transactions_2(std::vector wallet2::create_transactions_2(std::vector m_ignore_outputs_above || td.amount() < m_ignore_outputs_below) { -@@ -11296,9 +11323,15 @@ std::vector wallet2::create_transactions_2(std::vector wallet2::create_transactions_2(std::vector>> wallet2::export_key_images(bool all) const { -@@ -14015,53 +14055,60 @@ std::pair> +@@ -13828,53 +13868,60 @@ std::pair> return std::make_pair(offset, ski); } @@ -985,15 +961,15 @@ diff --git a/src/wallet/wallet2.h b/src/wallet/wallet2.h index daad1e940..a752f15b9 100644 --- a/src/wallet/wallet2.h +++ b/src/wallet/wallet2.h -@@ -1157,6 +1157,7 @@ private: +@@ -1112,6 +1112,7 @@ private: // locked & unlocked balance of given or current subaddress account - uint64_t balance(uint32_t subaddr_index_major, bool strict) const; - uint64_t unlocked_balance(uint32_t subaddr_index_major, bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL); + uint64_t balance(uint32_t subaddr_index_major, const std::string& asset_type, bool strict) const; + uint64_t unlocked_balance(uint32_t subaddr_index_major, const std::string& asset_type, bool strict, uint64_t *blocks_to_unlock = NULL, uint64_t *time_to_unlock = NULL); + uint64_t view_only_balance(uint32_t index_major, const std::vector& selected_inputs = {}); // locked & unlocked balance per subaddress of given or current subaddress account - std::map balance_per_subaddress(uint32_t subaddr_index_major, bool strict) const; - std::map>> unlocked_balance_per_subaddress(uint32_t subaddr_index_major, bool strict); -@@ -1631,9 +1632,11 @@ private: + std::map balance_per_subaddress(uint32_t subaddr_index_major, const std::string& asset_type, bool strict) const; + std::map>> unlocked_balance_per_subaddress(uint32_t subaddr_index_major, const std::string& asset_type, bool strict); +@@ -1596,9 +1597,11 @@ private: std::tuple> export_blockchain() const; void import_blockchain(const std::tuple> &bc); bool export_key_images(const std::string &filename, bool all = false) const;