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/AmendmentCenterInterface.hpp"
23#include "data/BackendInterface.hpp"
24#include "rpc/common/Specs.hpp"
25
26#include <boost/json/array.hpp>
27#include <boost/json/conversion.hpp>
28#include <boost/json/value.hpp>
29#include <xrpl/protocol/AccountID.h>
30#include <xrpl/protocol/Issue.h>
31
32#include <cstdint>
33#include <memory>
34#include <optional>
35#include <string>
36
37namespace rpc {
38
45 std::shared_ptr<BackendInterface> sharedPtrBackend_;
46 std::shared_ptr<data::AmendmentCenterInterface const> amendmentCenter_;
47
48public:
52 struct Output {
53 // todo: use better type than json types
54 boost::json::value amount1;
55 boost::json::value amount2;
56 boost::json::value lpToken;
57 boost::json::array voteSlots;
58 boost::json::value auctionSlot;
59 std::uint16_t tradingFee = 0;
60 std::string ammAccount;
61 std::optional<bool> asset1Frozen;
62 std::optional<bool> asset2Frozen;
63
64 std::string ledgerHash;
65 uint32_t ledgerIndex{};
66 bool validated = true;
67 };
68
72 struct Input {
73 std::optional<ripple::AccountID> accountID;
74 std::optional<ripple::AccountID> ammAccount;
75 ripple::Issue issue1 = ripple::noIssue();
76 ripple::Issue issue2 = ripple::noIssue();
77 std::optional<std::string> ledgerHash;
78 std::optional<uint32_t> ledgerIndex;
79 };
80
81 using Result = HandlerReturnType<Output>;
82
90 std::shared_ptr<BackendInterface> const& sharedPtrBackend,
91 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
92 )
93 : sharedPtrBackend_(sharedPtrBackend), amendmentCenter_{amendmentCenter}
94 {
95 }
96
103 static RpcSpecConstRef
104 spec([[maybe_unused]] uint32_t apiVersion);
105
113 Result
114 process(Input input, Context const& ctx) const;
115
116private:
123 friend void
124 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
125
132 friend Input
133 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value const& jv);
134};
135
136} // namespace rpc
AMMInfoHandler returns information about AMM pools.
Definition AMMInfo.hpp:44
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition AMMInfo.cpp:231
Result process(Input input, Context const &ctx) const
Process the AMMInfo command.
Definition AMMInfo.cpp:81
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:280
AMMInfoHandler(std::shared_ptr< BackendInterface > const &sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new AMMInfoHandler object.
Definition AMMInfo.hpp:89
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:37
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:72
A struct to hold the output data of the command.
Definition AMMInfo.hpp:52
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