Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Models.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2024, 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 "util/Concepts.hpp"
23
24#include <boost/json/object.hpp>
25#include <fmt/core.h>
26#include <xrpl/basics/Blob.h>
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/proto/org/xrpl/rpc/v1/get_ledger.pb.h>
29#include <xrpl/proto/org/xrpl/rpc/v1/ledger.pb.h>
30#include <xrpl/protocol/LedgerHeader.h>
31#include <xrpl/protocol/STTx.h>
32#include <xrpl/protocol/Serializer.h>
33#include <xrpl/protocol/TxFormats.h>
34#include <xrpl/protocol/TxMeta.h>
35
36#include <cstdint>
37#include <optional>
38#include <string>
39#include <vector>
40
41namespace etlng::model {
42
50template <ripple::TxType... Types>
51 requires(util::hasNoDuplicates(Types...))
52struct Spec {
53 static constexpr bool kSPEC_TAG = true;
54
61 [[nodiscard]] static constexpr bool
62 wants(ripple::TxType type) noexcept
63 {
64 return ((Types == type) || ...);
65 }
66};
67
72 std::string raw; // raw binary blob
73 std::string metaRaw;
74
75 // unpacked blob and meta
76 ripple::STTx sttx;
77 ripple::TxMeta meta;
78
79 // commonly used stuff
80 ripple::uint256 id;
81 std::string key; // key is the above id as a string of 32 characters
82 ripple::TxType type;
83
89 bool
90 operator==(Transaction const& other) const
91 {
92 return raw == other.raw //
93 and metaRaw == other.metaRaw //
94 and sttx.getTransactionID() == other.sttx.getTransactionID() //
95 and meta.getTxID() == other.meta.getTxID() //
96 and id == other.id //
97 and key == other.key //
98 and type == other.type;
99 }
100};
101
105struct Object {
109 enum class ModType : int {
110 Unspecified = 0,
111 Created = 1,
112 Modified = 2,
113 Deleted = 3,
114 };
115
116 ripple::uint256 key;
117 std::string keyRaw;
118 ripple::Blob data;
119 std::string dataRaw;
120 std::string successor;
121 std::string predecessor;
122
123 ModType type;
124
125 bool
126 operator==(Object const&) const = default;
127};
128
133 std::string firstBook;
134 std::string bookBase;
135
136 bool
137 operator==(BookSuccessor const&) const = default;
138};
139
144 std::vector<Transaction> transactions;
145 std::vector<Object> objects;
146 std::optional<std::vector<BookSuccessor>> successors;
147 std::optional<std::vector<std::string>> edgeKeys;
148
149 ripple::LedgerHeader header;
150 std::string rawHeader;
151 uint32_t seq;
152
158 bool
159 operator==(LedgerData const& other) const
160 {
161 auto const serialized = [](auto const& hdr) {
162 ripple::Serializer ser;
163 ripple::addRaw(hdr, ser);
164 return ser.getString();
165 };
166
167 return transactions == other.transactions //
168 and objects == other.objects //
169 and successors == other.successors //
170 and edgeKeys == other.edgeKeys //
171 and serialized(header) == serialized(other.header) //
172 and rawHeader == other.rawHeader //
173 and seq == other.seq;
174 }
175};
176
180struct Task {
184 enum class Priority : uint8_t {
185 Lower = 0u,
186 Higher = 1u,
187 };
188
189 Priority priority;
190 uint32_t seq;
191};
192
193} // namespace etlng::model
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
static consteval auto hasNoDuplicates(auto &&... values)
Checks that the list of given values contains no duplicates.
Definition Concepts.hpp:43
Represents a book successor.
Definition Models.hpp:132
Represents an entire ledger diff worth of transactions and objects.
Definition Models.hpp:143
bool operator==(LedgerData const &other) const
Compares LedgerData objects to each other without considering the header field.
Definition Models.hpp:159
Represents a single object on the ledger.
Definition Models.hpp:105
ModType
Modification type for the object.
Definition Models.hpp:109
A specification for the Registry.
Definition Models.hpp:52
static constexpr bool wants(ripple::TxType type) noexcept
Checks if the transaction type was requested.
Definition Models.hpp:62
Represents a task for the extractors.
Definition Models.hpp:180
Priority
Represents the priority of the task.
Definition Models.hpp:184
Represents a single transaction on the ledger.
Definition Models.hpp:71
bool operator==(Transaction const &other) const
Compares Transaction objects to each other without considering sttx and meta fields.
Definition Models.hpp:90