Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerIndex.hpp
1#pragma once
2#include "data/BackendInterface.hpp"
3#include "rpc/JS.hpp"
4#include "rpc/common/Specs.hpp"
5#include "rpc/common/Types.hpp"
6#include "rpc/common/Validators.hpp"
7
8#include <boost/json/conversion.hpp>
9#include <boost/json/value.hpp>
10#include <xrpl/protocol/jss.h>
11
12#include <cstdint>
13#include <memory>
14#include <optional>
15#include <string>
16
17namespace rpc {
18
24 std::shared_ptr<BackendInterface> sharedPtrBackend_;
25 static constexpr auto kDATE_FORMAT = "%Y-%m-%dT%TZ";
26
27public:
31 struct Output {
32 uint32_t ledgerIndex{};
33 std::string ledgerHash;
34 std::string closeTimeIso;
35 };
36
40 struct Input {
41 std::optional<std::string> date;
42 };
43
44 using Result = HandlerReturnType<Output>;
45
51 LedgerIndexHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
52 : sharedPtrBackend_(std::move(sharedPtrBackend))
53 {
54 }
55
62 static RpcSpecConstRef
63 spec([[maybe_unused]] uint32_t apiVersion)
64 {
65 static auto const kRPC_SPEC = RpcSpec{
66 {JS(date),
69 };
70 return kRPC_SPEC;
71 }
72
80 Result
81 process(Input const& input, Context const& ctx) const;
82
83private:
90 friend void
91 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
92
99 friend Input
100 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
101};
102
103} // namespace rpc
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition LedgerIndex.cpp:90
LedgerIndexHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new LedgerIndexHandler object.
Definition LedgerIndex.hpp:51
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition LedgerIndex.hpp:63
Result process(Input const &input, Context const &ctx) const
Process the LedgerIndex command.
Definition LedgerIndex.cpp:24
Validate that value can be converted to time according to the given format.
Definition Validators.hpp:288
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:18
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:130
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:62
Context of an RPC call.
Definition Types.hpp:99
A struct to hold the input data for the command.
Definition LedgerIndex.hpp:40
A struct to hold the output data of the command.
Definition LedgerIndex.hpp:31
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:110
Represents a Specification of an entire RPC command.
Definition Specs.hpp:82
Validates that the type of the value is one of the given types.
Definition Validators.hpp:128