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
47class LedgerFeed : public SingleFeedBase {
48public:
53 LedgerFeed(util::async::AnyExecutionContext& executionCtx) : SingleFeedBase(executionCtx, "ledger")
54 {
55 }
56
65 boost::json::object
66 sub(boost::asio::yield_context yield,
67 std::shared_ptr<data::BackendInterface const> const& backend,
68 SubscriberSharedPtr const& subscriber,
69 uint32_t networkID);
70
79 void
80 pub(ripple::LedgerHeader const& lgrInfo,
81 ripple::Fees const& fees,
82 std::string const& ledgerRange,
83 uint32_t txnCount,
84 uint32_t networkID);
85
86private:
87 static boost::json::object
88 makeLedgerPubMessage(
89 ripple::LedgerHeader const& lgrInfo,
90 ripple::Fees const& fees,
91 std::string const& ledgerRange,
92 uint32_t txnCount,
93 uint32_t networkID
94 );
95};
96} // namespace feed::impl
Feed that publishes the ledger info. Example : {'type': 'ledgerClosed', 'ledger_index': 2647935,...
Definition LedgerFeed.hpp:47
void pub(ripple::LedgerHeader const &lgrInfo, ripple::Fees const &fees, std::string const &ledgerRange, uint32_t txnCount, uint32_t networkID)
Publishes the ledger feed.
Definition LedgerFeed.cpp:95
LedgerFeed(util::async::AnyExecutionContext &executionCtx)
Construct a new Ledger Feed object.
Definition LedgerFeed.hpp:53
boost::json::object sub(boost::asio::yield_context yield, std::shared_ptr< data::BackendInterface const > const &backend, SubscriberSharedPtr const &subscriber, uint32_t networkID)
Subscribe the ledger feed.
Definition LedgerFeed.cpp:66
Base class for single feed.
Definition SingleFeedBase.hpp:42
A type-erased execution context.
Definition AnyExecutionContext.hpp:41