Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Types.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2022, the clio developers.
5
6 Permission to use, copy, modify, and distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#pragma once
21
22#include <xrpl/basics/base_uint.h>
23#include <xrpl/protocol/AccountID.h>
24
25#include <concepts>
26#include <cstdint>
27#include <optional>
28#include <string>
29#include <string_view>
30#include <tuple>
31#include <utility>
32#include <vector>
33
34namespace data {
35
36using Blob = std::vector<unsigned char>;
37
42 ripple::uint256 key;
43 Blob blob;
44
45 bool
46 operator==(LedgerObject const& other) const = default;
47};
48
52struct LedgerPage {
53 std::vector<LedgerObject> objects;
54 std::optional<ripple::uint256> cursor;
55};
56
61 std::vector<LedgerObject> offers;
62 std::optional<ripple::uint256> cursor;
63};
64
68struct TransactionAndMetadata {
69 Blob transaction;
70 Blob metadata;
71 std::uint32_t ledgerSequence = 0;
72 std::uint32_t date = 0;
73
74 TransactionAndMetadata() = default;
75
85 Blob transaction,
86 Blob metadata,
87 std::uint32_t ledgerSequence,
88 std::uint32_t date
89 )
90 : transaction{std::move(transaction)}
91 , metadata{std::move(metadata)}
92 , ledgerSequence{ledgerSequence}
93 , date{date}
94 {
95 }
96
102 TransactionAndMetadata(std::tuple<Blob, Blob, std::uint32_t, std::uint32_t> data)
103 : transaction{std::get<0>(data)}
104 , metadata{std::get<1>(data)}
105 , ledgerSequence{std::get<2>(data)}
106 , date{std::get<3>(data)}
107 {
108 }
109
116 bool
117 operator==(TransactionAndMetadata const& other) const
118 {
119 return transaction == other.transaction && metadata == other.metadata &&
120 ledgerSequence == other.ledgerSequence && date == other.date;
121 }
122};
123
127struct TransactionsCursor {
128 std::uint32_t ledgerSequence = 0;
129 std::uint32_t transactionIndex = 0;
130
131 TransactionsCursor() = default;
132
139 TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
140 : ledgerSequence{ledgerSequence}, transactionIndex{transactionIndex}
141 {
142 }
143
149 TransactionsCursor(std::tuple<std::uint32_t, std::uint32_t> data)
150 : ledgerSequence{std::get<0>(data)}, transactionIndex{std::get<1>(data)}
151 {
152 }
153
154 bool
155 operator==(TransactionsCursor const& other) const = default;
156
162 [[nodiscard]] std::tuple<std::uint32_t, std::uint32_t>
163 asTuple() const
164 {
165 return std::make_tuple(ledgerSequence, transactionIndex);
166 }
167};
168
173 std::vector<TransactionAndMetadata> txns;
174 std::optional<TransactionsCursor> cursor;
175};
176
180struct NFT {
181 ripple::uint256 tokenID;
182 std::uint32_t ledgerSequence{};
183 ripple::AccountID owner;
184 Blob uri;
185 bool isBurned{};
186
187 NFT() = default;
188
198 NFT(ripple::uint256 const& tokenID,
199 std::uint32_t ledgerSequence,
200 ripple::AccountID const& owner,
201 Blob uri,
202 bool isBurned)
203 : tokenID{tokenID}
204 , ledgerSequence{ledgerSequence}
205 , owner{owner}
206 , uri{std::move(uri)}
207 , isBurned{isBurned}
208 {
209 }
210
219 NFT(ripple::uint256 const& tokenID,
220 std::uint32_t ledgerSequence,
221 ripple::AccountID const& owner,
222 bool isBurned)
223 : NFT(tokenID, ledgerSequence, owner, {}, isBurned)
224 {
225 }
226
236 bool
237 operator==(NFT const& other) const
238 {
239 return tokenID == other.tokenID && ledgerSequence == other.ledgerSequence;
240 }
241};
242
247 std::vector<NFT> nfts;
248 std::optional<ripple::uint256> cursor;
249};
250
255 std::vector<Blob> mptokens;
256 std::optional<ripple::AccountID> cursor;
257};
258
263 std::uint32_t minSequence = 0;
264 std::uint32_t maxSequence = 0;
265
266 bool
267 operator==(LedgerRange const&) const = default;
268};
269
273struct Amendment {
274 std::string name;
275 ripple::uint256 feature;
276 bool isSupportedByXRPL = false;
277 bool isSupportedByClio = false;
278 bool isRetired = false;
279
286 static ripple::uint256
287 getAmendmentId(std::string_view const name);
288
294 bool
295 operator==(Amendment const& other) const
296 {
297 return name == other.name;
298 }
299};
300
305 std::string name;
306
311 AmendmentKey(std::convertible_to<std::string> auto&& val)
312 : name{std::forward<decltype(val)>(val)}
313 {
314 }
315
317 operator std::string const&() const;
318
320 operator std::string_view() const;
321
323 operator ripple::uint256() const;
324
330 auto
331 operator<=>(AmendmentKey const& other) const = default;
332};
333
334constexpr ripple::uint256 kFIRST_KEY{
335 "0000000000000000000000000000000000000000000000000000000000000000"
336};
337constexpr ripple::uint256 kLAST_KEY{
338 "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"
339};
340constexpr ripple::uint256 kHI192{
341 "0000000000000000000000000000000000000000000000001111111111111111"
342};
343
344} // namespace data
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:75
auto operator<=>(AmendmentKey const &other) const =default
Comparison operators.
AmendmentKey(std::convertible_to< std::string > auto &&val)
Construct a new AmendmentKey.
Definition Types.hpp:311
Represents an amendment in the XRPL.
Definition Types.hpp:273
bool operator==(Amendment const &other) const
Equality comparison operator.
Definition Types.hpp:295
static ripple::uint256 getAmendmentId(std::string_view const name)
Get the amendment Id from its name.
Definition AmendmentCenter.cpp:218
Represents a page of book offer objects.
Definition Types.hpp:60
Represents an object in the ledger.
Definition Types.hpp:41
Represents a page of LedgerObjects.
Definition Types.hpp:52
Stores a range of sequences as a min and max pair.
Definition Types.hpp:262
Represents an array of MPTokens.
Definition Types.hpp:254
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:198
bool operator==(NFT const &other) const
Check if the NFT is the same as another.
Definition Types.hpp:237
NFT(ripple::uint256 const &tokenID, std::uint32_t ledgerSequence, ripple::AccountID const &owner, bool isBurned)
Construct a new NFT object.
Definition Types.hpp:219
Represents a bundle of NFTs with a cursor to the next page.
Definition Types.hpp:246
TransactionAndMetadata(std::tuple< Blob, Blob, std::uint32_t, std::uint32_t > data)
Construct a new Transaction And Metadata object.
Definition Types.hpp:102
bool operator==(TransactionAndMetadata const &other) const
Check if the transaction and metadata are the same as another.
Definition Types.hpp:117
TransactionAndMetadata(Blob transaction, Blob metadata, std::uint32_t ledgerSequence, std::uint32_t date)
Construct a new Transaction And Metadata object.
Definition Types.hpp:84
Represests a bundle of transactions with metadata and a cursor to the next page.
Definition Types.hpp:172
Represents a cursor into the transactions table.
Definition Types.hpp:127
TransactionsCursor(std::tuple< std::uint32_t, std::uint32_t > data)
Construct a new Transactions Cursor object.
Definition Types.hpp:149
TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
Construct a new Transactions Cursor object.
Definition Types.hpp:139
std::tuple< std::uint32_t, std::uint32_t > asTuple() const
Convert the cursor to a tuple of seq and index.
Definition Types.hpp:163