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/common/SpecBackend.hpp"
6#include "rpc/common/Types.hpp"
7#include "util/log/Logger.hpp"
8
9#include <boost/json/array.hpp>
10#include <boost/json/conversion.hpp>
11#include <boost/json/object.hpp>
12#include <boost/json/value.hpp>
13#include <rpcspec/handlers/mptoken_issuance_history/Types.hpp>
14#include <xrpl/basics/base_uint.h>
15
16#include <atomic>
17#include <cstdint>
18#include <expected>
19#include <memory>
20#include <optional>
21#include <string>
22#include <utility>
23
24namespace rpc {
25
34 : public rpc::HandlerFor<rpc::spec::handlers::mptoken_issuance_history::Input> {
35 util::Logger log_{"RPC"};
36 std::shared_ptr<BackendInterface> sharedPtrBackend_;
37
43 std::shared_ptr<std::atomic_bool> migrated_ = std::make_shared<std::atomic_bool>(false);
44
45public:
49 static constexpr auto kLimitMin = rpc::spec::handlers::mptoken_issuance_history::kLimitMin;
53 static constexpr auto kLimitMax = rpc::spec::handlers::mptoken_issuance_history::kLimitMax;
57 static constexpr auto kLimitDefault =
58 rpc::spec::handlers::mptoken_issuance_history::kLimitDefault;
59
65 static constexpr char const* kMigratorName = "MPTokenIssuanceHistoryMigrator";
66
70 using Marker = rpc::spec::handlers::mptoken_issuance_history::Marker;
71
75 struct Output {
76 std::string mptIssuanceID;
77 uint32_t ledgerIndexMin{0};
78 uint32_t ledgerIndexMax{0};
79 std::optional<uint32_t> limit;
80 std::optional<Marker> marker;
85 boost::json::array transactions;
90 bool validated = true;
91 };
92
97
103 explicit MPTokenIssuanceHistoryHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
104 : sharedPtrBackend_(std::move(sharedPtrBackend))
105 {
106 }
107
115 [[nodiscard]] Result
116 process(Input const& input, Context const& ctx) const;
117
118private:
122 struct SequenceRange {
123 uint32_t min;
124 uint32_t max;
125 };
126
136 [[nodiscard]] MaybeError
137 verifyHistoryAvailable(Context const& ctx) const;
138
150 [[nodiscard]] std::expected<SequenceRange, Status>
151 resolveSequenceRange(Input const& input, Context const& ctx) const;
152
165 [[nodiscard]] data::TransactionsAndCursor
166 fetchTransactions(
167 Input const& input,
168 Context const& ctx,
169 xrpl::uint192 const& mptIssuanceID,
170 SequenceRange range
171 ) const;
172
186 void
187 processTransactionsPage(
188 Input const& input,
189 Context const& ctx,
190 SequenceRange range,
191 data::TransactionsAndCursor const& page,
192 Output& response
193 ) const;
194
204 [[nodiscard]] std::optional<boost::json::object>
205 transactionToJsonIfTypeMatches(
206 data::TransactionAndMetadata const& txnPlusMeta,
207 Input const& input,
208 Context const& ctx
209 ) const;
210
223 [[nodiscard]] boost::json::object
224 expandedTransactionToJson(
225 boost::json::object txn,
226 boost::json::object meta,
227 data::TransactionAndMetadata const& txnPlusMeta,
228 Context const& ctx
229 ) const;
230
237 friend void
238 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
239};
240
241} // namespace rpc
242
248
255void
256tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Marker const& marker);
257
258} // namespace rpc::spec::handlers::mptoken_issuance_history
HandlerReturnType< Output > Result
The result type of the command: either the Output or an error status.
Definition MPTokenIssuanceHistory.hpp:96
Result process(Input const &input, Context const &ctx) const
Process the MPTokenIssuanceHistory command.
Definition MPTokenIssuanceHistory.cpp:48
MPTokenIssuanceHistoryHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new MPTokenIssuanceHistoryHandler object.
Definition MPTokenIssuanceHistory.hpp:103
static constexpr auto kLimitMax
Maximum allowed value of the limit parameter.
Definition MPTokenIssuanceHistory.hpp:53
rpc::spec::handlers::mptoken_issuance_history::Marker Marker
A struct to hold the marker data.
Definition MPTokenIssuanceHistory.hpp:70
static constexpr auto kLimitDefault
Default value of the limit parameter.
Definition MPTokenIssuanceHistory.hpp:57
static constexpr char const * kMigratorName
The name used to query the issuance-history migrator's status.
Definition MPTokenIssuanceHistory.hpp:65
static constexpr auto kLimitMin
Minimum allowed value of the limit parameter.
Definition MPTokenIssuanceHistory.hpp:49
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:283
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
JSON conversions for the mptoken_issuance_history spec types used by MPTokenIssuanceHistoryHandler.
Definition MPTokenIssuanceHistory.cpp:306
void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Marker const &marker)
Convert the Marker to a JSON object.
Definition MPTokenIssuanceHistory.cpp:309
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:17
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:63
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:35
spec::HandlerFor< InputT, boost::json::value > HandlerFor
The spec-driven base every typed handler inherits.
Definition SpecBackend.hpp:24
Represents a transaction and its metadata bundled together.
Definition Types.hpp:52
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:156
Context of an RPC call.
Definition Types.hpp:102
A struct to hold the output data of the command.
Definition MPTokenIssuanceHistory.hpp:75
boost::json::array transactions
Transactions that affected the issuance.
Definition MPTokenIssuanceHistory.hpp:85
std::optional< uint32_t > limit
Limit from the request; unset if the default was used.
Definition MPTokenIssuanceHistory.hpp:79
uint32_t ledgerIndexMin
Lowest ledger sequence searched.
Definition MPTokenIssuanceHistory.hpp:77
bool validated
Whether the ledger is validated.
Definition MPTokenIssuanceHistory.hpp:90
std::string mptIssuanceID
ID of the queried MPTokenIssuance.
Definition MPTokenIssuanceHistory.hpp:76
uint32_t ledgerIndexMax
Highest ledger sequence searched.
Definition MPTokenIssuanceHistory.hpp:78
std::optional< Marker > marker
Marker to resume from, if more results remain.
Definition MPTokenIssuanceHistory.hpp:80
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:132