Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Models.hpp
1#pragma once
2
3#include "util/Concepts.hpp"
4
5#include <boost/json/object.hpp>
6#include <fmt/format.h>
7#include <xrpl/basics/Blob.h>
8#include <xrpl/basics/base_uint.h>
9#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
10#include <xrpl/proto/org/xrpl/rpc/v1/ledger.pb.h>
11#include <xrpl/protocol/LedgerHeader.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/Serializer.h>
14#include <xrpl/protocol/TxFormats.h>
15#include <xrpl/protocol/TxMeta.h>
16
17#include <cstdint>
18#include <optional>
19#include <string>
20#include <vector>
21
25namespace etl::model {
26
36template <xrpl::TxType... Types>
37 requires(util::hasNoDuplicates(Types...)) // NOLINT(readability-redundant-parentheses)
38struct Spec {
39 static constexpr bool kSpecTag = true;
40
47 [[nodiscard]] static constexpr bool
48 wants(xrpl::TxType type) noexcept
49 {
50 return ((Types == type) || ...);
51 }
52};
53
58 std::string raw;
59 std::string metaRaw;
60
61 // unpacked blob and meta
62 xrpl::STTx sttx;
63 xrpl::TxMeta meta;
64
65 // commonly used stuff
66 xrpl::uint256 id;
67 std::string key;
68 xrpl::TxType type;
69
75 bool
76 operator==(Transaction const& other) const
77 {
78 return raw == other.raw //
79 and metaRaw == other.metaRaw //
80 and sttx.getTransactionID() == other.sttx.getTransactionID() //
81 and meta.getTxID() == other.meta.getTxID() //
82 and id == other.id //
83 and key == other.key //
84 and type == other.type;
85 }
86};
87
91struct Object {
95 enum class ModType : int {
97 Created = 1,
99 Deleted = 3,
100 };
101
102 xrpl::uint256 key;
103 std::string keyRaw;
104 xrpl::Blob data;
105 std::string dataRaw;
106 std::string successor;
107 std::string predecessor;
108
110
111 bool
112 operator==(Object const&) const = default;
113};
114
119 std::string firstBook;
120 std::string bookBase;
121
122 bool
123 operator==(BookSuccessor const&) const = default;
124};
125
130 std::vector<Transaction> transactions;
131 std::vector<Object> objects;
132 std::optional<std::vector<BookSuccessor>> successors;
133 std::optional<std::vector<std::string>> edgeKeys;
134
135 xrpl::LedgerHeader header;
136 std::string rawHeader;
137 uint32_t seq;
138
144 bool
145 operator==(LedgerData const& other) const
146 {
147 auto const serialized = [](auto const& hdr) {
148 xrpl::Serializer ser;
149 xrpl::addRaw(hdr, ser);
150 return ser.getString();
151 };
152
153 return transactions == other.transactions //
154 and objects == other.objects //
155 and successors == other.successors //
156 and edgeKeys == other.edgeKeys //
157 and serialized(header) == serialized(other.header) //
158 and rawHeader == other.rawHeader //
159 and seq == other.seq;
160 }
161};
162
166struct Task {
170 enum class Priority : uint8_t {
171 Lower = 0u,
172 Higher = 1u,
173 };
174
176 uint32_t seq;
177};
178
179} // namespace etl::model
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
This namespace contains the data models used by the ETL pipeline and its extensions.
Definition Models.hpp:25
static consteval auto hasNoDuplicates(auto &&... values)
Checks that the list of given values contains no duplicates.
Definition Concepts.hpp:38
Represents a book successor.
Definition Models.hpp:118
std::string firstBook
Raw key of the first offer directory page of the book.
Definition Models.hpp:119
std::string bookBase
Raw key of the book base (book directory without the quality).
Definition Models.hpp:120
Represents an entire ledger diff worth of transactions and objects.
Definition Models.hpp:129
std::optional< std::vector< std::string > > edgeKeys
Last key of each initial load range.
Definition Models.hpp:133
std::optional< std::vector< BookSuccessor > > successors
Book successors, if provided.
Definition Models.hpp:132
bool operator==(LedgerData const &other) const
Compares LedgerData objects to each other without considering the header field.
Definition Models.hpp:145
xrpl::LedgerHeader header
Deserialized ledger header.
Definition Models.hpp:135
std::vector< Object > objects
Objects changed by the ledger.
Definition Models.hpp:131
std::string rawHeader
Serialized ledger header.
Definition Models.hpp:136
uint32_t seq
Sequence of the ledger.
Definition Models.hpp:137
std::vector< Transaction > transactions
Transactions in the ledger.
Definition Models.hpp:130
Represents a single object on the ledger.
Definition Models.hpp:91
std::string predecessor
Raw key of the previous object in the ledger (last key if unset).
Definition Models.hpp:107
xrpl::uint256 key
Key of the ledger object.
Definition Models.hpp:102
ModType
Modification type for the object.
Definition Models.hpp:95
@ Created
Object was created in this ledger.
Definition Models.hpp:97
@ Modified
Object was modified in this ledger.
Definition Models.hpp:98
@ Deleted
Object was deleted in this ledger.
Definition Models.hpp:99
@ Unspecified
Modification type was not provided.
Definition Models.hpp:96
std::string dataRaw
Serialized object data as a string.
Definition Models.hpp:105
std::string keyRaw
Key of the ledger object as raw bytes.
Definition Models.hpp:103
std::string successor
Raw key of the next object in the ledger (first key if unset).
Definition Models.hpp:106
ModType type
How the object was modified in this ledger.
Definition Models.hpp:109
A specification for the Registry.
Definition Models.hpp:38
static constexpr bool kSpecTag
Marker used by the Registry to detect a Spec.
Definition Models.hpp:39
static constexpr bool wants(xrpl::TxType type) noexcept
Checks if the transaction type was requested.
Definition Models.hpp:48
Represents a task for the extractors.
Definition Models.hpp:166
Priority
Represents the priority of the task.
Definition Models.hpp:170
@ Lower
Low priority, used for backfilling older ledgers.
Definition Models.hpp:171
@ Higher
High priority, used for extracting new ledgers going forward.
Definition Models.hpp:172
uint32_t seq
Sequence of the ledger to extract.
Definition Models.hpp:176
Priority priority
Priority of the task.
Definition Models.hpp:175
Represents a single transaction on the ledger.
Definition Models.hpp:57
xrpl::TxMeta meta
Deserialized transaction metadata.
Definition Models.hpp:63
xrpl::uint256 id
Transaction hash.
Definition Models.hpp:66
std::string metaRaw
Raw serialized transaction metadata blob.
Definition Models.hpp:59
bool operator==(Transaction const &other) const
Compares Transaction objects to each other without considering sttx and meta fields.
Definition Models.hpp:76
xrpl::TxType type
Transaction type.
Definition Models.hpp:68
std::string key
The above id as a string of 32 raw bytes.
Definition Models.hpp:67
std::string raw
Raw serialized transaction blob.
Definition Models.hpp:58
xrpl::STTx sttx
Deserialized transaction.
Definition Models.hpp:62