22#include "etl/Models.hpp"
23#include "etl/RegistryInterface.hpp"
24#include "etl/SystemState.hpp"
26#include <xrpl/protocol/TxFormats.h>
41 { p.onLedgerData(std::declval<model::LedgerData>()) } -> std::same_as<void>;
46 { p.onInitialData(std::declval<model::LedgerData>()) } -> std::same_as<void>;
51 { p.onTransaction(uint32_t{}, std::declval<model::Transaction>()) } -> std::same_as<void>;
56 { p.onObject(uint32_t{}, std::declval<model::Object>()) } -> std::same_as<void>;
62 p.onInitialTransaction(uint32_t{}, std::declval<model::Transaction>())
63 } -> std::same_as<void>;
69 p.onInitialObjects(uint32_t{}, std::declval<std::vector<model::Object>>(), std::string{})
70 } -> std::same_as<void>;
75 { p.onInitialObject(uint32_t{}, std::declval<model::Object>()) } -> std::same_as<void>;
97 std::reference_wrapper<SystemState const> state_;
98 std::tuple<Ps...> store_;
102 "Spec must be specified when 'onTransaction' function exists."
108 "Spec must be specified when 'onInitialTransaction' function exists."
113 requires(std::is_same_v<std::decay_t<
decltype(exts)>, std::decay_t<Ps>> and ...)
114 : state_{state}, store_(std::forward<Ps>(exts)...)
118 ~Registry()
override =
default;
119 Registry(Registry
const&) =
delete;
120 Registry(Registry&&) =
default;
122 operator=(Registry
const&) =
delete;
124 operator=(Registry&&) =
default;
131 auto const expand = [&](
auto& p) {
132 if constexpr (
requires { p.onLedgerData(
data); })
133 executeIfAllowed(p, [&
data](
auto& p) { p.onLedgerData(
data); });
136 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
142 if constexpr (
requires { p.onTransaction(
data.seq, t); }) {
143 if (std::decay_t<P>::spec::wants(t.type))
144 executeIfAllowed(p, [&
data, &t](
auto& p) { p.onTransaction(
data.seq, t); });
148 for (
auto const& t :
data.transactions) {
149 std::apply([&expand, &t](
auto&&... xs) { (expand(xs, t), ...); }, store_);
155 auto const expand = [&]<
typename P>(P&& p,
model::Object const& o) {
156 if constexpr (
requires { p.onObject(
data.seq, o); })
157 executeIfAllowed(p, [&
data, &o](
auto& p) { p.onObject(
data.seq, o); });
160 for (
auto const& obj :
data.objects) {
161 std::apply([&expand, &obj](
auto&&... xs) { (expand(xs, obj), ...); }, store_);
169 std::vector<model::Object>
const&
data,
175 auto const expand = [&](
auto&& p) {
176 if constexpr (
requires { p.onInitialObjects(seq,
data, lastKey); })
177 executeIfAllowed(p, [seq, &
data, &lastKey](
auto& p) {
178 p.onInitialObjects(seq,
data, lastKey);
182 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
187 auto const expand = [&]<
typename P>(P&& p,
model::Object const& o) {
188 if constexpr (
requires { p.onInitialObject(seq, o); })
189 executeIfAllowed(p, [seq, &o](
auto& p) { p.onInitialObject(seq, o); });
192 for (
auto const& obj :
data) {
193 std::apply([&expand, &obj](
auto&&... xs) { (expand(xs, obj), ...); }, store_);
203 auto const expand = [&](
auto&& p) {
204 if constexpr (
requires { p.onInitialData(
data); })
205 executeIfAllowed(p, [&
data](
auto& p) { p.onInitialData(
data); });
208 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
214 if constexpr (
requires { p.onInitialTransaction(
data.seq, tx); }) {
215 if (std::decay_t<P>::spec::wants(tx.type))
216 executeIfAllowed(p, [&
data, &tx](
auto& p) {
217 p.onInitialTransaction(
data.seq, tx);
222 for (
auto const& tx :
data.transactions) {
223 std::apply([&expand, &tx](
auto&&... xs) { (expand(xs, tx), ...); }, store_);
230 executeIfAllowed(
auto& p,
auto&& fn)
232 if constexpr (
requires { p.allowInReadonly(); }) {
233 if (state_.get().isWriting or p.allowInReadonly())
236 if (state_.get().isWriting)
243makeRegistry(SystemState
const& state,
auto&&... exts)
245 return std::make_unique<
Registry<std::decay_t<
decltype(exts)>...>>(
246 state, std::forward<
decltype(exts)>(exts)...
Definition Registry.hpp:96
constexpr void dispatch(model::LedgerData const &data) override
Dispatch an entire ledger diff.
Definition Registry.hpp:127
constexpr void dispatchInitialObjects(uint32_t seq, std::vector< model::Object > const &data, std::string lastKey) override
Dispatch initial objects.
Definition Registry.hpp:167
constexpr void dispatchInitialData(model::LedgerData const &data) override
Dispatch initial ledger data.
Definition Registry.hpp:199
Definition Registry.hpp:79
Definition Registry.hpp:82
Definition Registry.hpp:45
Definition Registry.hpp:74
Definition Registry.hpp:67
Definition Registry.hpp:60
Definition Registry.hpp:40
Definition Registry.hpp:55
Definition Registry.hpp:50
Definition Registry.hpp:88
Definition Registry.hpp:93
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:75
The interface for a registry that can dispatch transactions and objects to extensions.
Definition RegistryInterface.hpp:73
Represents the state of the ETL subsystem.
Definition SystemState.hpp:38
Represents an entire ledger diff worth of transactions and objects.
Definition Models.hpp:143
Represents a single object on the ledger.
Definition Models.hpp:105
Represents a single transaction on the ledger.
Definition Models.hpp:71