Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Types.hpp
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/protocol/AccountID.h>
5
6#include <concepts>
7#include <cstdint>
8#include <optional>
9#include <string>
10#include <string_view>
11#include <tuple>
12#include <utility>
13#include <vector>
14
15namespace data {
16
17using Blob = std::vector<unsigned char>;
18
23 ripple::uint256 key;
24 Blob blob;
25
26 bool
27 operator==(LedgerObject const& other) const = default;
28};
29
33struct LedgerPage {
34 std::vector<LedgerObject> objects;
35 std::optional<ripple::uint256> cursor;
36};
37
42 std::vector<LedgerObject> offers;
43 std::optional<ripple::uint256> cursor;
44};
45
49struct TransactionAndMetadata {
50 Blob transaction;
51 Blob metadata;
52 std::uint32_t ledgerSequence = 0;
53 std::uint32_t date = 0;
54
55 TransactionAndMetadata() = default;
56
66 Blob transaction,
67 Blob metadata,
68 std::uint32_t ledgerSequence,
69 std::uint32_t date
70 )
71 : transaction{std::move(transaction)}
72 , metadata{std::move(metadata)}
73 , ledgerSequence{ledgerSequence}
74 , date{date}
75 {
76 }
77
83 TransactionAndMetadata(std::tuple<Blob, Blob, std::uint32_t, std::uint32_t> data)
84 : transaction{std::get<0>(data)}
85 , metadata{std::get<1>(data)}
86 , ledgerSequence{std::get<2>(data)}
87 , date{std::get<3>(data)}
88 {
89 }
90
97 bool
98 operator==(TransactionAndMetadata const& other) const
99 {
100 return transaction == other.transaction && metadata == other.metadata &&
101 ledgerSequence == other.ledgerSequence && date == other.date;
102 }
103};
104
108struct TransactionsCursor {
109 std::uint32_t ledgerSequence = 0;
110 std::uint32_t transactionIndex = 0;
111
112 TransactionsCursor() = default;
113
120 TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
121 : ledgerSequence{ledgerSequence}, transactionIndex{transactionIndex}
122 {
123 }
124
130 TransactionsCursor(std::tuple<std::uint32_t, std::uint32_t> data)
131 : ledgerSequence{std::get<0>(data)}, transactionIndex{std::get<1>(data)}
132 {
133 }
134
135 bool
136 operator==(TransactionsCursor const& other) const = default;
137
143 [[nodiscard]] std::tuple<std::uint32_t, std::uint32_t>
144 asTuple() const
145 {
146 return std::make_tuple(ledgerSequence, transactionIndex);
147 }
148};
149
154 std::vector<TransactionAndMetadata> txns;
155 std::optional<TransactionsCursor> cursor;
156};
157
161struct NFT {
162 ripple::uint256 tokenID;
163 std::uint32_t ledgerSequence{};
164 ripple::AccountID owner;
165 Blob uri;
166 bool isBurned{};
167
168 NFT() = default;
169
179 NFT(ripple::uint256 const& tokenID,
180 std::uint32_t ledgerSequence,
181 ripple::AccountID const& owner,
182 Blob uri,
183 bool isBurned)
184 : tokenID{tokenID}
185 , ledgerSequence{ledgerSequence}
186 , owner{owner}
187 , uri{std::move(uri)}
188 , isBurned{isBurned}
189 {
190 }
191
200 NFT(ripple::uint256 const& tokenID,
201 std::uint32_t ledgerSequence,
202 ripple::AccountID const& owner,
203 bool isBurned)
204 : NFT(tokenID, ledgerSequence, owner, {}, isBurned)
205 {
206 }
207
217 bool
218 operator==(NFT const& other) const
219 {
220 return tokenID == other.tokenID && ledgerSequence == other.ledgerSequence;
221 }
222};
223
228 std::vector<NFT> nfts;
229 std::optional<ripple::uint256> cursor;
230};
231
236 std::vector<Blob> mptokens;
237 std::optional<ripple::AccountID> cursor;
238};
239
244 std::uint32_t minSequence = 0;
245 std::uint32_t maxSequence = 0;
246
247 bool
248 operator==(LedgerRange const&) const = default;
249};
250
254struct Amendment {
255 std::string name;
256 ripple::uint256 feature;
257 bool isSupportedByXRPL = false;
258 bool isSupportedByClio = false;
259 bool isRetired = false;
260
267 static ripple::uint256
268 getAmendmentId(std::string_view const name);
269
275 bool
276 operator==(Amendment const& other) const
277 {
278 return name == other.name;
279 }
280};
281
286 std::string name;
287
292 AmendmentKey(std::convertible_to<std::string> auto&& val)
293 : name{std::forward<decltype(val)>(val)}
294 {
295 }
296
298 operator std::string const&() const;
299
301 operator std::string_view() const;
302
304 operator ripple::uint256() const;
305
311 auto
312 operator<=>(AmendmentKey const& other) const = default;
313};
314
315constexpr ripple::uint256 kFIRST_KEY{
316 "0000000000000000000000000000000000000000000000000000000000000000"
317};
318constexpr ripple::uint256 kLAST_KEY{
319 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
320};
321constexpr ripple::uint256 kHI192{
322 "0000000000000000000000000000000000000000000000001111111111111111"
323};
324
325} // namespace data
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
auto operator<=>(AmendmentKey const &other) const =default
Comparison operators.
AmendmentKey(std::convertible_to< std::string > auto &&val)
Construct a new AmendmentKey.
Definition Types.hpp:292
Represents an amendment in the XRPL.
Definition Types.hpp:254
bool operator==(Amendment const &other) const
Equality comparison operator.
Definition Types.hpp:276
static ripple::uint256 getAmendmentId(std::string_view const name)
Get the amendment Id from its name.
Definition AmendmentCenter.cpp:211
Represents a page of book offer objects.
Definition Types.hpp:41
Represents an object in the ledger.
Definition Types.hpp:22
Represents a page of LedgerObjects.
Definition Types.hpp:33
Stores a range of sequences as a min and max pair.
Definition Types.hpp:243
Represents an array of MPTokens.
Definition Types.hpp:235
NFT(ripple::uint256 const &tokenID, std::uint32_t ledgerSequence, ripple::AccountID const &owner, Blob uri, bool isBurned)
Construct a new NFT object.
Definition Types.hpp:179
bool operator==(NFT const &other) const
Check if the NFT is the same as another.
Definition Types.hpp:218
NFT(ripple::uint256 const &tokenID, std::uint32_t ledgerSequence, ripple::AccountID const &owner, bool isBurned)
Construct a new NFT object.
Definition Types.hpp:200
Represents a bundle of NFTs with a cursor to the next page.
Definition Types.hpp:227
TransactionAndMetadata(std::tuple< Blob, Blob, std::uint32_t, std::uint32_t > data)
Construct a new Transaction And Metadata object.
Definition Types.hpp:83
bool operator==(TransactionAndMetadata const &other) const
Check if the transaction and metadata are the same as another.
Definition Types.hpp:98
TransactionAndMetadata(Blob transaction, Blob metadata, std::uint32_t ledgerSequence, std::uint32_t date)
Construct a new Transaction And Metadata object.
Definition Types.hpp:65
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:153
Represents a cursor into the transactions table.
Definition Types.hpp:108
TransactionsCursor(std::tuple< std::uint32_t, std::uint32_t > data)
Construct a new Transactions Cursor object.
Definition Types.hpp:130
TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
Construct a new Transactions Cursor object.
Definition Types.hpp:120
std::tuple< std::uint32_t, std::uint32_t > asTuple() const
Convert the cursor to a tuple of seq and index.
Definition Types.hpp:144