aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include
diff options
context:
space:
mode:
authorJaquee <jaquee.monero@gmail.com>2017-07-22 10:10:21 +0200
committerJaquee <jaquee.monero@gmail.com>2017-10-15 17:29:07 +0200
commit76961ddc3e8f63141e8dc364fadfe189367a31c4 (patch)
tree530b74ddbaec4e3ff83389e2aa73fc64d73fd9c2 /contrib/epee/include
parentepee http_client SSL support (diff)
downloadmonero-76961ddc3e8f63141e8dc364fadfe189367a31c4.tar.xz
Serializer: string to integer conversion for MyMonero compatibility
mymonero timestamp conversion
Diffstat (limited to 'contrib/epee/include')
-rw-r--r--contrib/epee/include/storages/portable_storage_val_converters.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/contrib/epee/include/storages/portable_storage_val_converters.h b/contrib/epee/include/storages/portable_storage_val_converters.h
index e9b91c82b..f4a16cfae 100644
--- a/contrib/epee/include/storages/portable_storage_val_converters.h
+++ b/contrib/epee/include/storages/portable_storage_val_converters.h
@@ -28,6 +28,8 @@
#pragma once
+#include <regex>
+
#include "misc_language.h"
#include "portable_storage_base.h"
#include "warnings.h"
@@ -131,6 +133,31 @@ POP_WARNINGS
}
};
+ // For MyMonero/OpenMonero backend compatibility
+ // MyMonero backend sends amount, fees and timestamp values as strings.
+ // Until MM backend is updated, this is needed for compatibility between OpenMonero and MyMonero.
+ template<>
+ struct convert_to_integral<std::string, uint64_t, false>
+ {
+ static void convert(const std::string& from, uint64_t& to)
+ {
+ MTRACE("Converting std::string to uint64_t. Source: " << from);
+ // String only contains digits
+ if(std::all_of(from.begin(), from.end(), ::isdigit))
+ to = boost::lexical_cast<uint64_t>(from);
+ // MyMonero ISO 8061 timestamp (2017-05-06T16:27:06Z)
+ else if (std::regex_match (from, std::regex("\\d{4}-[01]\\d-[0-3]\\dT[0-2]\\d:[0-5]\\d:[0-5]\\dZ")))
+ {
+ // Convert to unix timestamp
+ std::tm tm = {};
+ std::istringstream ss(from);
+ if (ss >> std::get_time(&tm, "%Y-%m-%dT%H:%M:%S"))
+ to = std::mktime(&tm);
+ } else
+ ASSERT_AND_THROW_WRONG_CONVERSION();
+ }
+ };
+
template<class from_type, class to_type>
struct is_convertable: std::integral_constant<bool,
std::is_integral<to_type>::value &&