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/log/Logger.hpp"
27#include "util/newconfig/ConfigDefinition.hpp"
28#include "util/newconfig/ObjectView.hpp"
29
30#include <boost/asio/io_context.hpp>
31#include <boost/asio/spawn.hpp>
32#include <boost/json/object.hpp>
33#include <boost/uuid/uuid.hpp>
34#include <grpcpp/support/status.h>
35#include <org/xrpl/rpc/v1/get_ledger.pb.h>
36
37#include <chrono>
38#include <cstdint>
39#include <expected>
40#include <functional>
41#include <memory>
42#include <optional>
43#include <string>
44#include <string_view>
45#include <utility>
46#include <vector>
47
48namespace etl {
49
55public:
56 using OnConnectHook = std::function<void()>;
57 using OnDisconnectHook = std::function<void(bool)>;
58 using OnLedgerClosedHook = std::function<void()>;
59
60 virtual ~SourceBase() = default;
61
65 virtual void
66 run() = 0;
67
74 virtual void
75 stop(boost::asio::yield_context yield) = 0;
76
82 virtual bool
83 isConnected() const = 0;
84
90 virtual void
91 setForwarding(bool isForwarding) = 0;
92
98 virtual boost::json::object
99 toJson() const = 0;
100
102 virtual std::string
103 toString() const = 0;
104
111 virtual bool
112 hasLedger(uint32_t sequence) const = 0;
113
125 virtual std::pair<grpc::Status, org::xrpl::rpc::v1::GetLedgerResponse>
126 fetchLedger(uint32_t sequence, bool getObjects = true, bool getObjectNeighbors = false) = 0;
127
136 virtual std::pair<std::vector<std::string>, bool>
137 loadInitialLedger(uint32_t sequence, std::uint32_t numMarkers, bool cacheOnly = false) = 0;
138
148 virtual std::expected<boost::json::object, rpc::ClioError>
150 boost::json::object const& request,
151 std::optional<std::string> const& forwardToRippledClientIp,
152 std::string_view xUserValue,
153 boost::asio::yield_context yield
154 ) const = 0;
155};
156
157using SourcePtr = std::unique_ptr<SourceBase>;
158
159using SourceFactory = std::function<SourcePtr(
160 util::config::ObjectView const& config,
161 boost::asio::io_context& ioc,
162 std::shared_ptr<BackendInterface> backend,
163 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
164 std::shared_ptr<NetworkValidatedLedgersInterface> validatedLedgers,
165 std::chrono::steady_clock::duration forwardingTimeout,
166 SourceBase::OnConnectHook onConnect,
167 SourceBase::OnDisconnectHook onDisconnect,
168 SourceBase::OnLedgerClosedHook onLedgerClosed
169)>;
170
186SourcePtr
188 util::config::ObjectView const& config,
189 boost::asio::io_context& ioc,
190 std::shared_ptr<BackendInterface> backend,
191 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions,
192 std::shared_ptr<NetworkValidatedLedgersInterface> validatedLedgers,
193 std::chrono::steady_clock::duration forwardingTimeout,
194 SourceBase::OnConnectHook onConnect,
195 SourceBase::OnDisconnectHook onDisconnect,
196 SourceBase::OnLedgerClosedHook onLedgerClosed
197);
198
199} // namespace etl
Provides an implementation of a ETL source.
Definition Source.hpp:54
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 std::pair< std::vector< std::string >, bool > loadInitialLedger(uint32_t sequence, std::uint32_t numMarkers, bool cacheOnly=false)=0
Download a ledger in full.
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:36
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