From 17b706d44c17dd06bf8cfe5e44e8940f96d3f0ff Mon Sep 17 00:00:00 2001 From: Lee Clagett Date: Tue, 22 Jul 2025 21:05:54 -0400 Subject: [PATCH] Closer to cpp14 compliance for monero_c release branch --- src/backend.cpp | 38 +++++++++++++++++++------------------- src/backend.h | 8 ++++---- src/rpc.cpp | 4 ++-- src/rpc.h | 20 +++++++++++--------- src/wallet.cpp | 4 ++-- src/wallet.h | 6 +++--- src/wallet_manager.cpp | 1 + 7 files changed, 42 insertions(+), 39 deletions(-) diff --git a/src/backend.cpp b/src/backend.cpp index 8754229..1ae6f67 100644 --- a/src/backend.cpp +++ b/src/backend.cpp @@ -243,7 +243,7 @@ namespace lwsf { namespace internal { namespace backend if constexpr (!std::is_const()) { - self.timestamp = std::nullopt; + self.timestamp = boost::none; if (timestamp) self.timestamp = time_point{time_point::duration{boost::numeric_cast(*timestamp)}}; } @@ -320,7 +320,7 @@ namespace lwsf { namespace internal { namespace backend default: throw std::runtime_error{"Unexpected ringct mask type"}; case rpc::ringct::format::none: - out.rct_mask = std::nullopt; + out.rct_mask = boost::none; break; case rpc::ringct::format::encrypted: case rpc::ringct::format::recompute: @@ -356,7 +356,7 @@ namespace lwsf { namespace internal { namespace backend } } - crypto::secret_key get_spend_secret(const account& self, const std::optional& index) + crypto::secret_key get_spend_secret(const account& self, const boost::optional& index) { if (!index || index->is_default()) return self.spend.sec; @@ -378,7 +378,7 @@ namespace lwsf { namespace internal { namespace backend return self.subaccounts[sub.maj_i].last < sub.min_i; // last is inclusive } - std::optional> update_tx(const account& self, transaction& out, const rpc::transaction& source) + boost::optional> update_tx(const account& self, transaction& out, const rpc::transaction& source) { /* Let `receives` re-populate in `merge_output`. This works because the server supplies all info - there is no local info to keep. */ @@ -390,7 +390,7 @@ namespace lwsf { namespace internal { namespace backend if (source.timestamp) out.timestamp = std::chrono::system_clock::from_time_t(*source.timestamp); else - out.timestamp = std::nullopt; + out.timestamp = boost::none; out.fee = std::uint64_t(source.fee.value_or(rpc::uint64_string(0))); out.height = source.height; out.unlock_time = source.unlock_time; @@ -423,7 +423,7 @@ namespace lwsf { namespace internal { namespace backend } if (!std::uint64_t(source.total_received) && !total_spent) - return std::nullopt; // used as decoy + return boost::none; // used as decoy if (out.fee <= total_spent) total_spent -= out.fee; @@ -516,7 +516,7 @@ namespace lwsf { namespace internal { namespace backend if (!rescanning) { - iter->second->height = std::nullopt; + iter->second->height = boost::none; iter->second->failed = false; } } @@ -1266,13 +1266,13 @@ namespace lwsf { namespace internal { namespace backend this->import_error = {}; else this->import_error = value.error(); - return value - } + return value; + }; boost::unique_lock lock{sync}; if (primary.restore_height <= height) - return update_import(import_response{}); + return update_import(rpc::import_response{}); if (import_error && import_error == error::import_pending) return import_error; @@ -1289,14 +1289,14 @@ namespace lwsf { namespace internal { namespace backend rpc::login login{primary.address, primary.view.sec}; lock.unlock(); - const auto import = rpc::invoke(client, login); + auto import = rpc::invoke(client, login); lock.lock(); if (!import) return update_import(import.error()); if (import->request_fulfilled) - return update_import(std::move(*import)); + return update_import(std::move(import)); const unsigned total = unsigned(bool(import->import_fee)) + bool(import->payment_address); @@ -1304,22 +1304,22 @@ namespace lwsf { namespace internal { namespace backend { default: case 0: - return update_import(error::import_pending); + return update_import({error::import_pending}); case 1: if (import->import_fee.value_or(rpc::uint64_string(0)) == rpc::uint64_string(0)) - return update_import(error::import_pending); - return update_import(error::import_invalid); + return update_import({error::import_pending}); + return update_import({error::import_invalid}); case 2: break; } cryptonote::address_parse_info info{}; if (!cryptonote::get_account_address_from_str(info, convert_net_type(primary.type), *import->payment_address)) - return update_import(error::import_invalid); + return update_import({error::import_invalid}); if (info.has_payment_id && import->payment_id) - return update_import(error::import_invalid); + return update_import({error::import_invalid}); if (import->payment_id && (import->payment_id->empty() || (import->payment_id->size() != sizeof(crypto::hash8) && import->payment_id->size() != sizeof(crypto::hash)))) - return update_import(error::import_invalid); + return update_import({error::import_invalid}); #ifdef LWSF_MASTER_ENABLE std::string payment_id; @@ -1342,7 +1342,7 @@ namespace lwsf { namespace internal { namespace backend else primary.addressbook[i] = address_book_entry{std::move(*import->payment_address), std::move(payment_id), std::move(description)}; #endif - return update_import(std::move(*import)); + return update_import(std::move(import)); } expect> wallet::get_decoys(const rpc::get_random_outs_request& req) diff --git a/src/backend.h b/src/backend.h index e773a32..f93fb15 100644 --- a/src/backend.h +++ b/src/backend.h @@ -30,6 +30,7 @@ #include #include +#include #include #include #include @@ -37,7 +38,6 @@ #include #include #include -#include #include #include #include @@ -130,7 +130,7 @@ namespace lwsf { namespace internal { namespace backend std::uint64_t amount; rpc::address_meta recipient; std::uint16_t index; - std::optional rct_mask; + boost::optional rct_mask; crypto::public_key tx_pub; transfer_in() noexcept @@ -178,8 +178,8 @@ namespace lwsf { namespace internal { namespace backend boost::container::flat_map receives; //!< Key is output pub std::vector transfers; std::string description; - std::optional timestamp; //!< guaranteed to be unix epoch in C++20 - std::optional height; + boost::optional timestamp; //!< guaranteed to be unix epoch in C++20 + boost::optional height; std::uint64_t amount; std::uint64_t fee; std::uint64_t unlock_time; diff --git a/src/rpc.cpp b/src/rpc.cpp index 46e3cae..a07f3e7 100644 --- a/src/rpc.cpp +++ b/src/rpc.cpp @@ -184,8 +184,8 @@ namespace lwsf { namespace internal { namespace rpc { using min_spent = wire::min_element_sizeof; - std::optional timestamp; - std::optional payment_id; + boost::optional timestamp; + boost::optional payment_id; wire::object(source, WIRE_FIELD_ARRAY(spent_outputs, min_spent), wire::optional_field("payment_id", std::ref(payment_id)), diff --git a/src/rpc.h b/src/rpc.h index 4e7758a..b37c867 100644 --- a/src/rpc.h +++ b/src/rpc.h @@ -29,9 +29,9 @@ #pragma once #include +#include #include #include -#include #include #include #include @@ -120,7 +120,7 @@ namespace lwsf { namespace internal { namespace rpc login_response() = delete; static constexpr const char* endpoint() noexcept { return "/login"; } - std::optional start_height; + boost::optional start_height; }; void read_bytes(wire::json_reader&, login_response&); @@ -171,7 +171,7 @@ namespace lwsf { namespace internal { namespace rpc struct transaction_spend { uint64_string amount; - std::optional sender; + boost::optional sender; std::uint16_t out_index; crypto::key_image key_image; crypto::public_key tx_pub_key; @@ -190,11 +190,11 @@ namespace lwsf { namespace internal { namespace rpc { std::vector spent_outputs; std::variant payment_id; - std::optional timestamp; - std::optional fee; + boost::optional timestamp; + boost::optional fee; uint64_string total_received; std::uint64_t unlock_time; - std::optional height; + boost::optional height; crypto::hash hash; bool coinbase; bool mempool; @@ -380,11 +380,13 @@ namespace lwsf { namespace internal { namespace rpc struct import_response { import_response() = delete; + import_response(import_response&&) = default; + import_response(const import_response&) = delete; static constexpr const char* endpoint() noexcept { return "/import_wallet_request"; } - std::optional payment_address; - std::optional payment_id; - std::optional import_fee; + boost::optional payment_address; + boost::optional payment_id; + boost::optional import_fee; std::string status; bool new_request; bool request_fulfilled; diff --git a/src/wallet.cpp b/src/wallet.cpp index 5e91589..f123654 100644 --- a/src/wallet.cpp +++ b/src/wallet.cpp @@ -387,7 +387,7 @@ namespace lwsf { namespace internal std::vector out; std::filesystem::path work_dir(path); if(!std::filesystem::is_directory(path)) - return out; + return out; std::filesystem::recursive_directory_iterator end_itr; for (std::filesystem::recursive_directory_iterator itr(path); itr != end_itr; ++itr) @@ -1921,6 +1921,6 @@ namespace lwsf { namespace internal payment_address = import->payment_address.value_or({}); status = std::move(import->status); } -#endif LWSF_MASTER_ENABLE +#endif // LWSF_MASTER_ENABLE }} // lwsf // internal diff --git a/src/wallet.h b/src/wallet.h index 6dad380..ec86f2f 100644 --- a/src/wallet.h +++ b/src/wallet.h @@ -270,7 +270,7 @@ namespace internal * @brief watchOnly - checks if wallet is watch only * @return - true if watch only */ - virtual bool watchOnly() const override { /* TODO */ return false; } + virtual bool watchOnly() const override { return false; } /** * @brief isDeterministic - checks if wallet keys are deterministic @@ -428,7 +428,7 @@ namespace internal * @return new info string if more rounds required or exception if no more rounds (i.e. no rounds to boost) */ virtual std::string getMultisigKeyExchangeBooster(const std::vector &info, const uint32_t threshold, const uint32_t num_signers) override { /* TODO */ return {}; } -#endif +#endif // LWSF_MASTER_ENABLE /** * @brief exportMultisigImages - exports transfers' key images @@ -737,7 +737,7 @@ namespace internal //! Initiates a light wallet import wallet request virtual bool lightWalletImportWalletRequest(std::string &payment_id, uint64_t &fee, bool &new_request, bool &request_fulfilled, std::string &payment_address, std::string &status) override; -#endif LWSF_MASTER_ENABLE +#endif // LWSF_MASTER_ENABLE //! locks/unlocks the keys file; returns true on success virtual bool lockKeysFile() override { return false; } diff --git a/src/wallet_manager.cpp b/src/wallet_manager.cpp index 12a560d..6c14bff 100644 --- a/src/wallet_manager.cpp +++ b/src/wallet_manager.cpp @@ -291,6 +291,7 @@ namespace lwsf bool queryWalletDevice(Monero::Wallet::Device& device_type, const std::string &keys_file_name, const std::string &password, uint64_t kdf_rounds) const override { //! \TODO Complete + return false; } /*!