aboutsummaryrefslogtreecommitdiff
path: root/contrib/epee/include/storages
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/epee/include/storages')
-rw-r--r--contrib/epee/include/storages/http_abstract_invoke.h5
-rw-r--r--contrib/epee/include/storages/portable_storage_val_converters.h27
2 files changed, 31 insertions, 1 deletions
diff --git a/contrib/epee/include/storages/http_abstract_invoke.h b/contrib/epee/include/storages/http_abstract_invoke.h
index 823ce6731..6517f1253 100644
--- a/contrib/epee/include/storages/http_abstract_invoke.h
+++ b/contrib/epee/include/storages/http_abstract_invoke.h
@@ -44,8 +44,11 @@ namespace epee
if(!serialization::store_t_to_json(out_struct, req_param))
return false;
+ http::fields_list additional_params;
+ additional_params.push_back(std::make_pair("Content-Type","application/json; charset=utf-8"));
+
const http::http_response_info* pri = NULL;
- if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri)))
+ if(!transport.invoke(uri, method, req_param, timeout, std::addressof(pri), std::move(additional_params)))
{
LOG_PRINT_L1("Failed to invoke http request to " << uri);
return false;
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 &&