Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ETLState.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, 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"
23#include "rpc/JS.hpp"
24
25#include <boost/json.hpp>
26#include <boost/json/conversion.hpp>
27#include <boost/json/object.hpp>
28#include <boost/json/value.hpp>
29#include <boost/json/value_to.hpp>
30#include <xrpl/protocol/jss.h>
31
32#include <cstdint>
33#include <optional>
34
35namespace etl {
36
40struct ETLState {
41 /*
42 * NOTE: Rippled NetworkID: Mainnet = 0; Testnet = 1; Devnet = 2
43 * However, if rippled is running on neither of these (ie. standalone mode) rippled will default to 0, but
44 * is not included in the stateOpt response. Must manually add it here.
45 */
46 uint32_t networkID{0};
47
53 template <typename Forward>
54 static std::optional<ETLState>
55 fetchETLStateFromSource(Forward& source) noexcept
56 {
57 auto const serverInfoRippled = data::synchronous([&source](auto yield) -> std::optional<boost::json::object> {
58 if (auto result = source.forwardToRippled({{"command", "server_info"}}, std::nullopt, {}, yield)) {
59 return std::move(result).value();
60 }
61 return std::nullopt;
62 });
63
64 if (serverInfoRippled && not serverInfoRippled->contains(JS(error))) {
65 return boost::json::value_to<ETLState>(boost::json::value(*serverInfoRippled));
66 }
67
68 return std::nullopt;
69 }
70};
71
78ETLState
79tag_invoke(boost::json::value_to_tag<ETLState>, boost::json::value const& jv);
80
81} // namespace etl
auto synchronous(FnType &&func)
Synchronously executes the given function object inside a coroutine.
Definition BackendInterface.hpp:104
This namespace contains everything to do with the ETL and ETL sources.
Definition CacheLoader.hpp:37
This class is responsible for fetching and storing the state of the ETL information,...
Definition ETLState.hpp:40
static std::optional< ETLState > fetchETLStateFromSource(Forward &source) noexcept
Fetch the ETL state from the rippled server.
Definition ETLState.hpp:55