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 "feed/SubscriptionManagerInterface.hpp"
25#include "rpc/Errors.hpp"
26#include "util/newconfig/ObjectView.hpp"
27
28#include <boost/asio/io_context.hpp>
29#include <boost/asio/spawn.hpp>
30#include <boost/json/object.hpp>
31#include <boost/uuid/uuid.hpp>
32#include <grpcpp/support/status.h>
33#include <org/xrpl/rpc/v1/get_ledger.pb.h>
34
35#include <chrono>
36#include <cstdint>
37#include <expected>
38#include <functional>
39#include <memory>
40#include <optional>
41#include <string>
42#include <string_view>
43#include <utility>
44#include <vector>
45
46namespace etl {
47
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 virtual bool
81 isConnected() const = 0;
82
88 virtual void
89 setForwarding(bool isForwarding) = 0;
90
96 virtual boost::json::object
97 toJson() const = 0;
98
100 virtual std::string
101 toString() const = 0;
102
109 virtual bool
110 hasLedger(uint32_t sequence) const = 0;
111
123 virtual std::pair<grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse>
124 fetchLedger(uint32_t sequence, bool getObjects = true, bool getObjectNeighbors = false) = 0;
125
133 virtual std::pair<std::vector<std::string>, bool>
134 loadInitialLedger(uint32_t sequence, std::uint32_t numMarkers) = 0;
135
145 virtual std::expected<boost::json::object, rpc::ClioError>
147 boost::json::object const& request,
148 std::optional<std::string> const& forwardToRippledClientIp,
149 std::string_view xUserValue,
150 boost::asio::yield_context yield
151 ) const = 0;
152};
153
154using SourcePtr = std::unique_ptr<SourceBase>;
155
156using SourceFactory = std::function<SourcePtr(
157 util::config::ObjectView const& config,
158 boost::asio::io_context& ioc,
159 std::shared_ptr<BackendInterface> backend,
160 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
161 std::shared_ptr<NetworkValidatedLedgersInterface> validatedLedgers,
162 std::chrono::steady_clock::duration forwardingTimeout,
163 SourceBase::OnConnectHook onConnect,
164 SourceBase::OnDisconnectHook onDisconnect,
165 SourceBase::OnLedgerClosedHook onLedgerClosed
166)>;
167
183SourcePtr
185 util::config::ObjectView const& config,
186 boost::asio::io_context& ioc,
187 std::shared_ptr<BackendInterface> backend,
188 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
189 std::shared_ptr<NetworkValidatedLedgersInterface> validatedLedgers,
190 std::chrono::steady_clock::duration forwardingTimeout,
191 SourceBase::OnConnectHook onConnect,
192 SourceBase::OnDisconnectHook onDisconnect,
193 SourceBase::OnLedgerClosedHook onLedgerClosed
194);
195
196} // namespace etl
Provides an implementation of a ETL source.
Definition Source.hpp:52
virtual std::pair< std::vector< std::string >, bool > loadInitialLedger(uint32_t sequence, std::uint32_t numMarkers)=0
Download a ledger in full.
virtual std::string toString() const =0
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 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 void run()=0
Run subscriptions loop of the source.
virtual boost::json::object toJson() const =0
Represent the source as a JSON object.
virtual bool isConnected() const =0
Check if source is connected.
virtual bool hasLedger(uint32_t sequence) const =0
Check if ledger is known by this source.
virtual void setForwarding(bool isForwarding)=0
Set the forwarding state of the source.
virtual void stop(boost::asio::yield_context yield)=0
Stop Source.
Provides a view into a subset of configuration data defined by a prefix.
Definition ObjectView.hpp:40
This namespace contains everything to do with the ETL and ETL sources.
Definition CacheLoader.hpp:37
SourcePtr makeSource(util::config::ObjectView const &config, boost::asio::io_context &ioc, std::shared_ptr< BackendInterface > backend, std::shared_ptr< feed::SubscriptionManagerInterface > subscriptions, std::shared_ptr< NetworkValidatedLedgersInterface > validatedLedgers, std::chrono::steady_clock::duration forwardingTimeout, SourceBase::OnConnectHook onConnect, SourceBase::OnDisconnectHook onDisconnect, SourceBase::OnLedgerClosedHook onLedgerClosed)
Create a source.
Definition Source.cpp:41