Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Feature.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/value.hpp>
9#include <rpcspec/HandlerFor.hpp>
10#include <rpcspec/handlers/feature/Types.hpp>
11
12#include <cstdint>
13#include <map>
14#include <memory>
15#include <string>
16#include <utility>
17
18namespace rpc {
19
23class FeatureHandler : public rpc::spec::HandlerFor<rpc::spec::handlers::feature::Input> {
24 std::shared_ptr<BackendInterface> sharedPtrBackend_;
25 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
26
27public:
31 struct Output {
35 struct Feature {
36 std::string name;
37 std::string key;
38 bool supported = false;
39 bool enabled = false;
40 };
41
42 std::map<std::string, Feature> features;
43 std::string ledgerHash;
44 uint32_t ledgerIndex{};
45
46 // when set to true, output will be inlined in `result` instead of wrapping as `features`
47 // inside of `result`.
48 bool inlineResult = false;
49
50 // validated should be sent via framework
51 bool validated = true;
52 };
53
55
63 std::shared_ptr<BackendInterface> sharedPtrBackend,
64 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
65 )
66 : sharedPtrBackend_(std::move(sharedPtrBackend)), amendmentCenter_(amendmentCenter)
67 {
68 }
69
77 [[nodiscard]] Result
78 process(
79 Input const& input,
80 Context const& ctx
81 ) const; // NOLINT(readability-convert-member-functions-to-static)
82
83private:
90 friend void
91 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
92
99 friend void
100 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output::Feature const& feature);
101};
102
103} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the Feature command.
Definition Feature.cpp:29
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition Feature.cpp:96
FeatureHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new FeatureHandler object.
Definition Feature.hpp:62
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
Represents an amendment/feature.
Definition Feature.hpp:35
A struct to hold the output data of the command.
Definition Feature.hpp:31
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:109