Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,10 @@ set(
src/daemon/monero_daemon_model.cpp
src/daemon/monero_daemon.cpp
src/wallet/monero_wallet_model.cpp
src/wallet/monero_wallet_light_model.cpp
src/wallet/monero_wallet_keys.cpp
src/wallet/monero_wallet_full.cpp
src/wallet/monero_wallet_light.cpp
)

if (BUILD_LIBRARY)
Expand Down Expand Up @@ -357,9 +359,12 @@ endif()
src/utils/monero_utils.h
DESTINATION include/utils)
INSTALL(FILES src/wallet/monero_wallet_full.h
src/wallet/monero_wallet_light.h
src/wallet/monero_wallet.h
src/wallet/monero_wallet_keys.h
src/wallet/monero_wallet_model.h
src/wallet/monero_wallet_light_model.h
src/wallet/monero_wallet_utils.h
DESTINATION include/wallet)
INSTALL(TARGETS monero-cpp
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/monero_daemon_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ namespace monero {
if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector<uint64_t>(src->m_output_indices);
tgt->m_metadata = src->m_metadata;
tgt->m_common_tx_sets = src->m_common_tx_sets;
if (!src->m_extra.empty()) throw std::runtime_error("extra deep copy not implemented"); // TODO: implement extra
if (!src->m_extra.empty()) tgt->m_extra = std::vector<uint8_t>(src->m_extra);
tgt->m_rct_signatures = src->m_rct_signatures;
tgt->m_rct_sig_prunable = src->m_rct_sig_prunable;
tgt->m_is_kept_by_block = src->m_is_kept_by_block;
Expand Down
48 changes: 48 additions & 0 deletions src/utils/gen_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#include <boost/uuid/uuid.hpp>
#include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/posix_time/posix_time_io.hpp>
#include <chrono>
#include <thread>
#include "include_base_utils.h"
Expand All @@ -80,6 +82,52 @@ namespace gen_utils
return boost::uuids::to_string(uuid);
}

static bool is_uint64_t(const std::string& str) {
try {
size_t sz;
std::stol(str, &sz);
return sz == str.size();
}
catch (const std::invalid_argument&) {
// if no conversion could be performed.
return false;
}
catch (const std::out_of_range&) {
// if the converted value would fall out of the range of the result type.
return false;
}
}

static uint64_t uint64_t_cast(const std::string& str) {
if (!is_uint64_t(str)) {
throw std::out_of_range("String provided is not a valid uint64_t");
}

uint64_t value;

std::istringstream itr(str);

itr >> value;

return value;
}

static uint64_t timestamp_to_epoch(const std::string& iso_timestamp) {
// ISO 8601
std::string timestamp = boost::replace_all_copy(iso_timestamp, "T", " ");
boost::replace_all(timestamp, "Z", "");

boost::posix_time::ptime pt = boost::posix_time::time_from_string(timestamp);
boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
boost::posix_time::time_duration diff = pt - epoch;

return static_cast<uint64_t>(diff.total_seconds());
}

static bool bool_equals(bool val, const boost::optional<bool>& opt_val) {
return opt_val == boost::none ? false : val == *opt_val;
}

/**
* Wait for the given duration.
*
Expand Down
Loading