Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AMMInfo.hpp
1#pragma once
2
3#include "data/AmendmentCenterInterface.hpp"
4#include "data/BackendInterface.hpp"
5#include "rpc/common/Types.hpp"
6
7#include <boost/json/array.hpp>
8#include <boost/json/conversion.hpp>
9#include <boost/json/value.hpp>
10#include <rpcspec/HandlerFor.hpp>
11#include <rpcspec/handlers/amm_info/Types.hpp>
12
13#include <cstdint>
14#include <memory>
15#include <optional>
16#include <string>
17#include <utility>
18
19namespace rpc {
20
26class AMMInfoHandler : public rpc::spec::HandlerFor<rpc::spec::handlers::amm_info::Input> {
27 std::shared_ptr<BackendInterface> sharedPtrBackend_;
28 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
29
30public:
34 struct Output {
35 // todo: use better type than json types
36 boost::json::value amount1;
37 boost::json::value amount2;
38 boost::json::value lpToken;
39 boost::json::array voteSlots;
40 boost::json::value auctionSlot;
41 std::uint16_t tradingFee = 0;
42 std::string ammAccount;
43 std::optional<bool> asset1Frozen;
44 std::optional<bool> asset2Frozen;
45
46 std::string ledgerHash;
47 uint32_t ledgerIndex{};
48 bool validated = true;
49 };
50
51 using Result = HandlerReturnType<Output>;
52
60 std::shared_ptr<BackendInterface> sharedPtrBackend,
61 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
62 )
63 : sharedPtrBackend_(std::move(sharedPtrBackend)), amendmentCenter_{amendmentCenter}
64 {
65 }
66
74 [[nodiscard]] Result
75 process(Input const& input, Context const& ctx) const;
76
77private:
84 friend void
85 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
86};
87
88} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the AMMInfo command.
Definition AMMInfo.cpp:56
AMMInfoHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new AMMInfoHandler object.
Definition AMMInfo.hpp:59
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition AMMInfo.cpp:223
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:17
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:61
A struct to hold the output data of the command.
Definition AMMInfo.hpp:34
Context of an RPC call.
Definition Types.hpp:98
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:109