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/Types.hpp"
6
7#include <boost/json/conversion.hpp>
8#include <boost/json/object.hpp>
9#include <boost/json/value.hpp>
10#include <rpcspec/HandlerFor.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::spec::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
41 using Result = HandlerReturnType<Output>;
42
50 std::shared_ptr<BackendInterface> sharedPtrBackend,
51 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter
52 )
53 : sharedPtrBackend_(std::move(sharedPtrBackend))
54 , amendmentCenter_(std::move(amendmentCenter))
55 {
56 }
57
65 [[nodiscard]] Result
66 process(Input const& input, Context const& ctx) const;
67
68private:
75 friend void
76 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
77};
78} // namespace rpc
LedgerHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > amendmentCenter)
Construct a new LedgerHandler object.
Definition Ledger.hpp:49
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:61
Context of an RPC call.
Definition Types.hpp:98
A struct to hold the output data of the command.
Definition Ledger.hpp:33
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:109