Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Unsubscribe.hpp
1#pragma once
2
3#include "feed/SubscriptionManagerInterface.hpp"
4#include "feed/Types.hpp"
5#include "rpc/common/Specs.hpp"
6#include "rpc/common/Types.hpp"
7
8#include <boost/json/conversion.hpp>
9#include <boost/json/value.hpp>
10#include <boost/json/value_to.hpp>
11#include <xrpl/protocol/Book.h>
12#include <xrpl/protocol/ErrorCodes.h>
13#include <xrpl/protocol/jss.h>
14
15#include <cstdint>
16#include <memory>
17#include <optional>
18#include <string>
19#include <vector>
20
21namespace rpc {
22
30
32 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions_;
33
34public:
38 struct OrderBook {
39 ripple::Book book;
40 bool both = false;
41 };
42
46 struct Input {
47 std::optional<std::vector<std::string>> accounts;
48 std::optional<std::vector<std::string>> streams;
49 std::optional<std::vector<std::string>> accountsProposed;
50 std::optional<std::vector<OrderBook>> books;
51 };
52
53 using Output = VoidOutput;
54 using Result = HandlerReturnType<Output>;
55
61 UnsubscribeHandler(std::shared_ptr<feed::SubscriptionManagerInterface> const& subscriptions);
62
69 static RpcSpecConstRef
70 spec([[maybe_unused]] uint32_t apiVersion);
71
79 Result
80 process(Input const& input, Context const& ctx) const;
81
82private:
83 void
84 unsubscribeFromStreams(
85 std::vector<std::string> const& streams,
86 feed::SubscriberSharedPtr const& session
87 ) const;
88
89 void
90 unsubscribeFromAccounts(
91 std::vector<std::string> accounts,
92 feed::SubscriberSharedPtr const& session
93 ) const;
94
95 void
96 unsubscribeFromProposedAccounts(
97 std::vector<std::string> accountsProposed,
98 feed::SubscriberSharedPtr const& session
99 ) const;
100
101 void
102 unsubscribeFromBooks(
103 std::vector<OrderBook> const& books,
104 feed::SubscriberSharedPtr const& session
105 ) const;
106
113 friend Input
114 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
115};
116
117} // namespace rpc
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition Unsubscribe.cpp:36
UnsubscribeHandler(std::shared_ptr< feed::SubscriptionManagerInterface > const &subscriptions)
Construct a new BaseUnsubscribeHandler object.
Definition Unsubscribe.cpp:28
Result process(Input const &input, Context const &ctx) const
Process the Unsubscribe command.
Definition Unsubscribe.cpp:79
friend Input tag_invoke(boost::json::value_to_tag< Input >, boost::json::value const &jv)
Convert a JSON object to an Input.
Definition Unsubscribe.cpp:159
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:18
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:130
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:62
Context of an RPC call.
Definition Types.hpp:99
A struct to hold the input data for the command.
Definition Unsubscribe.hpp:46
A struct to hold one order book.
Definition Unsubscribe.hpp:38
An empty type used as Output for handlers than don't actually produce output.
Definition Types.hpp:94