Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
ProposedTransactionFeed.hpp
1#pragma once
2
3#include "feed/Types.hpp"
4#include "feed/impl/TrackableSignal.hpp"
5#include "feed/impl/TrackableSignalMap.hpp"
6#include "feed/impl/Util.hpp"
7#include "util/async/AnyExecutionContext.hpp"
8#include "util/async/AnyStrand.hpp"
9#include "util/log/Logger.hpp"
10#include "util/prometheus/Gauge.hpp"
11
12#include <boost/asio/io_context.hpp>
13#include <boost/asio/strand.hpp>
14#include <boost/json/object.hpp>
15#include <fmt/format.h>
16#include <xrpl/protocol/AccountID.h>
17#include <xrpl/protocol/Book.h>
18#include <xrpl/protocol/LedgerHeader.h>
19
20#include <cstdint>
21#include <functional>
22#include <memory>
23#include <string>
24#include <unordered_set>
25
26namespace feed::impl {
27
32 // Hold two versions of transaction messages
33 struct AllVersionMsgsType {
34 std::string v1;
35 std::string v2;
36 };
37
38 using AllVersionsMsgsPtrType = std::shared_ptr<AllVersionMsgsType>;
39
40 class ProposedTransactionSlot {
41 std::reference_wrapper<ProposedTransactionFeed> feed_;
42 std::weak_ptr<Subscriber> subscriptionContextWeakPtr_;
43
44 public:
45 ProposedTransactionSlot(
47 SubscriberSharedPtr const& connection
48 )
49 : feed_(feed), subscriptionContextWeakPtr_(connection)
50 {
51 }
52
53 void
54 operator()(AllVersionsMsgsPtrType const& allVersionMsgs) const;
55 };
56
57 util::Logger logger_{"Subscriptions"};
58
59 std::unordered_set<SubscriberPtr> notified_; // Used by slots to prevent double notifications
60 // if tx contains multiple subscribed accounts
62 std::reference_wrapper<util::prometheus::GaugeInt> subAllCount_;
63 std::reference_wrapper<util::prometheus::GaugeInt> subAccountCount_;
64
67
68public:
74
80 : strand_(executionCtx.makeStrand())
81 , subAllCount_(getSubscriptionsGaugeInt("tx_proposed"))
82 , subAccountCount_(getSubscriptionsGaugeInt("account_proposed"))
83
84 {
85 }
86
91 void
92 sub(SubscriberSharedPtr const& subscriber);
93
100 void
101 sub(ripple::AccountID const& account, SubscriberSharedPtr const& subscriber);
102
107 void
108 unsub(SubscriberSharedPtr const& subscriber);
109
115 void
116 unsub(ripple::AccountID const& account, SubscriberSharedPtr const& subscriber);
117
122 void
123 pub(boost::json::object const& receivedTxJson);
124
128 std::uint64_t
129 transactionSubcount() const;
130
134 std::uint64_t
135 accountSubCount() const;
136
137private:
138 void
139 unsubInternal(SubscriberPtr subscriber);
140
141 void
142 unsubInternal(ripple::AccountID const& account, SubscriberPtr subscriber);
143};
144} // namespace feed::impl
ProposedTransactionFeed(ProposedTransactionFeed &&)=delete
Move constructor is deleted because ProposedTransactionSlot takes ProposedTransactionFeed by referenc...
std::uint64_t accountSubCount() const
Get the number of accounts subscribers.
Definition ProposedTransactionFeed.cpp:142
std::uint64_t transactionSubcount() const
Get the number of subscribers of the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:136
ProposedTransactionFeed(util::async::AnyExecutionContext &executionCtx)
Construct a Proposed Transaction Feed object.
Definition ProposedTransactionFeed.hpp:79
void sub(SubscriberSharedPtr const &subscriber)
Subscribe to the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:42
void unsub(SubscriberSharedPtr const &subscriber)
Unsubscribe to the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:74
void pub(boost::json::object const &receivedTxJson)
Publishes the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:89
Class to manage a map of key and its associative signal.
Definition TrackableSignalMap.hpp:30
A thread-safe class to manage a signal and its tracking connections.
Definition TrackableSignal.hpp:26
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:77
A type-erased execution context.
Definition AnyExecutionContext.hpp:22
A type-erased execution context.
Definition AnyStrand.hpp:21
This namespace implements everything related to subscriptions.
Definition BookChangesFeed.hpp:14