Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
Unsubscribe.hpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of clio: https://github.com/XRPLF/clio
4 Copyright (c) 2023, 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/SubscriptionManagerInterface.hpp"
23#include "feed/Types.hpp"
24#include "rpc/common/Specs.hpp"
25#include "rpc/common/Types.hpp"
26
27#include <boost/json/conversion.hpp>
28#include <boost/json/value.hpp>
29#include <boost/json/value_to.hpp>
30#include <xrpl/protocol/Book.h>
31#include <xrpl/protocol/ErrorCodes.h>
32#include <xrpl/protocol/jss.h>
33
34#include <cstdint>
35#include <memory>
36#include <optional>
37#include <string>
38#include <vector>
39
40namespace rpc {
41
51 std::shared_ptr<feed::SubscriptionManagerInterface> subscriptions_;
52
53public:
57 struct OrderBook {
58 ripple::Book book;
59 bool both = false;
60 };
61
65 struct Input {
66 std::optional<std::vector<std::string>> accounts;
67 std::optional<std::vector<std::string>> streams;
68 std::optional<std::vector<std::string>> accountsProposed;
69 std::optional<std::vector<OrderBook>> books;
70 };
71
72 using Output = VoidOutput;
73 using Result = HandlerReturnType<Output>;
74
80 UnsubscribeHandler(std::shared_ptr<feed::SubscriptionManagerInterface> const& subscriptions);
81
88 static RpcSpecConstRef
89 spec([[maybe_unused]] uint32_t apiVersion);
90
98 Result
99 process(Input input, Context const& ctx) const;
100
101private:
102 void
103 unsubscribeFromStreams(std::vector<std::string> const& streams, feed::SubscriberSharedPtr const& session) const;
104
105 void
106 unsubscribeFromAccounts(std::vector<std::string> accounts, feed::SubscriberSharedPtr const& session) const;
107
108 void
109 unsubscribeFromProposedAccounts(std::vector<std::string> accountsProposed, feed::SubscriberSharedPtr const& session)
110 const;
111
112 void
113 unsubscribeFromBooks(std::vector<OrderBook> const& books, feed::SubscriberSharedPtr const& session) const;
114
121 friend Input
122 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
123};
124
125} // namespace rpc
Handles the unsubscribe command which is used to disconnect a subscriber from a feed....
Definition Unsubscribe.hpp:50
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition Unsubscribe.cpp:54
UnsubscribeHandler(std::shared_ptr< feed::SubscriptionManagerInterface > const &subscriptions)
Construct a new BaseUnsubscribeHandler object.
Definition Unsubscribe.cpp:48
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:166
Result process(Input input, Context const &ctx) const
Process the Unsubscribe command.
Definition Unsubscribe.cpp:90
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:36
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:145
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:81
Context of an RPC call.
Definition Types.hpp:118
A struct to hold the input data for the command.
Definition Unsubscribe.hpp:65
A struct to hold one order book.
Definition Unsubscribe.hpp:57
An empty type used as Output for handlers than don't actually produce output.
Definition Types.hpp:113