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/Specs.hpp"
6#include "rpc/common/Types.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 <map>
14#include <memory>
15#include <optional>
16#include <string>
17
18namespace rpc {
19
24 std::shared_ptr<BackendInterface> sharedPtrBackend_;
25 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
26
27public:
31 struct Input {
32 std::optional<std::string> ledgerHash;
33 std::optional<uint32_t> ledgerIndex;
34 std::optional<std::string> feature;
35 };
36
40 struct Output {
44 struct Feature {
45 std::string name;
46 std::string key;
47 bool supported = false;
48 bool enabled = false;
49 };
50
51 std::map<std::string, Feature> features;
52 std::string ledgerHash;
53 uint32_t ledgerIndex{};
54
55 // when set to true, output will be inlined in `result` instead of wrapping as `features`
56 // inside of `result`.
57 bool inlineResult = false;
58
59 // validated should be sent via framework
60 bool validated = true;
61 };
62
64
72 std::shared_ptr<BackendInterface> sharedPtrBackend,
73 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
74 )
75 : sharedPtrBackend_(std::move(sharedPtrBackend)), amendmentCenter_(amendmentCenter)
76 {
77 }
78
85 static RpcSpecConstRef
86 spec([[maybe_unused]] uint32_t apiVersion);
87
95 [[nodiscard]] Result
96 process(
97 Input const& input,
98 Context const& ctx
99 ) const; // NOLINT(readability-convert-member-functions-to-static)
100
101private:
108 friend void
109 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
110
117 friend void
118 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output::Feature const& feature);
119
126 friend Input
127 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
128};
129
130} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the Feature command.
Definition Feature.cpp:35
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition Feature.cpp:103
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:122
FeatureHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new FeatureHandler object.
Definition Feature.hpp:71
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 Feature.hpp:31
Represents an amendment/feature.
Definition Feature.hpp:44
A struct to hold the output data of the command.
Definition Feature.hpp:40
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:110