Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
APIVersionParser.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 "util/log/Logger.hpp"
24#include "util/newconfig/ObjectView.hpp"
25
26#include <boost/json/object.hpp>
27
28#include <cstdint>
29#include <expected>
30#include <string>
31
32namespace rpc::impl {
33
35 util::Logger log_{"RPC"};
36
37 uint32_t defaultVersion_;
38 uint32_t minVersion_;
39 uint32_t maxVersion_;
40
41public:
43 uint32_t defaultVersion = kAPI_VERSION_DEFAULT,
44 uint32_t minVersion = kAPI_VERSION_MIN,
45 uint32_t maxVersion = kAPI_VERSION_MAX
46 );
47
49
50 std::expected<uint32_t, std::string>
51 parse(boost::json::object const& request) const override;
52
53 uint32_t
54 getDefaultVersion() const
55 {
56 return defaultVersion_;
57 }
58
59 uint32_t
60 getMinVersion() const
61 {
62 return minVersion_;
63 }
64
65 uint32_t
66 getMaxVersion() const
67 {
68 return maxVersion_;
69 }
70};
71
72} // namespace rpc::impl
A baseclass for API version helper.
Definition APIVersion.hpp:48
Definition APIVersionParser.hpp:34
std::expected< uint32_t, std::string > parse(boost::json::object const &request) const override
Extracts API version information from a JSON object.
Definition APIVersionParser.cpp:57
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:40
static constexpr uint32_t kAPI_VERSION_MIN
Minimum API version supported by this build.
Definition APIVersion.hpp:38
static constexpr uint32_t kAPI_VERSION_MAX
Maximum API version supported by this build.
Definition APIVersion.hpp:43
static constexpr uint32_t kAPI_VERSION_DEFAULT
Default API version to use if no version is specified by clients.
Definition APIVersion.hpp:33