Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
MPTokenIssuanceHistory.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "data/Types.hpp"
5#include "rpc/Errors.hpp"
6#include "rpc/JS.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#include "util/TxUtils.hpp"
13#include "util/log/Logger.hpp"
14
15#include <boost/json/array.hpp>
16#include <boost/json/conversion.hpp>
17#include <boost/json/object.hpp>
18#include <boost/json/value.hpp>
19#include <xrpl/basics/base_uint.h>
20#include <xrpl/protocol/ErrorCodes.h>
21#include <xrpl/protocol/jss.h>
22
23#include <atomic>
24#include <cstdint>
25#include <expected>
26#include <memory>
27#include <optional>
28#include <string>
29#include <utility>
30
31namespace rpc {
32
41 util::Logger log_{"RPC"};
42 std::shared_ptr<BackendInterface> sharedPtrBackend_;
43
49 std::shared_ptr<std::atomic_bool> migrated_ = std::make_shared<std::atomic_bool>(false);
50
51public:
52 static constexpr auto kLimitMin = 1;
53 static constexpr auto kLimitMax = 100;
54 static constexpr auto kLimitDefault = 50;
55
61 static constexpr char const* kMigratorName = "MPTokenIssuanceHistoryMigrator";
62
66 struct Marker {
67 uint32_t ledger;
68 uint32_t seq;
69 };
70
74 struct Output {
75 std::string mptIssuanceID;
76 uint32_t ledgerIndexMin{0};
77 uint32_t ledgerIndexMax{0};
78 std::optional<uint32_t> limit;
79 std::optional<Marker> marker;
81 boost::json::array transactions;
83 bool validated = true;
84 };
85
92 struct Input {
93 std::string mptIssuanceID;
94 std::optional<std::string> account;
95 std::optional<std::string> transactionTypeInLowercase;
96 std::optional<std::string> ledgerHash;
97 std::optional<uint32_t> ledgerIndex;
98 std::optional<int32_t> ledgerIndexMin;
99 std::optional<int32_t> ledgerIndexMax;
100 bool binary = false;
101 bool forward = false;
102 std::optional<uint32_t> limit;
103 std::optional<Marker> marker;
104 };
105
106 using Result = HandlerReturnType<Output>;
107
113 explicit MPTokenIssuanceHistoryHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
114 : sharedPtrBackend_(std::move(sharedPtrBackend))
115 {
116 }
117
124 static RpcSpecConstRef
125 spec([[maybe_unused]] uint32_t apiVersion)
126 {
127 auto const& typesKeysInLowercase = util::getTxTypesInLowercase();
128 static auto const kRpcSpec = RpcSpec{
129 {JS(mpt_issuance_id),
133 {
134 "tx_type",
138 typesKeysInLowercase.cbegin(), typesKeysInLowercase.cend()
139 ),
140 },
143 {JS(ledger_index_min), validation::Type<int32_t>{}},
144 {JS(ledger_index_max), validation::Type<int32_t>{}},
145 {JS(binary), validation::Type<bool>{}},
146 {JS(forward), validation::Type<bool>{}},
147 {JS(limit),
149 validation::Min(1u),
150 modifiers::Clamp<int32_t>{kLimitMin, kLimitMax}},
151 {JS(marker),
154 Status{RippledError::RpcInvalidParams, "invalidMarker"}
155 },
159 }},
160 };
161
162 return kRpcSpec;
163 }
164
172 [[nodiscard]] Result
173 process(Input const& input, Context const& ctx) const;
174
175private:
179 struct SequenceRange {
180 uint32_t min;
181 uint32_t max;
182 };
183
193 [[nodiscard]] MaybeError
194 verifyHistoryAvailable(Context const& ctx) const;
195
207 [[nodiscard]] std::expected<SequenceRange, Status>
208 resolveSequenceRange(Input const& input, Context const& ctx) const;
209
222 [[nodiscard]] data::TransactionsAndCursor
223 fetchTransactions(
224 Input const& input,
225 Context const& ctx,
226 xrpl::uint192 const& mptIssuanceID,
227 SequenceRange range
228 ) const;
229
243 void
244 processTransactionsPage(
245 Input const& input,
246 Context const& ctx,
247 SequenceRange range,
248 data::TransactionsAndCursor const& page,
249 Output& response
250 ) const;
251
261 [[nodiscard]] std::optional<boost::json::object>
262 transactionToJsonIfTypeMatches(
263 data::TransactionAndMetadata const& txnPlusMeta,
264 Input const& input,
265 Context const& ctx
266 ) const;
267
280 [[nodiscard]] boost::json::object
281 expandedTransactionToJson(
282 boost::json::object txn,
283 boost::json::object meta,
284 data::TransactionAndMetadata const& txnPlusMeta,
285 Context const& ctx
286 ) const;
287
294 friend void
295 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
296
303 friend Input
304 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
305
312 friend void
313 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
314};
315
316} // namespace rpc
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition MPTokenIssuanceHistory.hpp:125
Result process(Input const &input, Context const &ctx) const
Process the MPTokenIssuanceHistory command.
Definition MPTokenIssuanceHistory.cpp:47
MPTokenIssuanceHistoryHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new MPTokenIssuanceHistoryHandler object.
Definition MPTokenIssuanceHistory.hpp:113
static constexpr char const * kMigratorName
The name used to query the issuance-history migrator's status.
Definition MPTokenIssuanceHistory.hpp:61
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition MPTokenIssuanceHistory.cpp:286
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
Validates that the value is one of the values passed in.
Definition Validators.hpp:364
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:17
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
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
std::unordered_set< std::string > const & getTxTypesInLowercase()
Get the transaction types in lowercase.
Definition TxUtils.cpp:18
Represents a transaction and its metadata bundled together.
Definition Types.hpp:49
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:153
Context of an RPC call.
Definition Types.hpp:99
A struct to hold the input data for the command.
Definition MPTokenIssuanceHistory.hpp:92
A struct to hold the marker data.
Definition MPTokenIssuanceHistory.hpp:66
A struct to hold the output data of the command.
Definition MPTokenIssuanceHistory.hpp:74
boost::json::array transactions
Definition MPTokenIssuanceHistory.hpp:81
bool validated
Definition MPTokenIssuanceHistory.hpp:83
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:73
Convert input string to lower case.
Definition Modifiers.hpp:66
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 uint192HexStringValidator
Provides a commonly used validator for uint192 hex string.
Definition Validators.hpp:543
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