Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
VersionHandler.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, 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 "rpc/common/APIVersion.hpp"
23#include "rpc/common/Types.hpp"
24#include "rpc/common/impl/APIVersionParser.hpp"
25#include "util/newconfig/ConfigDefinition.hpp"
26
27#include <boost/json/conversion.hpp>
28#include <boost/json/value.hpp>
29
30#include <cstdint>
31
32namespace rpc {
33
40
41public:
45 struct Output {
46 uint32_t minVersion;
47 uint32_t maxVersion;
48 uint32_t currVersion;
49 };
50
57 : apiVersionParser_(
58 config.get<uint32_t>("api_version.default"),
59 config.get<uint32_t>("api_version.min"),
60 config.get<uint32_t>("api_version.max")
61 )
62 {
63 }
64
66
73 Result
74 process([[maybe_unused]] Context const& ctx) const
75 {
76 using namespace rpc;
77
78 auto output = Output{};
79 output.currVersion = apiVersionParser_.getDefaultVersion();
80 output.minVersion = apiVersionParser_.getMinVersion();
81 output.maxVersion = apiVersionParser_.getMaxVersion();
82 return output;
83 }
84
85private:
86 friend void
87 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output)
88 {
89 jv = {
90 {"version",
91 {
92 {"first", output.minVersion},
93 {"last", output.maxVersion},
94 {"good", output.currVersion},
95 }},
96 };
97 }
98};
99
100} // namespace rpc
The version command returns the min,max and current api Version we are using.
Definition VersionHandler.hpp:38
Result process(Context const &ctx) const
Process the version command.
Definition VersionHandler.hpp:74
VersionHandler(util::config::ClioConfigDefinition const &config)
Construct a new Version Handler object.
Definition VersionHandler.hpp:56
Definition APIVersionParser.hpp:34
All the config data will be stored and extracted from this class.
Definition ConfigDefinition.hpp:54
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:36
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:81
Context of an RPC call.
Definition Types.hpp:118
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:129
A struct to hold the output data of the command.
Definition VersionHandler.hpp:45