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
20using Blob = std::vector<unsigned char>;
21
26 xrpl::uint256 key;
28
29 bool
30 operator==(LedgerObject const& other) const = default;
31};
32
36struct LedgerPage {
37 std::vector<LedgerObject> objects;
38 std::optional<xrpl::uint256> cursor;
39};
40
45 std::vector<LedgerObject> offers;
46 std::optional<xrpl::uint256> cursor;
47};
48
52struct TransactionAndMetadata {
55 std::uint32_t ledgerSequence = 0;
56 std::uint32_t date = 0;
57
58 TransactionAndMetadata() = default;
59
71 std::uint32_t ledgerSequence,
72 std::uint32_t date
73 )
74 : transaction{std::move(transaction)}
75 , metadata{std::move(metadata)}
77 , date{date}
78 {
79 }
80
86 TransactionAndMetadata(std::tuple<Blob, Blob, std::uint32_t, std::uint32_t> data)
87 : transaction{std::get<0>(data)}
88 , metadata{std::get<1>(data)}
89 , ledgerSequence{std::get<2>(data)}
90 , date{std::get<3>(data)}
91 {
92 }
93
100 bool
101 operator==(TransactionAndMetadata const& other) const
102 {
103 return transaction == other.transaction && metadata == other.metadata &&
104 ledgerSequence == other.ledgerSequence && date == other.date;
105 }
106};
107
111struct TransactionsCursor {
112 std::uint32_t ledgerSequence = 0;
113 std::uint32_t transactionIndex = 0;
114
115 TransactionsCursor() = default;
116
127
133 TransactionsCursor(std::tuple<std::uint32_t, std::uint32_t> data)
134 : ledgerSequence{std::get<0>(data)}, transactionIndex{std::get<1>(data)}
135 {
136 }
137
138 bool
139 operator==(TransactionsCursor const& other) const = default;
140
146 [[nodiscard]] std::tuple<std::uint32_t, std::uint32_t>
147 asTuple() const
148 {
149 return std::make_tuple(ledgerSequence, transactionIndex);
150 }
151};
152
157 std::vector<TransactionAndMetadata> txns;
158 std::optional<TransactionsCursor> cursor;
159};
160
164struct NFT {
165 xrpl::uint256 tokenID;
166 std::uint32_t ledgerSequence{};
167 xrpl::AccountID owner;
169 bool isBurned{};
170
171 NFT() = default;
172
182 NFT(xrpl::uint256 const& tokenID,
183 std::uint32_t ledgerSequence,
184 xrpl::AccountID const& owner,
185 Blob uri,
186 bool isBurned)
189 , owner{owner}
190 , uri{std::move(uri)}
192 {
193 }
194
203 NFT(xrpl::uint256 const& tokenID,
204 std::uint32_t ledgerSequence,
205 xrpl::AccountID const& owner,
206 bool isBurned)
208 {
209 }
210
220 bool
221 operator==(NFT const& other) const
222 {
223 return tokenID == other.tokenID && ledgerSequence == other.ledgerSequence;
224 }
225};
226
231 std::vector<NFT> nfts;
232 std::optional<xrpl::uint256> cursor;
233};
234
239 std::vector<Blob> mptokens;
240 std::optional<xrpl::AccountID> cursor;
241};
242
247 std::uint32_t minSequence = 0;
248 std::uint32_t maxSequence = 0;
249
250 bool
251 operator==(LedgerRange const&) const = default;
252};
253
257struct Amendment {
258 std::string name;
259 xrpl::uint256 feature;
260 bool isSupportedByXRPL = false;
261 bool isSupportedByClio = false;
262 bool isRetired = false;
263
270 static xrpl::uint256
271 getAmendmentId(std::string_view const name);
272
278 bool
279 operator==(Amendment const& other) const
280 {
281 return name == other.name;
282 }
283};
284
289 std::string name;
290
295 AmendmentKey(std::convertible_to<std::string> auto&& val)
296 : name{std::forward<decltype(val)>(val)}
297 {
298 }
299
305 operator std::string const&() const;
306
312 operator std::string_view() const;
313
319 operator xrpl::uint256() const;
320
326 auto
327 operator<=>(AmendmentKey const& other) const = default;
328};
329
333constexpr xrpl::uint256 kFirstKey{
334 "0000000000000000000000000000000000000000000000000000000000000000"
335};
336
339constexpr xrpl::uint256 kLastKey{
340 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
341};
342
345constexpr xrpl::uint256 kHi192{"0000000000000000000000000000000000000000000000001111111111111111"};
346
347} // namespace data
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
constexpr xrpl::uint256 kLastKey
The largest possible ledger object key; used as the end of the key space.
Definition Types.hpp:339
constexpr xrpl::uint256 kFirstKey
The smallest possible ledger object key; used as the start of the key space.
Definition Types.hpp:333
constexpr xrpl::uint256 kHi192
Key with the high 192 bits zero and the low 64 bits set to 0x1111111111111111.
Definition Types.hpp:345
std::vector< unsigned char > Blob
Raw serialized data, e.g. a ledger object, transaction or metadata.
Definition Types.hpp:20
auto operator<=>(AmendmentKey const &other) const =default
Comparison operators.
std::string name
Name of the amendment.
Definition Types.hpp:289
AmendmentKey(std::convertible_to< std::string > auto &&val)
Construct a new AmendmentKey.
Definition Types.hpp:295
Represents an amendment in the XRPL.
Definition Types.hpp:257
bool isRetired
Whether the amendment is retired.
Definition Types.hpp:262
std::string name
Name of the amendment.
Definition Types.hpp:258
bool operator==(Amendment const &other) const
Equality comparison operator.
Definition Types.hpp:279
bool isSupportedByClio
Whether Clio supports the amendment.
Definition Types.hpp:261
static xrpl::uint256 getAmendmentId(std::string_view const name)
Get the amendment Id from its name.
Definition AmendmentCenter.cpp:211
xrpl::uint256 feature
Amendment ID (hash of the name).
Definition Types.hpp:259
bool isSupportedByXRPL
Whether libxrpl knows and supports the amendment.
Definition Types.hpp:260
Represents a page of book offer objects.
Definition Types.hpp:44
std::optional< xrpl::uint256 > cursor
Unused; fetchBookOffers() never sets it.
Definition Types.hpp:46
std::vector< LedgerObject > offers
Offer objects in this page.
Definition Types.hpp:45
Represents an object in the ledger.
Definition Types.hpp:25
xrpl::uint256 key
Key (index) of the object in the ledger.
Definition Types.hpp:26
Blob blob
Serialized object data; empty if the object was deleted.
Definition Types.hpp:27
Represents a page of LedgerObjects.
Definition Types.hpp:36
std::optional< xrpl::uint256 > cursor
Key to continue from; nullopt if no more pages.
Definition Types.hpp:38
std::vector< LedgerObject > objects
Ledger objects in this page.
Definition Types.hpp:37
Stores a range of sequences as a min and max pair.
Definition Types.hpp:246
std::uint32_t minSequence
Lowest ledger sequence in the range (inclusive).
Definition Types.hpp:247
std::uint32_t maxSequence
Highest ledger sequence in the range (inclusive).
Definition Types.hpp:248
Represents an array of MPTokens.
Definition Types.hpp:238
std::optional< xrpl::AccountID > cursor
Holder to continue from; nullopt if no more pages.
Definition Types.hpp:240
std::vector< Blob > mptokens
Serialized MPToken ledger objects.
Definition Types.hpp:239
Represents a NFToken.
Definition Types.hpp:164
xrpl::uint256 tokenID
ID of the NFToken.
Definition Types.hpp:165
bool isBurned
Whether the token has been burned.
Definition Types.hpp:169
bool operator==(NFT const &other) const
Check if the NFT is the same as another.
Definition Types.hpp:221
xrpl::AccountID owner
Owner of the token.
Definition Types.hpp:167
std::uint32_t ledgerSequence
Ledger sequence at which this state of the token applies.
Definition Types.hpp:166
NFT(xrpl::uint256 const &tokenID, std::uint32_t ledgerSequence, xrpl::AccountID const &owner, bool isBurned)
Construct a new NFT object.
Definition Types.hpp:203
NFT(xrpl::uint256 const &tokenID, std::uint32_t ledgerSequence, xrpl::AccountID const &owner, Blob uri, bool isBurned)
Construct a new NFT object.
Definition Types.hpp:182
Blob uri
URI of the token; empty if not set.
Definition Types.hpp:168
Represents a bundle of NFTs with a cursor to the next page.
Definition Types.hpp:230
std::vector< NFT > nfts
NFTs in this page.
Definition Types.hpp:231
std::optional< xrpl::uint256 > cursor
Token ID to continue from; nullopt if no more pages.
Definition Types.hpp:232
TransactionAndMetadata(std::tuple< Blob, Blob, std::uint32_t, std::uint32_t > data)
Construct a new Transaction And Metadata object.
Definition Types.hpp:86
std::uint32_t ledgerSequence
Sequence of the ledger containing the transaction.
Definition Types.hpp:55
Blob metadata
Serialized transaction metadata.
Definition Types.hpp:54
std::uint32_t date
Close time of that ledger, in seconds since XRPL epoch.
Definition Types.hpp:56
Blob transaction
Serialized transaction.
Definition Types.hpp:53
bool operator==(TransactionAndMetadata const &other) const
Check if the transaction and metadata are the same as another.
Definition Types.hpp:101
TransactionAndMetadata(Blob transaction, Blob metadata, std::uint32_t ledgerSequence, std::uint32_t date)
Construct a new Transaction And Metadata object.
Definition Types.hpp:68
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:156
std::vector< TransactionAndMetadata > txns
Transactions in this page.
Definition Types.hpp:157
std::optional< TransactionsCursor > cursor
Cursor to the next page, if any.
Definition Types.hpp:158
Represents a cursor into the transactions table.
Definition Types.hpp:111
std::uint32_t ledgerSequence
Ledger sequence to continue from.
Definition Types.hpp:112
TransactionsCursor(std::tuple< std::uint32_t, std::uint32_t > data)
Construct a new Transactions Cursor object.
Definition Types.hpp:133
std::uint32_t transactionIndex
Transaction index within that ledger to continue from.
Definition Types.hpp:113
TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
Construct a new Transactions Cursor object.
Definition Types.hpp:123
std::tuple< std::uint32_t, std::uint32_t > asTuple() const
Convert the cursor to a tuple of seq and index.
Definition Types.hpp:147