Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AccountObjects.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/JS.hpp"
5#include "rpc/common/Modifiers.hpp"
6#include "rpc/common/Specs.hpp"
7#include "rpc/common/Types.hpp"
8#include "rpc/common/Validators.hpp"
9
10#include <boost/json/conversion.hpp>
11#include <boost/json/value.hpp>
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/jss.h>
14
15#include <cstdint>
16#include <memory>
17#include <optional>
18#include <string>
19#include <unordered_map>
20#include <unordered_set>
21#include <vector>
22
23namespace rpc {
24
33 // dependencies
34 std::shared_ptr<BackendInterface> sharedPtrBackend_;
35
36public:
37 static constexpr auto kLIMIT_MIN = 10;
38 static constexpr auto kLIMIT_MAX = 400;
39 static constexpr auto kLIMIT_DEFAULT = 200;
40
44 struct Output {
45 std::string account;
46 std::string ledgerHash;
47 uint32_t ledgerIndex{};
48 std::optional<std::string> marker;
49 uint32_t limit{};
50 std::vector<ripple::SLE> accountObjects;
51 bool validated = true;
52 };
53
57 struct Input {
58 std::string account;
59 std::optional<std::string> ledgerHash;
60 std::optional<uint32_t> ledgerIndex;
61 uint32_t limit = kLIMIT_DEFAULT; // [10,400]
62 std::optional<std::string> marker;
63 std::optional<ripple::LedgerEntryType> type;
64 bool deletionBlockersOnly = false;
65 };
66
67 using Result = HandlerReturnType<Output>;
68
74 AccountObjectsHandler(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 = RpcSpec{
92 {JS(limit),
95 modifiers::Clamp<int32_t>(kLIMIT_MIN, kLIMIT_MAX)},
98 {JS(deletion_blockers_only), validation::Type<bool>{}},
99 };
100
101 return kRPC_SPEC;
102 }
103
111 Result
112 process(Input const& input, Context const& ctx) const;
113
114private:
121 friend void
122 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
123
130 friend Input
131 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
132};
133
134} // namespace rpc
AccountObjectsHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new AccountObjectsHandler object.
Definition AccountObjects.hpp:74
Result process(Input const &input, Context const &ctx) const
Process the AccountObjects command.
Definition AccountObjects.cpp:35
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition AccountObjects.hpp:86
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition AccountObjects.cpp:112
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
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
A struct to hold the input data for the command.
Definition AccountObjects.hpp:57
A struct to hold the output data of the command.
Definition AccountObjects.hpp:44
Context of an RPC call.
Definition Types.hpp:99
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
static CustomValidator accountValidator
Provides a commonly used validator for accounts.
Definition Validators.hpp:504
static CustomValidator accountTypeValidator
Provides a validator for account type.
Definition Validators.hpp:527
static CustomValidator accountMarkerValidator
Provides a commonly used validator for markers.
Definition Validators.hpp:519
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