Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerData.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/Errors.hpp"
5#include "rpc/common/SpecBackend.hpp"
6#include "rpc/common/Types.hpp"
7#include "util/log/Logger.hpp"
8
9#include <boost/json/array.hpp>
10#include <boost/json/conversion.hpp>
11#include <boost/json/object.hpp>
12#include <boost/json/value.hpp>
13#include <rpcspec/handlers/ledger_data/Types.hpp>
14#include <xrpl/basics/base_uint.h>
15#include <xrpl/protocol/LedgerFormats.h>
16
17#include <cstdint>
18#include <expected>
19#include <memory>
20#include <optional>
21#include <string>
22#include <utility>
23
24namespace rpc {
25
32class LedgerDataHandler : public rpc::HandlerFor<rpc::spec::handlers::ledger_data::Input> {
33 // dependencies
34 std::shared_ptr<BackendInterface> sharedPtrBackend_;
35 util::Logger log_{"RPC"};
36
37public:
38 // constants
39 static constexpr auto kLimitBinary = rpc::spec::handlers::ledger_data::kLimitBinary;
40 static constexpr auto kLimitJson = rpc::spec::handlers::ledger_data::kLimitJson;
41
45 struct Output {
46 uint32_t ledgerIndex{};
47 std::string ledgerHash;
48 std::optional<boost::json::object> header;
49 boost::json::array states;
50 std::optional<std::string> marker;
51 std::optional<uint32_t> diffMarker;
52 std::optional<bool> cacheFull;
53 bool validated = true;
54 };
55
56 using Result = HandlerReturnType<Output>;
57
63 LedgerDataHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
64 : sharedPtrBackend_(std::move(sharedPtrBackend))
65 {
66 }
67
75 [[nodiscard]] Result
76 process(Input const& input, Context const& ctx) const;
77
78private:
85 friend void
86 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
87};
88
89} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the LedgerData command.
Definition LedgerData.cpp:37
LedgerDataHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new LedgerDataHandler object.
Definition LedgerData.hpp:63
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition LedgerData.cpp:158
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:78
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:17
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:61
spec::HandlerFor< InputT, boost::json::value > HandlerFor
The spec-driven base every typed handler inherits.
Definition SpecBackend.hpp:24
Context of an RPC call.
Definition Types.hpp:98
A struct to hold the output data of the command.
Definition LedgerData.hpp:45
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:109