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/SpecBackend.hpp"
6#include "rpc/common/Types.hpp"
7
8#include <boost/json/array.hpp>
9#include <boost/json/conversion.hpp>
10#include <boost/json/value.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::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
55
63 std::shared_ptr<BackendInterface> sharedPtrBackend,
64 std::shared_ptr<data::AmendmentCenterInterface const> const& amendmentCenter
65 )
66 : sharedPtrBackend_(std::move(sharedPtrBackend)), amendmentCenter_{amendmentCenter}
67 {
68 }
69
77 [[nodiscard]] Result
78 process(Input const& input, Context const& ctx) const;
79
80private:
87 friend void
88 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
89};
90
91} // namespace rpc
Result process(Input const &input, Context const &ctx) const
Process the AMMInfo command.
Definition AMMInfo.cpp:56
HandlerReturnType< Output > Result
The result type of the command: the Output on success or an error Status.
Definition AMMInfo.hpp:54
AMMInfoHandler(std::shared_ptr< BackendInterface > sharedPtrBackend, std::shared_ptr< data::AmendmentCenterInterface const > const &amendmentCenter)
Construct a new AMMInfoHandler object.
Definition AMMInfo.hpp:62
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:63
spec::HandlerFor< InputT, boost::json::value > HandlerFor
The spec-driven base every typed handler inherits.
Definition SpecBackend.hpp:24
A struct to hold the output data of the command.
Definition AMMInfo.hpp:34
std::uint16_t tradingFee
Trading fee in units of 1/100,000.
Definition AMMInfo.hpp:41
std::string ammAccount
Address of the AMM's special account.
Definition AMMInfo.hpp:42
std::string ledgerHash
Hash of the ledger the info was taken from.
Definition AMMInfo.hpp:46
boost::json::value amount2
Balance of the second asset in the AMM pool.
Definition AMMInfo.hpp:37
uint32_t ledgerIndex
Sequence of the ledger the info was taken from.
Definition AMMInfo.hpp:47
boost::json::value auctionSlot
Current auction slot holder info; null if none.
Definition AMMInfo.hpp:40
boost::json::array voteSlots
Current trading fee votes (account, fee, weight).
Definition AMMInfo.hpp:39
std::optional< bool > asset1Frozen
Whether the first asset is frozen; unset for XRP.
Definition AMMInfo.hpp:43
boost::json::value lpToken
LP tokens of account if given, else total.
Definition AMMInfo.hpp:38
bool validated
Whether the ledger is validated.
Definition AMMInfo.hpp:48
boost::json::value amount1
Balance of the first asset in the AMM pool.
Definition AMMInfo.hpp:36
std::optional< bool > asset2Frozen
Whether the second asset is frozen; unset for XRP.
Definition AMMInfo.hpp:44
Context of an RPC call.
Definition Types.hpp:102
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:132