Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
NFTHistory.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/Errors.hpp"
5#include "rpc/JS.hpp"
6#include "rpc/common/MetaProcessors.hpp"
7#include "rpc/common/Modifiers.hpp"
8#include "rpc/common/Specs.hpp"
9#include "rpc/common/Types.hpp"
10#include "rpc/common/Validators.hpp"
11#include "util/log/Logger.hpp"
12
13#include <boost/json/array.hpp>
14#include <boost/json/conversion.hpp>
15#include <boost/json/object.hpp>
16#include <boost/json/value.hpp>
17#include <xrpl/protocol/ErrorCodes.h>
18#include <xrpl/protocol/jss.h>
19
20#include <cstdint>
21#include <memory>
22#include <optional>
23#include <string>
24
25namespace rpc {
26
34 util::Logger log_{"RPC"};
35 std::shared_ptr<BackendInterface> sharedPtrBackend_;
36
37public:
38 static constexpr auto kLimitMin = 1;
39 static constexpr auto kLimitMax = 100;
40 static constexpr auto kLimitDefault = 50;
41
45 // TODO: this marker is same as account_tx, reuse in future
46 struct Marker {
47 uint32_t ledger;
48 uint32_t seq;
49 };
50
54 struct Output {
55 std::string nftID;
56 uint32_t ledgerIndexMin{0};
57 uint32_t ledgerIndexMax{0};
58 std::optional<uint32_t> limit;
59 std::optional<Marker> marker;
60 // TODO: use a better type than json
61 boost::json::array transactions;
62 // validated should be sent via framework
63 bool validated = true;
64 };
65
69 struct Input {
70 std::string nftID;
71 // You must use at least one of the following fields in your request:
72 // ledger_index, ledger_hash, ledger_index_min, or ledger_index_max.
73 std::optional<std::string> ledgerHash;
74 std::optional<uint32_t> ledgerIndex;
75 std::optional<int32_t> ledgerIndexMin;
76 std::optional<int32_t> ledgerIndexMax;
77 bool binary = false;
78 bool forward = false;
79 std::optional<uint32_t> limit;
80 std::optional<Marker> marker;
81 };
82
83 using Result = HandlerReturnType<Output>;
84
90 NFTHistoryHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
91 : sharedPtrBackend_(std::move(sharedPtrBackend))
92 {
93 }
94
101 static RpcSpecConstRef
102 spec([[maybe_unused]] uint32_t apiVersion)
103 {
104 static auto const kRpcSpec = RpcSpec{
105 {JS(nft_id),
110 {JS(ledger_index_min), validation::Type<int32_t>{}},
111 {JS(ledger_index_max), validation::Type<int32_t>{}},
112 {JS(binary), validation::Type<bool>{}},
113 {JS(forward), validation::Type<bool>{}},
114 {JS(limit),
116 validation::Min(1u),
117 modifiers::Clamp<int32_t>{kLimitMin, kLimitMax}},
118 {JS(marker),
121 Status{RippledError::rpcINVALID_PARAMS, "invalidMarker"}
122 },
126 }},
127 };
128
129 return kRpcSpec;
130 }
131
139 [[nodiscard]] Result
140 process(Input const& input, Context const& ctx) const;
141
142private:
149 friend void
150 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
151
158 friend Input
159 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
160
167 friend void
168 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
169};
170
171} // namespace rpc
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition NFTHistory.hpp:102
NFTHistoryHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new NFTHistoryHandler object.
Definition NFTHistory.hpp:90
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition NFTHistory.cpp:169
Result process(Input const &input, Context const &ctx) const
Process the NFTHistory command.
Definition NFTHistory.cpp:35
A meta-processor that acts as a spec for a sub-object/section.
Definition MetaProcessors.hpp:24
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
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:78
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 struct to hold the input data for the command.
Definition NFTHistory.hpp:69
A struct to hold the marker data.
Definition NFTHistory.hpp:46
A struct to hold the output data of the command.
Definition NFTHistory.hpp:54
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 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