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
22namespace etl::model {
23
31template <ripple::TxType... Types>
32 requires(util::hasNoDuplicates(Types...))
33struct Spec {
34 static constexpr bool kSPEC_TAG = true;
35
42 [[nodiscard]] static constexpr bool
43 wants(ripple::TxType type) noexcept
44 {
45 return ((Types == type) || ...);
46 }
47};
48
53 std::string raw; // raw binary blob
54 std::string metaRaw;
55
56 // unpacked blob and meta
57 ripple::STTx sttx;
58 ripple::TxMeta meta;
59
60 // commonly used stuff
61 ripple::uint256 id;
62 std::string key; // key is the above id as a string of 32 characters
63 ripple::TxType type;
64
70 bool
71 operator==(Transaction const& other) const
72 {
73 return raw == other.raw //
74 and metaRaw == other.metaRaw //
75 and sttx.getTransactionID() == other.sttx.getTransactionID() //
76 and meta.getTxID() == other.meta.getTxID() //
77 and id == other.id //
78 and key == other.key //
79 and type == other.type;
80 }
81};
82
86struct Object {
90 enum class ModType : int {
91 Unspecified = 0,
92 Created = 1,
93 Modified = 2,
94 Deleted = 3,
95 };
96
97 ripple::uint256 key;
98 std::string keyRaw;
99 ripple::Blob data;
100 std::string dataRaw;
101 std::string successor;
102 std::string predecessor;
103
104 ModType type;
105
106 bool
107 operator==(Object const&) const = default;
108};
109
114 std::string firstBook;
115 std::string bookBase;
116
117 bool
118 operator==(BookSuccessor const&) const = default;
119};
120
125 std::vector<Transaction> transactions;
126 std::vector<Object> objects;
127 std::optional<std::vector<BookSuccessor>> successors;
128 std::optional<std::vector<std::string>> edgeKeys;
129
130 ripple::LedgerHeader header;
131 std::string rawHeader;
132 uint32_t seq;
133
139 bool
140 operator==(LedgerData const& other) const
141 {
142 auto const serialized = [](auto const& hdr) {
143 ripple::Serializer ser;
144 ripple::addRaw(hdr, ser);
145 return ser.getString();
146 };
147
148 return transactions == other.transactions //
149 and objects == other.objects //
150 and successors == other.successors //
151 and edgeKeys == other.edgeKeys //
152 and serialized(header) == serialized(other.header) //
153 and rawHeader == other.rawHeader //
154 and seq == other.seq;
155 }
156};
157
161struct Task {
165 enum class Priority : uint8_t {
166 Lower = 0u,
167 Higher = 1u,
168 };
169
170 Priority priority;
171 uint32_t seq;
172};
173
174} // namespace etl::model
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
static consteval auto hasNoDuplicates(auto &&... values)
Checks that the list of given values contains no duplicates.
Definition Concepts.hpp:24
Represents a book successor.
Definition Models.hpp:113
Represents an entire ledger diff worth of transactions and objects.
Definition Models.hpp:124
bool operator==(LedgerData const &other) const
Compares LedgerData objects to each other without considering the header field.
Definition Models.hpp:140
Represents a single object on the ledger.
Definition Models.hpp:86
ModType
Modification type for the object.
Definition Models.hpp:90
A specification for the Registry.
Definition Models.hpp:33
static constexpr bool wants(ripple::TxType type) noexcept
Checks if the transaction type was requested.
Definition Models.hpp:43
Represents a task for the extractors.
Definition Models.hpp:161
Priority
Represents the priority of the task.
Definition Models.hpp:165
Represents a single transaction on the ledger.
Definition Models.hpp:52
bool operator==(Transaction const &other) const
Compares Transaction objects to each other without considering sttx and meta fields.
Definition Models.hpp:71