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>;
61 { p.onInitialTransaction(uint32_t{}, std::declval<model::Transaction>()) } -> std::same_as<void>;
66 { p.onInitialObjects(uint32_t{}, std::declval<std::vector<model::Object>>(), std::string{}) } -> std::same_as<void>;
71 { p.onInitialObject(uint32_t{}, std::declval<model::Object>()) } -> std::same_as<void>;
92 std::reference_wrapper<SystemState const> state_;
93 std::tuple<Ps...> store_;
97 "Spec must be specified when 'onTransaction' function exists."
102 "Spec must be specified when 'onInitialTransaction' function exists."
107 requires(std::is_same_v<std::decay_t<
decltype(exts)>, std::decay_t<Ps>> and ...)
108 : state_{state}, store_(std::forward<Ps>(exts)...)
112 ~Registry()
override =
default;
113 Registry(Registry
const&) =
delete;
114 Registry(Registry&&) =
default;
116 operator=(Registry
const&) =
delete;
118 operator=(Registry&&) =
default;
125 auto const expand = [&](
auto& p) {
126 if constexpr (
requires { p.onLedgerData(
data); })
127 executeIfAllowed(p, [&
data](
auto& p) { p.onLedgerData(
data); });
130 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
136 if constexpr (
requires { p.onTransaction(
data.seq, t); }) {
137 if (std::decay_t<P>::spec::wants(t.type))
138 executeIfAllowed(p, [&
data, &t](
auto& p) { p.onTransaction(
data.seq, t); });
142 for (
auto const& t :
data.transactions) {
143 std::apply([&expand, &t](
auto&&... xs) { (expand(xs, t), ...); }, store_);
149 auto const expand = [&]<
typename P>(P&& p,
model::Object const& o) {
150 if constexpr (
requires { p.onObject(
data.seq, o); })
151 executeIfAllowed(p, [&
data, &o](
auto& p) { p.onObject(
data.seq, o); });
154 for (
auto const& obj :
data.objects) {
155 std::apply([&expand, &obj](
auto&&... xs) { (expand(xs, obj), ...); }, store_);
165 auto const expand = [&](
auto&& p) {
166 if constexpr (
requires { p.onInitialObjects(seq,
data, lastKey); })
167 executeIfAllowed(p, [seq, &
data, &lastKey](
auto& p) { p.onInitialObjects(seq,
data, lastKey); });
170 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
175 auto const expand = [&]<
typename P>(P&& p,
model::Object const& o) {
176 if constexpr (
requires { p.onInitialObject(seq, o); })
177 executeIfAllowed(p, [seq, &o](
auto& p) { p.onInitialObject(seq, o); });
180 for (
auto const& obj :
data) {
181 std::apply([&expand, &obj](
auto&&... xs) { (expand(xs, obj), ...); }, store_);
191 auto const expand = [&](
auto&& p) {
192 if constexpr (
requires { p.onInitialData(
data); })
193 executeIfAllowed(p, [&
data](
auto& p) { p.onInitialData(
data); });
196 std::apply([&expand](
auto&&... xs) { (expand(xs), ...); }, store_);
202 if constexpr (
requires { p.onInitialTransaction(
data.seq, tx); }) {
203 if (std::decay_t<P>::spec::wants(tx.type))
204 executeIfAllowed(p, [&
data, &tx](
auto& p) { p.onInitialTransaction(
data.seq, tx); });
208 for (
auto const& tx :
data.transactions) {
209 std::apply([&expand, &tx](
auto&&... xs) { (expand(xs, tx), ...); }, store_);
216 executeIfAllowed(
auto& p,
auto&& fn)
218 if constexpr (
requires { p.allowInReadonly(); }) {
219 if (state_.get().isWriting or p.allowInReadonly())
222 if (state_.get().isWriting)
229makeRegistry(SystemState
const& state,
auto&&... exts)
231 return std::make_unique<
Registry<std::decay_t<
decltype(exts)>...>>(state, std::forward<
decltype(exts)>(exts)...);
Definition Registry.hpp:91
constexpr void dispatch(model::LedgerData const &data) override
Dispatch an entire ledger diff.
Definition Registry.hpp:121
constexpr void dispatchInitialObjects(uint32_t seq, std::vector< model::Object > const &data, std::string lastKey) override
Dispatch initial objects.
Definition Registry.hpp:161
constexpr void dispatchInitialData(model::LedgerData const &data) override
Dispatch initial ledger data.
Definition Registry.hpp:187
Definition Registry.hpp:75
Definition Registry.hpp:78
Definition Registry.hpp:45
Definition Registry.hpp:70
Definition Registry.hpp:65
Definition Registry.hpp:60
Definition Registry.hpp:40
Definition Registry.hpp:55
Definition Registry.hpp:50
Definition Registry.hpp:83
Definition Registry.hpp:88
This namespace implements the data access layer and related components.
Definition AmendmentCenter.cpp:70
The interface for a registry that can dispatch transactions and objects to extensions.
Definition RegistryInterface.hpp:72
Represents the state of the ETL subsystem.
Definition SystemState.hpp:33
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