Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Specs.hpp
1#pragma once
2
3#include "rpc/common/Checkers.hpp"
4#include "rpc/common/Concepts.hpp"
5#include "rpc/common/Types.hpp"
6#include "rpc/common/impl/Factories.hpp"
7
8#include <boost/json/array.hpp>
9#include <boost/json/value.hpp>
10
11#include <initializer_list>
12#include <string>
13#include <utility>
14#include <vector>
15
16namespace rpc {
17
21struct FieldSpec final {
30 template <SomeProcessor... Processors>
31 FieldSpec(std::string const& key, Processors&&... processors)
32 : processor_{
33 impl::makeFieldProcessor<Processors...>(key, std::forward<Processors>(processors)...)
34 }
35 , checker_{impl::kEMPTY_FIELD_CHECKER}
36 {
37 }
38
46 template <SomeCheck... Checks>
47 FieldSpec(std::string const& key, Checks&&... checks)
48 : processor_{impl::kEMPTY_FIELD_PROCESSOR}
49 , checker_{impl::makeFieldChecker<Checks...>(key, std::forward<Checks>(checks)...)}
50 {
51 }
52
59 [[nodiscard]] MaybeError
60 process(boost::json::value& value) const;
61
68 [[nodiscard]] check::Warnings
69 check(boost::json::value const& value) const;
70
71private:
72 impl::FieldSpecProcessor processor_;
73 impl::FieldChecker checker_;
74};
75
82struct RpcSpec final {
88 RpcSpec(std::initializer_list<FieldSpec> fields) : fields_{fields}
89 {
90 }
91
98 RpcSpec(RpcSpec const& other, std::initializer_list<FieldSpec> additionalFields)
99 : fields_{other.fields_}
100 {
101 for (auto& f : additionalFields)
102 fields_.push_back(f);
103 }
104
111 [[nodiscard]] MaybeError
112 process(boost::json::value& value) const;
113
120 [[nodiscard]] boost::json::array
121 check(boost::json::value const& value) const;
122
123private:
124 std::vector<FieldSpec> fields_;
125};
126
131
132} // namespace rpc
Specifies what a check used with rpc::FieldSpec must provide.
Definition Concepts.hpp:39
The requirements of a processor to be used with rpc::FieldSpec.
Definition Concepts.hpp:47
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< void, Status > MaybeError
Return type used for Validators that can return error but don't have specific value to return.
Definition Types.hpp:36
FieldSpec(std::string const &key, Checks &&... checks)
Construct a field specification out of a set of checkers.
Definition Specs.hpp:47
MaybeError process(boost::json::value &value) const
Processes the passed JSON value using the stored processors.
Definition Specs.cpp:18
check::Warnings check(boost::json::value const &value) const
Checks the passed JSON value using the stored checkers.
Definition Specs.cpp:24
FieldSpec(std::string const &key, Processors &&... processors)
Construct a field specification out of a set of processors.
Definition Specs.hpp:31
Represents a Specification of an entire RPC command.
Definition Specs.hpp:82
MaybeError process(boost::json::value &value) const
Processes the passed JSON value using the stored field specs.
Definition Specs.cpp:30
RpcSpec(std::initializer_list< FieldSpec > fields)
Construct a full RPC request specification.
Definition Specs.hpp:88
RpcSpec(RpcSpec const &other, std::initializer_list< FieldSpec > additionalFields)
Construct a full RPC request specification from another spec and additional fields.
Definition Specs.hpp:98
boost::json::array check(boost::json::value const &value) const
Checks the passed JSON value using the stored field specs.
Definition Specs.cpp:41