Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Feature.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include "data/AmendmentCenterInterface.hpp"
23#include "data/BackendInterface.hpp"
24#include "rpc/common/Specs.hpp"
25#include "rpc/common/Types.hpp"
26
27#include <boost/json/conversion.hpp>
28#include <boost/json/value.hpp>
29#include <xrpl/protocol/jss.h>
30
31#include <cstdint>
32#include <map>
33#include <memory>
34#include <optional>
35#include <string>
36
37namespace rpc {
38
43 std::shared_ptr<BackendInterface> sharedPtrBackend_;
44 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
45
46public:
50 struct Input {
51 std::optional<std::string> ledgerHash;
52 std::optional<uint32_t> ledgerIndex;
53 std::optional<std::string> feature;
54 };
55
59 struct Output {
63 struct Feature {
64 std::string name;
65 std::string key;
66 bool supported = false;
67 bool enabled = false;
68 };
69
70 std::map<std::string, Feature> features;
71 std::string ledgerHash;
72 uint32_t ledgerIndex{};
73
74 // when set to true, output will be inlined in `result` instead of wrapping as `features` inside of `result`.
75 bool inlineResult = false;
76
77 // validated should be sent via framework
78 bool validated = true;
79 };
80
82
90 std::shared_ptr<BackendInterface> const& backend,
91 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
92 )
93 : sharedPtrBackend_(backend), amendmentCenter_(amendmentCenter)
94 {
95 }
96
103 static RpcSpecConstRef
104 spec([[maybe_unused]] uint32_t apiVersion);
105
113 Result
114 process(Input input, Context const& ctx) const; // NOLINT(readability-convert-member-functions-to-static)
115
116private:
123 friend void
124 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
125
132 friend void
133 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output::Feature const& feature);
134
141 friend Input
142 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
143};
144
145} // namespace rpc
Contains common functionality for handling the server_info command.
Definition Feature.hpp:42
FeatureHandler(std::shared_ptr< BackendInterface > const &backend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new FeatureHandler object.
Definition Feature.hpp:89
Result process(Input input, Context const &ctx) const
Process the Feature command.
Definition Feature.cpp:54
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition Feature.cpp:113
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:129
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:36
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:145
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:81
Context of an RPC call.
Definition Types.hpp:118
A struct to hold the input data for the command.
Definition Feature.hpp:50
Represents an amendment/feature.
Definition Feature.hpp:63
A struct to hold the output data of the command.
Definition Feature.hpp:59
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:129