mirror of
https://github.com/XRPLF/clio.git
synced 2025-12-06 17:27:58 +00:00
@@ -22,6 +22,7 @@
|
||||
#include "rpc/Errors.hpp"
|
||||
#include "rpc/RPCHelpers.hpp"
|
||||
#include "rpc/common/Types.hpp"
|
||||
#include "util/TimeUtils.hpp"
|
||||
|
||||
#include <boost/json/object.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
@@ -65,10 +66,8 @@ TimeFormatValidator::verify(boost::json::value const& value, std::string_view ke
|
||||
if (not value.as_object().at(key).is_string())
|
||||
return Error{Status{RippledError::rpcINVALID_PARAMS}};
|
||||
|
||||
std::tm time = {};
|
||||
std::stringstream stream(value_to<std::string>(value.as_object().at(key)));
|
||||
stream >> std::get_time(&time, format_.c_str());
|
||||
if (stream.fail())
|
||||
auto const ret = util::SystemTpFromUTCStr(value_to<std::string>(value.as_object().at(key)), format_);
|
||||
if (!ret)
|
||||
return Error{Status{RippledError::rpcINVALID_PARAMS}};
|
||||
|
||||
return {};
|
||||
|
||||
@@ -22,19 +22,16 @@
|
||||
#include "rpc/Errors.hpp"
|
||||
#include "rpc/JS.hpp"
|
||||
#include "rpc/common/Types.hpp"
|
||||
#include "util/TimeUtils.hpp"
|
||||
|
||||
#include <boost/json/conversion.hpp>
|
||||
#include <boost/json/object.hpp>
|
||||
#include <boost/json/value.hpp>
|
||||
#include <xrpl/basics/chrono.h>
|
||||
#include <xrpl/basics/strHex.h>
|
||||
#include <xrpl/protocol/jss.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <ctime>
|
||||
#include <iomanip>
|
||||
#include <ranges>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
@@ -61,18 +58,16 @@ LedgerIndexHandler::process(LedgerIndexHandler::Input input, Context const& ctx)
|
||||
return fillOutputByIndex(maxIndex);
|
||||
|
||||
auto const convertISOTimeStrToTicks = [](std::string const& isoTimeStr) {
|
||||
std::tm time = {};
|
||||
std::stringstream ss(isoTimeStr);
|
||||
ss >> std::get_time(&time, DATE_FORMAT);
|
||||
return std::chrono::system_clock::from_time_t(std::mktime(&time)).time_since_epoch().count();
|
||||
auto const systemTime = util::SystemTpFromUTCStr(isoTimeStr, DATE_FORMAT);
|
||||
// systemTime must be valid after validation passed
|
||||
return systemTime->time_since_epoch().count();
|
||||
};
|
||||
|
||||
auto const ticks = convertISOTimeStrToTicks(*input.date);
|
||||
|
||||
auto const earlierThan = [&](std::uint32_t ledgerIndex) {
|
||||
auto const header = sharedPtrBackend_->fetchLedgerBySequence(ledgerIndex, ctx.yield);
|
||||
auto const ledgerTime =
|
||||
std::chrono::system_clock::time_point{header->closeTime.time_since_epoch() + ripple::epoch_offset};
|
||||
auto const ledgerTime = util::SystemTpFromLedgerCloseTime(header->closeTime);
|
||||
return ticks < ledgerTime.time_since_epoch().count();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user