Skip to content

Commit 055dc5d

Browse files
add monero_wallet_light
1 parent d2f4840 commit 055dc5d

18 files changed

Lines changed: 7985 additions & 522 deletions

CMakeLists.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,15 @@ set(
272272
LIBRARY_SRC_FILES
273273
src/utils/gen_utils.cpp
274274
src/utils/monero_utils.cpp
275+
src/utils/monero_light_client.cpp
276+
src/utils/monero_light_model.cpp
275277
src/daemon/monero_daemon_model.cpp
276278
src/daemon/monero_daemon.cpp
279+
src/wallet/monero_wallet_utils.cpp
277280
src/wallet/monero_wallet_model.cpp
278281
src/wallet/monero_wallet_keys.cpp
279282
src/wallet/monero_wallet_full.cpp
283+
src/wallet/monero_wallet_light.cpp
280284
)
281285

282286
if (BUILD_LIBRARY)
@@ -355,11 +359,15 @@ endif()
355359
DESTINATION include/daemon)
356360
INSTALL(FILES src/utils/gen_utils.h
357361
src/utils/monero_utils.h
362+
src/utils/monero_light_client.h
363+
src/utils/monero_light_model.h
358364
DESTINATION include/utils)
359365
INSTALL(FILES src/wallet/monero_wallet_full.h
366+
src/wallet/monero_wallet_light.h
360367
src/wallet/monero_wallet.h
361368
src/wallet/monero_wallet_keys.h
362369
src/wallet/monero_wallet_model.h
370+
src/wallet/monero_wallet_utils.h
363371
DESTINATION include/wallet)
364372
INSTALL(TARGETS monero-cpp
365373
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT Runtime

src/daemon/monero_daemon_model.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ namespace monero {
447447
if (!src->m_output_indices.empty()) tgt->m_output_indices = std::vector<uint64_t>(src->m_output_indices);
448448
tgt->m_metadata = src->m_metadata;
449449
tgt->m_common_tx_sets = src->m_common_tx_sets;
450-
if (!src->m_extra.empty()) throw std::runtime_error("extra deep copy not implemented"); // TODO: implement extra
450+
if (!src->m_extra.empty()) tgt->m_extra = std::vector<uint8_t>(src->m_extra);
451451
tgt->m_rct_signatures = src->m_rct_signatures;
452452
tgt->m_rct_sig_prunable = src->m_rct_sig_prunable;
453453
tgt->m_is_kept_by_block = src->m_is_kept_by_block;

src/utils/gen_utils.h

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@
5858
#include <boost/uuid/uuid.hpp>
5959
#include <boost/uuid/uuid_generators.hpp>
6060
#include <boost/uuid/uuid_io.hpp>
61+
#include <boost/date_time/posix_time/posix_time.hpp>
62+
#include <boost/date_time/posix_time/posix_time_io.hpp>
6163
#include <chrono>
6264
#include <thread>
6365
#include "include_base_utils.h"
@@ -80,6 +82,52 @@ namespace gen_utils
8082
return boost::uuids::to_string(uuid);
8183
}
8284

85+
static bool is_uint64_t(const std::string& str) {
86+
try {
87+
size_t sz;
88+
std::stol(str, &sz);
89+
return sz == str.size();
90+
}
91+
catch (const std::invalid_argument&) {
92+
// if no conversion could be performed.
93+
return false;
94+
}
95+
catch (const std::out_of_range&) {
96+
// if the converted value would fall out of the range of the result type.
97+
return false;
98+
}
99+
}
100+
101+
static uint64_t uint64_t_cast(const std::string& str) {
102+
if (!is_uint64_t(str)) {
103+
throw std::out_of_range("String provided is not a valid uint64_t");
104+
}
105+
106+
uint64_t value;
107+
108+
std::istringstream itr(str);
109+
110+
itr >> value;
111+
112+
return value;
113+
}
114+
115+
static uint64_t timestamp_to_epoch(const std::string& iso_timestamp) {
116+
// ISO 8601
117+
std::string timestamp = boost::replace_all_copy(iso_timestamp, "T", " ");
118+
boost::replace_all(timestamp, "Z", "");
119+
120+
boost::posix_time::ptime pt = boost::posix_time::time_from_string(timestamp);
121+
boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
122+
boost::posix_time::time_duration diff = pt - epoch;
123+
124+
return static_cast<uint64_t>(diff.total_seconds());
125+
}
126+
127+
static bool bool_equals(bool val, const boost::optional<bool>& opt_val) {
128+
return opt_val == boost::none ? false : val == *opt_val;
129+
}
130+
83131
/**
84132
* Wait for the given duration.
85133
*

0 commit comments

Comments
 (0)