Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ProposedTransactionFeed.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 "feed/Types.hpp"
23#include "feed/impl/TrackableSignal.hpp"
24#include "feed/impl/TrackableSignalMap.hpp"
25#include "feed/impl/Util.hpp"
26#include "util/async/AnyExecutionContext.hpp"
27#include "util/async/AnyStrand.hpp"
28#include "util/log/Logger.hpp"
29#include "util/prometheus/Gauge.hpp"
30
31#include <boost/asio/io_context.hpp>
32#include <boost/asio/strand.hpp>
33#include <boost/json/object.hpp>
34#include <fmt/core.h>
35#include <xrpl/protocol/AccountID.h>
36#include <xrpl/protocol/Book.h>
37#include <xrpl/protocol/LedgerHeader.h>
38
39#include <cstdint>
40#include <functional>
41#include <memory>
42#include <string>
43#include <unordered_set>
44
45namespace feed::impl {
46
52 util::Logger logger_{"Subscriptions"};
53
54 std::unordered_set<SubscriberPtr>
55 notified_; // Used by slots to prevent double notifications if tx contains multiple subscribed accounts
57 std::reference_wrapper<util::prometheus::GaugeInt> subAllCount_;
58 std::reference_wrapper<util::prometheus::GaugeInt> subAccountCount_;
59
62
63public:
69 : strand_(executionCtx.makeStrand())
70 , subAllCount_(getSubscriptionsGaugeInt("tx_proposed"))
71 , subAccountCount_(getSubscriptionsGaugeInt("account_proposed"))
72
73 {
74 }
75
80 void
81 sub(SubscriberSharedPtr const& subscriber);
82
88 void
89 sub(ripple::AccountID const& account, SubscriberSharedPtr const& subscriber);
90
95 void
96 unsub(SubscriberSharedPtr const& subscriber);
97
103 void
104 unsub(ripple::AccountID const& account, SubscriberSharedPtr const& subscriber);
105
110 void
111 pub(boost::json::object const& receivedTxJson);
112
116 std::uint64_t
117 transactionSubcount() const;
118
122 std::uint64_t
123 accountSubCount() const;
124
125private:
126 void
127 unsubInternal(SubscriberPtr subscriber);
128
129 void
130 unsubInternal(ripple::AccountID const& account, SubscriberPtr subscriber);
131};
132} // namespace feed::impl
Feed that publishes the Proposed Transactions.
Definition ProposedTransactionFeed.hpp:51
std::uint64_t accountSubCount() const
Get the number of accounts subscribers.
Definition ProposedTransactionFeed.cpp:122
std::uint64_t transactionSubcount() const
Get the number of subscribers of the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:116
ProposedTransactionFeed(util::async::AnyExecutionContext &executionCtx)
Construct a Proposed Transaction Feed object.
Definition ProposedTransactionFeed.hpp:68
void sub(SubscriberSharedPtr const &subscriber)
Subscribe to the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:39
void unsub(SubscriberSharedPtr const &subscriber)
Unsubscribe to the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:81
void pub(boost::json::object const &receivedTxJson)
Publishes the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:93
Class to manage a map of key and its associative signal.
Definition TrackableSignalMap.hpp:49
A thread-safe class to manage a signal and its tracking connections.
Definition TrackableSignal.hpp:44
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:110
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
A type-erased execution context.
Definition AnyStrand.hpp:40
An interface to provide connection functionality for subscriptions.
Definition SubscriptionContextInterface.hpp:39