Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
LedgerFeed.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"
23#include "feed/Types.hpp"
24#include "feed/impl/SingleFeedBase.hpp"
25#include "util/async/AnyExecutionContext.hpp"
26
27#include <boost/asio/io_context.hpp>
28#include <boost/asio/spawn.hpp>
29#include <boost/json/object.hpp>
30#include <boost/json/serialize.hpp>
31#include <xrpl/protocol/Fees.h>
32#include <xrpl/protocol/LedgerHeader.h>
33
34#include <cstdint>
35#include <memory>
36#include <string>
37
38namespace feed::impl {
39
46class LedgerFeed : public SingleFeedBase {
47public:
52 LedgerFeed(util::async::AnyExecutionContext& executionCtx) : SingleFeedBase(executionCtx, "ledger")
53 {
54 }
55
63 boost::json::object
64 sub(boost::asio::yield_context yield,
65 std::shared_ptr<data::BackendInterface const> const& backend,
66 SubscriberSharedPtr const& subscriber);
67
75 void
76 pub(ripple::LedgerHeader const& lgrInfo,
77 ripple::Fees const& fees,
78 std::string const& ledgerRange,
79 std::uint32_t txnCount);
80
81private:
82 static boost::json::object
83 makeLedgerPubMessage(
84 ripple::LedgerHeader const& lgrInfo,
85 ripple::Fees const& fees,
86 std::string const& ledgerRange,
87 std::uint32_t txnCount
88 );
89};
90} // namespace feed::impl
Feed that publishes the ledger info. Example : {'type': 'ledgerClosed', 'ledger_index': 2647935,...
Definition LedgerFeed.hpp:46
void pub(ripple::LedgerHeader const &lgrInfo, ripple::Fees const &fees, std::string const &ledgerRange, std::uint32_t txnCount)
Publishes the ledger feed.
Definition LedgerFeed.cpp:92
boost::json::object sub(boost::asio::yield_context yield, std::shared_ptr< data::BackendInterface const > const &backend, SubscriberSharedPtr const &subscriber)
Subscribe the ledger feed.
Definition LedgerFeed.cpp:64
LedgerFeed(util::async::AnyExecutionContext &executionCtx)
Construct a new Ledger Feed object.
Definition LedgerFeed.hpp:52
Base class for single feed.
Definition SingleFeedBase.hpp:42
A type-erased execution context.
Definition AnyExecutionContext.hpp:41