Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
NoRippleCheck.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/Errors.hpp"
5#include "rpc/JS.hpp"
6#include "rpc/common/JsonBool.hpp"
7#include "rpc/common/MetaProcessors.hpp"
8#include "rpc/common/Modifiers.hpp"
9#include "rpc/common/Specs.hpp"
10#include "rpc/common/Types.hpp"
11#include "rpc/common/Validators.hpp"
12
13#include <boost/json/array.hpp>
14#include <boost/json/conversion.hpp>
15#include <boost/json/value.hpp>
16#include <xrpl/protocol/ErrorCodes.h>
17#include <xrpl/protocol/jss.h>
18
19#include <cstdint>
20#include <memory>
21#include <optional>
22#include <string>
23#include <vector>
24
25namespace rpc {
26
36 std::shared_ptr<BackendInterface> sharedPtrBackend_;
37
38public:
39 static constexpr auto kLIMIT_MIN = 1;
40 static constexpr auto kLIMIT_MAX = 500;
41 static constexpr auto kLIMIT_DEFAULT = 300;
42
46 struct Output {
47 std::string ledgerHash;
48 uint32_t ledgerIndex{};
49 std::vector<std::string> problems;
50 // TODO: use better type than json
51 std::optional<boost::json::array> transactions;
52 bool validated = true;
53 };
54
58 struct Input {
59 std::string account;
60 bool roleGateway = false;
61 std::optional<std::string> ledgerHash;
62 std::optional<uint32_t> ledgerIndex;
63 uint32_t limit = kLIMIT_DEFAULT;
64 JsonBool transactions{false};
65 };
66
67 using Result = HandlerReturnType<Output>;
68
74 NoRippleCheckHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
75 : sharedPtrBackend_(std::move(sharedPtrBackend))
76 {
77 }
78
85 static RpcSpecConstRef
86 spec([[maybe_unused]] uint32_t apiVersion)
87 {
88 static auto const kRPC_SPEC_V1 = RpcSpec{
90 {JS(role),
93 validation::OneOf{"gateway", "user"},
94 Status{RippledError::rpcINVALID_PARAMS, "role field is invalid"}
95 }},
98 {JS(limit),
100 validation::Min(1u),
101 modifiers::Clamp<int32_t>{kLIMIT_MIN, kLIMIT_MAX}}
102 };
103
104 static auto const kRPC_SPEC = RpcSpec{
105 kRPC_SPEC_V1,
106 {
107 {JS(transactions), validation::Type<bool>()},
108 }
109 };
110
111 return apiVersion == 1 ? kRPC_SPEC_V1 : kRPC_SPEC;
112 }
113
121 Result
122 process(Input const& input, Context const& ctx) const;
123
124private:
131 friend void
132 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
133
140 friend Input
141 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
142};
143} // namespace rpc
NoRippleCheckHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new NoRippleCheckHandler object.
Definition NoRippleCheck.hpp:74
Result process(Input const &input, Context const &ctx) const
Process the NoRippleCheck command.
Definition NoRippleCheck.cpp:40
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition NoRippleCheck.cpp:198
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition NoRippleCheck.hpp:86
A meta-processor that wraps a validator and produces a custom error in case the wrapped validator fai...
Definition MetaProcessors.hpp:152
Clamp value between min and max.
Definition Modifiers.hpp:23
Validate that value is equal or greater than the specified min.
Definition Validators.hpp:205
Validates that the value is one of the values passed in.
Definition Validators.hpp:364
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< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:62
Context of an RPC call.
Definition Types.hpp:99
A wrapper around bool that allows to convert from any JSON value.
Definition JsonBool.hpp:15
A struct to hold the input data for the command.
Definition NoRippleCheck.hpp:58
A struct to hold the output data of the command.
Definition NoRippleCheck.hpp:46
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:110
Represents a Specification of an entire RPC command.
Definition Specs.hpp:82
A status returned from any RPC handler.
Definition Errors.hpp:65
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:504
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:489
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:551
A validator that simply requires a field to be present.
Definition Validators.hpp:28
Validates that the type of the value is one of the given types.
Definition Validators.hpp:128