Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ETLState.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/JS.hpp"
5
6#include <boost/json.hpp>
7#include <boost/json/conversion.hpp>
8#include <boost/json/object.hpp>
9#include <boost/json/value.hpp>
10#include <boost/json/value_to.hpp>
11#include <xrpl/protocol/jss.h>
12
13#include <cstdint>
14#include <optional>
15
16namespace etl {
17
22struct ETLState {
23 /*
24 * NOTE: Rippled NetworkID: Mainnet = 0; Testnet = 1; Devnet = 2
25 * However, if rippled is running on neither of these (ie. standalone mode) rippled will default
26 * to 0, but is not included in the stateOpt response. Must manually add it here.
27 */
28 uint32_t networkID{0};
29
35 template <typename Forward>
36 static std::optional<ETLState>
37 fetchETLStateFromSource(Forward& source) noexcept
38 {
39 auto const serverInfoRippled =
40 data::synchronous([&source](auto yield) -> std::optional<boost::json::object> {
41 if (auto result = source.forwardToRippled(
42 {{"command", "server_info"}}, std::nullopt, {}, yield
43 )) {
44 return std::move(result).value();
45 }
46 return std::nullopt;
47 });
48
49 if (serverInfoRippled && not serverInfoRippled->contains(JS(error))) {
50 return boost::json::value_to<ETLState>(boost::json::value(*serverInfoRippled));
51 }
52
53 return std::nullopt;
54 }
55};
56
63ETLState
64tag_invoke(boost::json::value_to_tag<ETLState>, boost::json::value const& jv);
65
66} // namespace etl
auto synchronous(FnType &&func)
Synchronously executes the given function object inside a coroutine.
Definition BackendInterface.hpp:86
This class is responsible for fetching and storing the state of the ETL information,...
Definition ETLState.hpp:22
static std::optional< ETLState > fetchETLStateFromSource(Forward &source) noexcept
Fetch the ETL state from the rippled server.
Definition ETLState.hpp:37