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
69 Blob transaction;
70 Blob metadata;
71 std::uint32_t ledgerSequence = 0;
72 std::uint32_t date = 0;
73
74 TransactionAndMetadata() = default;
75
84 TransactionAndMetadata(Blob transaction, Blob metadata, std::uint32_t ledgerSequence, std::uint32_t date)
85 : transaction{std::move(transaction)}, metadata{std::move(metadata)}, ledgerSequence{ledgerSequence}, date{date}
86 {
87 }
88
94 TransactionAndMetadata(std::tuple<Blob, Blob, std::uint32_t, std::uint32_t> data)
95 : transaction{std::get<0>(data)}
96 , metadata{std::get<1>(data)}
97 , ledgerSequence{std::get<2>(data)}
98 , date{std::get<3>(data)}
99 {
100 }
101
108 bool
110 {
111 return transaction == other.transaction && metadata == other.metadata &&
112 ledgerSequence == other.ledgerSequence && date == other.date;
113 }
114};
115
120 std::uint32_t ledgerSequence = 0;
121 std::uint32_t transactionIndex = 0;
122
123 TransactionsCursor() = default;
124
131 TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
132 : ledgerSequence{ledgerSequence}, transactionIndex{transactionIndex}
133 {
134 }
135
141 TransactionsCursor(std::tuple<std::uint32_t, std::uint32_t> data)
142 : ledgerSequence{std::get<0>(data)}, transactionIndex{std::get<1>(data)}
143 {
144 }
145
146 bool
147 operator==(TransactionsCursor const& other) const = default;
148
154 [[nodiscard]] std::tuple<std::uint32_t, std::uint32_t>
155 asTuple() const
156 {
157 return std::make_tuple(ledgerSequence, transactionIndex);
158 }
159};
160
165 std::vector<TransactionAndMetadata> txns;
166 std::optional<TransactionsCursor> cursor;
167};
168
172struct NFT {
173 ripple::uint256 tokenID;
174 std::uint32_t ledgerSequence{};
175 ripple::AccountID owner;
176 Blob uri;
177 bool isBurned{};
178
179 NFT() = default;
180
190 NFT(ripple::uint256 const& tokenID,
191 std::uint32_t ledgerSequence,
192 ripple::AccountID const& owner,
193 Blob uri,
194 bool isBurned)
195 : tokenID{tokenID}, ledgerSequence{ledgerSequence}, owner{owner}, uri{std::move(uri)}, isBurned{isBurned}
196 {
197 }
198
207 NFT(ripple::uint256 const& tokenID, std::uint32_t ledgerSequence, ripple::AccountID const& owner, bool isBurned)
208 : NFT(tokenID, ledgerSequence, owner, {}, isBurned)
209 {
210 }
211
221 bool
222 operator==(NFT const& other) const
223 {
224 return tokenID == other.tokenID && ledgerSequence == other.ledgerSequence;
225 }
226};
227
232 std::vector<NFT> nfts;
233 std::optional<ripple::uint256> cursor;
234};
235
240 std::vector<Blob> mptokens;
241 std::optional<ripple::AccountID> cursor;
242};
243
248 std::uint32_t minSequence = 0;
249 std::uint32_t maxSequence = 0;
250};
251
255struct Amendment {
256 std::string name;
257 ripple::uint256 feature;
258 bool isSupportedByXRPL = false;
259 bool isSupportedByClio = false;
260 bool isRetired = false;
261
268 static ripple::uint256
269 getAmendmentId(std::string_view const name);
270
276 bool
277 operator==(Amendment const& other) const
278 {
279 return name == other.name;
280 }
281};
282
287 std::string name;
288
293 AmendmentKey(std::convertible_to<std::string> auto&& val) : 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{"0000000000000000000000000000000000000000000000000000000000000000"};
316constexpr ripple::uint256 kLAST_KEY{"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"};
317constexpr ripple::uint256 kHI192{"0000000000000000000000000000000000000000000000001111111111111111"};
318
319} // namespace data
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
A helper for amendment name to feature conversions.
Definition Types.hpp:286
auto operator<=>(AmendmentKey const &other) const =default
Comparison operators.
AmendmentKey(std::convertible_to< std::string > auto &&val)
Construct a new AmendmentKey.
Definition Types.hpp:293
Represents an amendment in the XRPL.
Definition Types.hpp:255
bool operator==(Amendment const &other) const
Equality comparison operator.
Definition Types.hpp:277
static ripple::uint256 getAmendmentId(std::string_view const name)
Get the amendment Id from its name.
Definition AmendmentCenter.cpp:183
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:247
Represents an array of MPTokens.
Definition Types.hpp:239
Represents a NFToken.
Definition Types.hpp:172
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:190
bool operator==(NFT const &other) const
Check if the NFT is the same as another.
Definition Types.hpp:222
NFT(ripple::uint256 const &tokenID, std::uint32_t ledgerSequence, ripple::AccountID const &owner, bool isBurned)
Construct a new NFT object.
Definition Types.hpp:207
Represents a bundle of NFTs with a cursor to the next page.
Definition Types.hpp:231
Represents a transaction and its metadata bundled together.
Definition Types.hpp:68
TransactionAndMetadata(std::tuple< Blob, Blob, std::uint32_t, std::uint32_t > data)
Construct a new Transaction And Metadata object.
Definition Types.hpp:94
bool operator==(TransactionAndMetadata const &other) const
Check if the transaction and metadata are the same as another.
Definition Types.hpp:109
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:164
Represents a cursor into the transactions table.
Definition Types.hpp:119
TransactionsCursor(std::tuple< std::uint32_t, std::uint32_t > data)
Construct a new Transactions Cursor object.
Definition Types.hpp:141
TransactionsCursor(std::uint32_t ledgerSequence, std::uint32_t transactionIndex)
Construct a new Transactions Cursor object.
Definition Types.hpp:131
std::tuple< std::uint32_t, std::uint32_t > asTuple() const
Convert the cursor to a tuple of seq and index.
Definition Types.hpp:155