Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Source.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 "data/BackendInterface.hpp"
24#include "etlng/InitialLoadObserverInterface.hpp"
25#include "feed/SubscriptionManagerInterface.hpp"
26#include "rpc/Errors.hpp"
27#include "util/newconfig/ObjectView.hpp"
28
29#include <boost/asio/io_context.hpp>
30#include <boost/asio/spawn.hpp>
31#include <boost/json/object.hpp>
32#include <boost/uuid/uuid.hpp>
33#include <grpcpp/support/status.h>
34#include <org/xrpl/rpc/v1/get_ledger.pb.h>
35
36#include <chrono>
37#include <cstdint>
38#include <expected>
39#include <functional>
40#include <memory>
41#include <optional>
42#include <string>
43#include <string_view>
44#include <utility>
45#include <vector>
46
47namespace etlng {
48
53public:
54 using OnConnectHook = std::function<void()>;
55 using OnDisconnectHook = std::function<void(bool)>;
56 using OnLedgerClosedHook = std::function<void()>;
57
58 virtual ~SourceBase() = default;
59
63 virtual void
64 run() = 0;
65
72 virtual void
73 stop(boost::asio::yield_context yield) = 0;
74
80 [[nodiscard]] virtual bool
81 isConnected() const = 0;
82
88 virtual void
89 setForwarding(bool isForwarding) = 0;
90
96 [[nodiscard]] virtual boost::json::object
97 toJson() const = 0;
98
100 [[nodiscard]] virtual std::string
101 toString() const = 0;
102
109 [[nodiscard]] virtual bool
110 hasLedger(uint32_t sequence) const = 0;
111
123 [[nodiscard]] virtual std::pair<grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse>
124 fetchLedger(uint32_t sequence, bool getObjects = true, bool getObjectNeighbors = false) = 0;
125
134 virtual std::pair<std::vector<std::string>, bool>
135 loadInitialLedger(uint32_t sequence, std::uint32_t numMarkers, etlng::InitialLoadObserverInterface& loader) = 0;
136
146 [[nodiscard]] virtual std::expected<boost::json::object, rpc::ClioError>
148 boost::json::object const& request,
149 std::optional<std::string> const& forwardToRippledClientIp,
150 std::string_view xUserValue,
151 boost::asio::yield_context yield
152 ) const = 0;
153};
154
155using SourcePtr = std::unique_ptr<SourceBase>;
156
157using SourceFactory = std::function<SourcePtr(
158 util::config::ObjectView const& config,
159 boost::asio::io_context& ioc,
160 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
161 std::shared_ptr<etl::NetworkValidatedLedgersInterface> validatedLedgers,
162 std::chrono::steady_clock::duration forwardingTimeout,
163 SourceBase::OnConnectHook onConnect,
164 SourceBase::OnDisconnectHook onDisconnect,
165 SourceBase::OnLedgerClosedHook onLedgerClosed
166)>;
167
182[[nodiscard]] SourcePtr
183makeSource(
184 util::config::ObjectView const& config,
185 boost::asio::io_context& ioc,
186 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
187 std::shared_ptr<etl::NetworkValidatedLedgersInterface> validatedLedgers,
188 std::chrono::steady_clock::duration forwardingTimeout,
189 SourceBase::OnConnectHook onConnect,
190 SourceBase::OnDisconnectHook onDisconnect,
191 SourceBase::OnLedgerClosedHook onLedgerClosed
192);
193
194} // namespace etlng
Provides an implementation of a ETL source.
Definition Source.hpp:52
virtual bool isConnected() const =0
Check if source is connected.
virtual std::pair< std::vector< std::string >, bool > loadInitialLedger(uint32_t sequence, std::uint32_t numMarkers, etlng::InitialLoadObserverInterface &loader)=0
Download a ledger in full.
virtual std::expected< boost::json::object, rpc::ClioError > forwardToRippled(boost::json::object const &request, std::optional< std::string > const &forwardToRippledClientIp, std::string_view xUserValue, boost::asio::yield_context yield) const =0
Forward a request to rippled.
virtual boost::json::object toJson() const =0
Represent the source as a JSON object.
virtual void setForwarding(bool isForwarding)=0
Set the forwarding state of the source.
virtual void stop(boost::asio::yield_context yield)=0
Stop Source.
virtual bool hasLedger(uint32_t sequence) const =0
Check if ledger is known by this source.
virtual std::pair< grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse > fetchLedger(uint32_t sequence, bool getObjects=true, bool getObjectNeighbors=false)=0
Fetch data for a specific ledger.
virtual std::string toString() const =0
virtual void run()=0
Run subscriptions loop of the source.
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:40
The interface for observing the initial ledger load.
Definition InitialLoadObserverInterface.hpp:36