3#include "etl/Models.hpp"
4#include "etl/RegistryInterface.hpp"
5#include "etl/SystemState.hpp"
7#include <xrpl/protocol/TxFormats.h>
22 { p.onLedgerData(std::declval<model::LedgerData>()) } -> std::same_as<void>;
27 { p.onInitialData(std::declval<model::LedgerData>()) } -> std::same_as<void>;
32 { p.onTransaction(uint32_t{}, std::declval<model::Transaction>()) } -> std::same_as<void>;
37 { p.onObject(uint32_t{}, std::declval<model::Object>()) } -> std::same_as<void>;
43 p.onInitialTransaction(uint32_t{}, std::declval<model::Transaction>())
44 } -> std::same_as<void>;
50 p.onInitialObjects(uint32_t{}, std::declval<std::vector<model::Object>>(), std::string{})
51 } -> std::same_as<void>;
56 { p.onInitialObject(uint32_t{}, std::declval<model::Object>()) } -> std::same_as<void>;
78 std::reference_wrapper<SystemState const> state_;
79 std::tuple<Ps...> store_;
83 "Spec must be specified when 'onTransaction' function exists."
89 "Spec must be specified when 'onInitialTransaction' function exists."
94 requires(std::is_same_v<std::decay_t<
decltype(exts)>, std::decay_t<Ps>> and ...)
95 : state_{state}, store_(std::forward<Ps>(exts)...)
99 ~Registry()
override =
default;
100 Registry(Registry
const&) =
delete;
101 Registry(Registry&&) =
default;
103 operator=(Registry
const&) =
delete;
105 operator=(Registry&&) =
default;
112 auto const expand = [&](
auto& p) {
113 if constexpr (
requires { p.onLedgerData(
data); })
114 executeIfAllowed(p, [&
data](
auto& p) { p.onLedgerData(
data); });
117 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
123 if constexpr (
requires { p.onTransaction(
data.seq, t); }) {
124 if (std::decay_t<P>::spec::wants(t.type))
125 executeIfAllowed(p, [&
data, &t](
auto& p) { p.onTransaction(
data.seq, t); });
129 for (
auto const& t :
data.transactions) {
130 std::apply([&expand, &t](
auto&&... xs) { (expand(xs, t), ...); }, store_);
136 auto const expand = [&]<
typename P>(P&& p,
model::Object const& o) {
137 if constexpr (
requires { p.onObject(
data.seq, o); })
138 executeIfAllowed(p, [&
data, &o](
auto& p) { p.onObject(
data.seq, o); });
141 for (
auto const& obj :
data.objects) {
142 std::apply([&expand, &obj](
auto&&... xs) { (expand(xs, obj), ...); }, store_);
150 std::vector<model::Object>
const&
data,
156 auto const expand = [&](
auto&& p) {
157 if constexpr (
requires { p.onInitialObjects(seq,
data, lastKey); }) {
158 executeIfAllowed(p, [seq, &
data, &lastKey](
auto& p) {
159 p.onInitialObjects(seq,
data, lastKey);
164 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
169 auto const expand = [&]<
typename P>(P&& p,
model::Object const& o) {
170 if constexpr (
requires { p.onInitialObject(seq, o); })
171 executeIfAllowed(p, [seq, &o](
auto& p) { p.onInitialObject(seq, o); });
174 for (
auto const& obj :
data) {
175 std::apply([&expand, &obj](
auto&&... xs) { (expand(xs, obj), ...); }, store_);
185 auto const expand = [&](
auto&& p) {
186 if constexpr (
requires { p.onInitialData(
data); })
187 executeIfAllowed(p, [&
data](
auto& p) { p.onInitialData(
data); });
190 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
196 if constexpr (
requires { p.onInitialTransaction(
data.seq, tx); }) {
197 if (std::decay_t<P>::spec::wants(tx.type)) {
198 executeIfAllowed(p, [&
data, &tx](
auto& p) {
199 p.onInitialTransaction(
data.seq, tx);
205 for (
auto const& tx :
data.transactions) {
206 std::apply([&expand, &tx](
auto&&... xs) { (expand(xs, tx), ...); }, store_);
213 executeIfAllowed(
auto& p,
auto&& fn)
215 if constexpr (
requires { p.allowInReadonly(); }) {
216 if (state_.get().isWriting or p.allowInReadonly())
219 if (state_.get().isWriting)
226makeRegistry(SystemState
const& state,
auto&&... exts)
228 return std::make_unique<
Registry<std::decay_t<
decltype(exts)>...>>(
229 state, std::forward<
decltype(exts)>(exts)...
Definition Registry.hpp:77
constexpr void dispatch(model::LedgerData const &data) override
Dispatch an entire ledger diff.
Definition Registry.hpp:108
constexpr void dispatchInitialObjects(uint32_t seq, std::vector< model::Object > const &data, std::string lastKey) override
Dispatch initial objects.
Definition Registry.hpp:148
constexpr void dispatchInitialData(model::LedgerData const &data) override
Dispatch initial ledger data.
Definition Registry.hpp:181
Definition Registry.hpp:60
Definition Registry.hpp:63
Definition Registry.hpp:26
Definition Registry.hpp:55
Definition Registry.hpp:48
Definition Registry.hpp:41
Definition Registry.hpp:21
Definition Registry.hpp:36
Definition Registry.hpp:31
Definition Registry.hpp:69
Definition Registry.hpp:74
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:56
The interface for a registry that can dispatch transactions and objects to extensions.
Definition RegistryInterface.hpp:54
Represents the state of the ETL subsystem.
Definition SystemState.hpp:20
Represents an entire ledger diff worth of transactions and objects.
Definition Models.hpp:124
Represents a single object on the ledger.
Definition Models.hpp:86
Represents a single transaction on the ledger.
Definition Models.hpp:52