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/format.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> notified_; // Used by slots to prevent double notifications
55 // 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
89 void
90 sub(ripple::AccountID const& account, SubscriberSharedPtr const& subscriber);
91
96 void
97 unsub(SubscriberSharedPtr const& subscriber);
98
104 void
105 unsub(ripple::AccountID const& account, SubscriberSharedPtr const& subscriber);
106
111 void
112 pub(boost::json::object const& receivedTxJson);
113
117 std::uint64_t
118 transactionSubcount() const;
119
123 std::uint64_t
124 accountSubCount() const;
125
126private:
127 void
128 unsubInternal(SubscriberPtr subscriber);
129
130 void
131 unsubInternal(ripple::AccountID const& account, SubscriberPtr subscriber);
132};
133} // namespace feed::impl
std::uint64_t accountSubCount() const
Get the number of accounts subscribers.
Definition ProposedTransactionFeed.cpp:133
std::uint64_t transactionSubcount() const
Get the number of subscribers of the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:127
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:86
void pub(boost::json::object const &receivedTxJson)
Publishes the proposed transaction feed.
Definition ProposedTransactionFeed.cpp:101
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:45
A simple thread-safe logger for the channel specified in the constructor.
Definition Logger.hpp:96
A type-erased execution context.
Definition AnyExecutionContext.hpp:41
A type-erased execution context.
Definition AnyStrand.hpp:40