Clio develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AMMInfo.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 "data/BackendInterface.hpp"
23#include "rpc/common/Specs.hpp"
24
25#include <boost/json/array.hpp>
26#include <boost/json/conversion.hpp>
27#include <boost/json/value.hpp>
28#include <xrpl/protocol/AccountID.h>
29#include <xrpl/protocol/Issue.h>
30
31#include <cstdint>
32#include <memory>
33#include <optional>
34#include <string>
35
36namespace rpc {
37
44 std::shared_ptr<BackendInterface> sharedPtrBackend_;
45
46public:
50 struct Output {
51 // todo: use better type than json types
52 boost::json::value amount1;
53 boost::json::value amount2;
54 boost::json::value lpToken;
55 boost::json::array voteSlots;
56 boost::json::value auctionSlot;
57 std::uint16_t tradingFee = 0;
58 std::string ammAccount;
59 std::optional<bool> asset1Frozen;
60 std::optional<bool> asset2Frozen;
61
62 std::string ledgerHash;
63 uint32_t ledgerIndex{};
64 bool validated = true;
65 };
66
70 struct Input {
71 std::optional<ripple::AccountID> accountID;
72 std::optional<ripple::AccountID> ammAccount;
73 ripple::Issue issue1 = ripple::noIssue();
74 ripple::Issue issue2 = ripple::noIssue();
75 std::optional<std::string> ledgerHash;
76 std::optional<uint32_t> ledgerIndex;
77 };
78
79 using Result = HandlerReturnType<Output>;
80
86 AMMInfoHandler(std::shared_ptr<BackendInterface> const& sharedPtrBackend) : sharedPtrBackend_(sharedPtrBackend)
87 {
88 }
89
96 static RpcSpecConstRef
97 spec([[maybe_unused]] uint32_t apiVersion);
98
106 Result
107 process(Input input, Context const& ctx) const;
108
109private:
116 friend void
117 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
118
125 friend Input
126 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
127};
128
129} // namespace rpc
AMMInfoHandler returns information about AMM pools.
Definition AMMInfo.hpp:43
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition AMMInfo.cpp:230
Result process(Input input, Context const &ctx) const
Process the AMMInfo command.
Definition AMMInfo.cpp:81
AMMInfoHandler(std::shared_ptr< BackendInterface > const &sharedPtrBackend)
Construct a new AMMInfoHandler object.
Definition AMMInfo.hpp:86
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:279
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
A struct to hold the input data for the command.
Definition AMMInfo.hpp:70
A struct to hold the output data of the command.
Definition AMMInfo.hpp:50
Context of an RPC call.
Definition Types.hpp:118
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:129