Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Ledger.hpp
1#pragma once
2
3#include "data/AmendmentCenterInterface.hpp"
4#include "data/BackendInterface.hpp"
5#include "rpc/common/SpecBackend.hpp"
6#include "rpc/common/Types.hpp"
7
8#include <boost/json/conversion.hpp>
9#include <boost/json/object.hpp>
10#include <boost/json/value.hpp>
11#include <rpcspec/handlers/ledger/Types.hpp>
12
13#include <cstdint>
14#include <memory>
15#include <string>
16#include <utility>
17
18namespace rpc {
19
25class LedgerHandler : public rpc::HandlerFor<rpc::spec::handlers::ledger::Input> {
26 std::shared_ptr<BackendInterface> sharedPtrBackend_;
27 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
28
29public:
33 struct Output {
34 uint32_t ledgerIndex{};
35 std::string ledgerHash;
36 // TODO: use better type
37 boost::json::object header;
38 bool validated = true;
39 };
40
45
53 std::shared_ptr<BackendInterface> sharedPtrBackend,
54 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter
55 )
56 : sharedPtrBackend_(std::move(sharedPtrBackend))
57 , amendmentCenter_(std::move(amendmentCenter))
58 {
59 }
60
68 [[nodiscard]] Result
69 process(Input const& input, Context const& ctx) const;
70
71private:
78 friend void
79 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
80};
81} // namespace rpc
HandlerReturnType< Output > Result
The result type of the command: either the Output or an error status.
Definition Ledger.hpp:44
LedgerHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > amendmentCenter)
Construct a new LedgerHandler object.
Definition Ledger.hpp:52
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition Ledger.cpp:179
Result process(Input const &input, Context const &ctx) const
Process the Ledger command.
Definition Ledger.cpp:32
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:63
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:102
A struct to hold the output data of the command.
Definition Ledger.hpp:33
std::string ledgerHash
Hash of the requested ledger.
Definition Ledger.hpp:35
bool validated
Whether the ledger is validated.
Definition Ledger.hpp:38
uint32_t ledgerIndex
Sequence of the requested ledger.
Definition Ledger.hpp:34
boost::json::object header
Ledger header plus any requested transactions and diff.
Definition Ledger.hpp:37
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:132