Closer to cpp14 compliance for monero_c release branch

This commit is contained in:
Lee Clagett
2025-07-22 21:05:54 -04:00
parent 93d7ff1eeb
commit 17b706d44c
7 changed files with 42 additions and 39 deletions
+19 -19
View File
@@ -243,7 +243,7 @@ namespace lwsf { namespace internal { namespace backend
if constexpr (!std::is_const<T>()) if constexpr (!std::is_const<T>())
{ {
self.timestamp = std::nullopt; self.timestamp = boost::none;
if (timestamp) if (timestamp)
self.timestamp = time_point{time_point::duration{boost::numeric_cast<time_point::rep>(*timestamp)}}; self.timestamp = time_point{time_point::duration{boost::numeric_cast<time_point::rep>(*timestamp)}};
} }
@@ -320,7 +320,7 @@ namespace lwsf { namespace internal { namespace backend
default: default:
throw std::runtime_error{"Unexpected ringct mask type"}; throw std::runtime_error{"Unexpected ringct mask type"};
case rpc::ringct::format::none: case rpc::ringct::format::none:
out.rct_mask = std::nullopt; out.rct_mask = boost::none;
break; break;
case rpc::ringct::format::encrypted: case rpc::ringct::format::encrypted:
case rpc::ringct::format::recompute: 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<rpc::address_meta>& index) crypto::secret_key get_spend_secret(const account& self, const boost::optional<rpc::address_meta>& index)
{ {
if (!index || index->is_default()) if (!index || index->is_default())
return self.spend.sec; 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 return self.subaccounts[sub.maj_i].last < sub.min_i; // last is inclusive
} }
std::optional<std::vector<rpc::address_meta>> update_tx(const account& self, transaction& out, const rpc::transaction& source) boost::optional<std::vector<rpc::address_meta>> update_tx(const account& self, transaction& out, const rpc::transaction& source)
{ {
/* Let `receives` re-populate in `merge_output`. This works because the /* Let `receives` re-populate in `merge_output`. This works because the
server supplies all info - there is no local info to keep. */ server supplies all info - there is no local info to keep. */
@@ -390,7 +390,7 @@ namespace lwsf { namespace internal { namespace backend
if (source.timestamp) if (source.timestamp)
out.timestamp = std::chrono::system_clock::from_time_t(*source.timestamp); out.timestamp = std::chrono::system_clock::from_time_t(*source.timestamp);
else else
out.timestamp = std::nullopt; out.timestamp = boost::none;
out.fee = std::uint64_t(source.fee.value_or(rpc::uint64_string(0))); out.fee = std::uint64_t(source.fee.value_or(rpc::uint64_string(0)));
out.height = source.height; out.height = source.height;
out.unlock_time = source.unlock_time; 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) 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) if (out.fee <= total_spent)
total_spent -= out.fee; total_spent -= out.fee;
@@ -516,7 +516,7 @@ namespace lwsf { namespace internal { namespace backend
if (!rescanning) if (!rescanning)
{ {
iter->second->height = std::nullopt; iter->second->height = boost::none;
iter->second->failed = false; iter->second->failed = false;
} }
} }
@@ -1266,13 +1266,13 @@ namespace lwsf { namespace internal { namespace backend
this->import_error = {}; this->import_error = {};
else else
this->import_error = value.error(); this->import_error = value.error();
return value return value;
} };
boost::unique_lock<boost::mutex> lock{sync}; boost::unique_lock<boost::mutex> lock{sync};
if (primary.restore_height <= height) if (primary.restore_height <= height)
return update_import(import_response{}); return update_import(rpc::import_response{});
if (import_error && import_error == error::import_pending) if (import_error && import_error == error::import_pending)
return import_error; return import_error;
@@ -1289,14 +1289,14 @@ namespace lwsf { namespace internal { namespace backend
rpc::login login{primary.address, primary.view.sec}; rpc::login login{primary.address, primary.view.sec};
lock.unlock(); lock.unlock();
const auto import = rpc::invoke<rpc::import_response>(client, login); auto import = rpc::invoke<rpc::import_response>(client, login);
lock.lock(); lock.lock();
if (!import) if (!import)
return update_import(import.error()); return update_import(import.error());
if (import->request_fulfilled) if (import->request_fulfilled)
return update_import(std::move(*import)); return update_import(std::move(import));
const unsigned total = const unsigned total =
unsigned(bool(import->import_fee)) + bool(import->payment_address); unsigned(bool(import->import_fee)) + bool(import->payment_address);
@@ -1304,22 +1304,22 @@ namespace lwsf { namespace internal { namespace backend
{ {
default: default:
case 0: case 0:
return update_import(error::import_pending); return update_import({error::import_pending});
case 1: case 1:
if (import->import_fee.value_or(rpc::uint64_string(0)) == rpc::uint64_string(0)) 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_pending});
return update_import(error::import_invalid); return update_import({error::import_invalid});
case 2: case 2:
break; break;
} }
cryptonote::address_parse_info info{}; cryptonote::address_parse_info info{};
if (!cryptonote::get_account_address_from_str(info, convert_net_type(primary.type), *import->payment_address)) 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) 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)))) 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 #ifdef LWSF_MASTER_ENABLE
std::string payment_id; std::string payment_id;
@@ -1342,7 +1342,7 @@ namespace lwsf { namespace internal { namespace backend
else else
primary.addressbook[i] = address_book_entry{std::move(*import->payment_address), std::move(payment_id), std::move(description)}; primary.addressbook[i] = address_book_entry{std::move(*import->payment_address), std::move(payment_id), std::move(description)};
#endif #endif
return update_import(std::move(*import)); return update_import(std::move(import));
} }
expect<std::vector<rpc::random_outputs>> wallet::get_decoys(const rpc::get_random_outs_request& req) expect<std::vector<rpc::random_outputs>> wallet::get_decoys(const rpc::get_random_outs_request& req)
+4 -4
View File
@@ -30,6 +30,7 @@
#include <atomic> #include <atomic>
#include <boost/container/flat_map.hpp> #include <boost/container/flat_map.hpp>
#include <boost/optional/optional.hpp>
#include <boost/thread/mutex.hpp> #include <boost/thread/mutex.hpp>
#include <chrono> #include <chrono>
#include <cstdint> #include <cstdint>
@@ -37,7 +38,6 @@
#include <filesystem> #include <filesystem>
#include <map> #include <map>
#include <memory> #include <memory>
#include <optional>
#include <unordered_map> #include <unordered_map>
#include <type_traits> #include <type_traits>
#include <variant> #include <variant>
@@ -130,7 +130,7 @@ namespace lwsf { namespace internal { namespace backend
std::uint64_t amount; std::uint64_t amount;
rpc::address_meta recipient; rpc::address_meta recipient;
std::uint16_t index; std::uint16_t index;
std::optional<rct::key> rct_mask; boost::optional<rct::key> rct_mask;
crypto::public_key tx_pub; crypto::public_key tx_pub;
transfer_in() noexcept transfer_in() noexcept
@@ -178,8 +178,8 @@ namespace lwsf { namespace internal { namespace backend
boost::container::flat_map<crypto::public_key, transfer_in, memory> receives; //!< Key is output pub boost::container::flat_map<crypto::public_key, transfer_in, memory> receives; //!< Key is output pub
std::vector<transfer_out> transfers; std::vector<transfer_out> transfers;
std::string description; std::string description;
std::optional<std::chrono::system_clock::time_point> timestamp; //!< guaranteed to be unix epoch in C++20 boost::optional<std::chrono::system_clock::time_point> timestamp; //!< guaranteed to be unix epoch in C++20
std::optional<std::uint64_t> height; boost::optional<std::uint64_t> height;
std::uint64_t amount; std::uint64_t amount;
std::uint64_t fee; std::uint64_t fee;
std::uint64_t unlock_time; std::uint64_t unlock_time;
+2 -2
View File
@@ -184,8 +184,8 @@ namespace lwsf { namespace internal { namespace rpc
{ {
using min_spent = wire::min_element_sizeof<crypto::key_image>; using min_spent = wire::min_element_sizeof<crypto::key_image>;
std::optional<std::string> timestamp; boost::optional<std::string> timestamp;
std::optional<epee::byte_slice> payment_id; boost::optional<epee::byte_slice> payment_id;
wire::object(source, wire::object(source,
WIRE_FIELD_ARRAY(spent_outputs, min_spent), WIRE_FIELD_ARRAY(spent_outputs, min_spent),
wire::optional_field("payment_id", std::ref(payment_id)), wire::optional_field("payment_id", std::ref(payment_id)),
+11 -9
View File
@@ -29,9 +29,9 @@
#pragma once #pragma once
#include <boost/container/flat_set.hpp> #include <boost/container/flat_set.hpp>
#include <boost/optional/optional.hpp>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <ctime> #include <ctime>
#include <optional>
#include <system_error> #include <system_error>
#include <type_traits> #include <type_traits>
#include <vector> #include <vector>
@@ -120,7 +120,7 @@ namespace lwsf { namespace internal { namespace rpc
login_response() = delete; login_response() = delete;
static constexpr const char* endpoint() noexcept { return "/login"; } static constexpr const char* endpoint() noexcept { return "/login"; }
std::optional<std::uint64_t> start_height; boost::optional<std::uint64_t> start_height;
}; };
void read_bytes(wire::json_reader&, login_response&); void read_bytes(wire::json_reader&, login_response&);
@@ -171,7 +171,7 @@ namespace lwsf { namespace internal { namespace rpc
struct transaction_spend struct transaction_spend
{ {
uint64_string amount; uint64_string amount;
std::optional<address_meta> sender; boost::optional<address_meta> sender;
std::uint16_t out_index; std::uint16_t out_index;
crypto::key_image key_image; crypto::key_image key_image;
crypto::public_key tx_pub_key; crypto::public_key tx_pub_key;
@@ -190,11 +190,11 @@ namespace lwsf { namespace internal { namespace rpc
{ {
std::vector<transaction_spend> spent_outputs; std::vector<transaction_spend> spent_outputs;
std::variant<empty, crypto::hash8, crypto::hash> payment_id; std::variant<empty, crypto::hash8, crypto::hash> payment_id;
std::optional<std::time_t> timestamp; boost::optional<std::time_t> timestamp;
std::optional<uint64_string> fee; boost::optional<uint64_string> fee;
uint64_string total_received; uint64_string total_received;
std::uint64_t unlock_time; std::uint64_t unlock_time;
std::optional<std::uint64_t> height; boost::optional<std::uint64_t> height;
crypto::hash hash; crypto::hash hash;
bool coinbase; bool coinbase;
bool mempool; bool mempool;
@@ -380,11 +380,13 @@ namespace lwsf { namespace internal { namespace rpc
struct import_response struct import_response
{ {
import_response() = delete; import_response() = delete;
import_response(import_response&&) = default;
import_response(const import_response&) = delete;
static constexpr const char* endpoint() noexcept { return "/import_wallet_request"; } static constexpr const char* endpoint() noexcept { return "/import_wallet_request"; }
std::optional<std::string> payment_address; boost::optional<std::string> payment_address;
std::optional<epee::byte_slice> payment_id; boost::optional<epee::byte_slice> payment_id;
std::optional<uint64_string> import_fee; boost::optional<uint64_string> import_fee;
std::string status; std::string status;
bool new_request; bool new_request;
bool request_fulfilled; bool request_fulfilled;
+2 -2
View File
@@ -387,7 +387,7 @@ namespace lwsf { namespace internal
std::vector<std::string> out; std::vector<std::string> out;
std::filesystem::path work_dir(path); std::filesystem::path work_dir(path);
if(!std::filesystem::is_directory(path)) if(!std::filesystem::is_directory(path))
return out; return out;
std::filesystem::recursive_directory_iterator end_itr; std::filesystem::recursive_directory_iterator end_itr;
for (std::filesystem::recursive_directory_iterator itr(path); itr != end_itr; ++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({}); payment_address = import->payment_address.value_or({});
status = std::move(import->status); status = std::move(import->status);
} }
#endif LWSF_MASTER_ENABLE #endif // LWSF_MASTER_ENABLE
}} // lwsf // internal }} // lwsf // internal
+3 -3
View File
@@ -270,7 +270,7 @@ namespace internal
* @brief watchOnly - checks if wallet is watch only * @brief watchOnly - checks if wallet is watch only
* @return - true if 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 * @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) * @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<std::string> &info, const uint32_t threshold, const uint32_t num_signers) override { /* TODO */ return {}; } virtual std::string getMultisigKeyExchangeBooster(const std::vector<std::string> &info, const uint32_t threshold, const uint32_t num_signers) override { /* TODO */ return {}; }
#endif #endif // LWSF_MASTER_ENABLE
/** /**
* @brief exportMultisigImages - exports transfers' key images * @brief exportMultisigImages - exports transfers' key images
@@ -737,7 +737,7 @@ namespace internal
//! Initiates a light wallet import wallet request //! 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; 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 //! locks/unlocks the keys file; returns true on success
virtual bool lockKeysFile() override { return false; } virtual bool lockKeysFile() override { return false; }
+1
View File
@@ -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 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 //! \TODO Complete
return false;
} }
/*! /*!