Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Processors.hpp
1#pragma once
2
3#include "rpc/common/Concepts.hpp"
4#include "rpc/common/Types.hpp"
5
6#include <boost/json/value.hpp>
7#include <rpcspec/backends/BoostJson.hpp>
8
9#include <utility>
10
11namespace rpc::impl {
12
13template <SomeHandler HandlerType>
14struct DefaultProcessor final {
15 [[nodiscard]] ReturnType
16 operator()(
17 HandlerType const& handler,
18 boost::json::value const& value,
19 Context const& ctx
20 ) const
21 {
22 using boost::json::value_from;
23
24 static_assert(
26 "handler matches none of the branches below"
27 );
28
30 auto input = HandlerType::parseInput(value, ctx.apiVersion);
31 auto warnings = rpc::spec::toJsonArray(HandlerType::spec(ctx.apiVersion).check(value));
32
33 if (not input.has_value())
34 return ReturnType{Error{std::move(input).error()}, std::move(warnings)};
35
36 auto ret = handler.process(*input, ctx);
37
38 if (not ret.has_value())
39 return ReturnType{Error{std::move(ret).error()}, std::move(warnings)};
40
41 return ReturnType{value_from(std::move(ret).value()), std::move(warnings)};
42 }
43
45 // no input to pass, ignore the value
46 auto const ret = handler.process(ctx);
47 if (not ret.has_value())
48 return ReturnType{Error{ret.error()}}; // forward Status
49
50 return ReturnType{value_from(ret.value())};
51 }
52 }
53};
54
55} // namespace rpc::impl
Specifies what a Handler validated by the shared consteval spec must provide.
Definition Concepts.hpp:45
Specifies what a Handler without Input must provide.
Definition Concepts.hpp:55
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:55
Context of an RPC call.
Definition Types.hpp:98
The final return type out of RPC engine.
Definition Types.hpp:66
Definition Processors.hpp:14