Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
GetAggregatePrice.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/Errors.hpp"
5#include "rpc/common/SpecBackend.hpp"
6#include "rpc/common/Types.hpp"
7
8#include <boost/asio/spawn.hpp>
9#include <boost/json/array.hpp>
10#include <boost/json/conversion.hpp>
11#include <boost/json/value.hpp>
12#include <rpcspec/handlers/get_aggregate_price/Types.hpp>
13#include <xrpl/basics/Number.h>
14#include <xrpl/protocol/AccountID.h>
15#include <xrpl/protocol/STAmount.h>
16#include <xrpl/protocol/STObject.h>
17
18#include <cstddef>
19#include <cstdint>
20#include <expected>
21#include <functional>
22#include <memory>
23#include <optional>
24#include <string>
25#include <utility>
26#include <vector>
27
28namespace rpc {
29
34 : public rpc::HandlerFor<rpc::spec::handlers::get_aggregate_price::Input> {
35 std::shared_ptr<BackendInterface> sharedPtrBackend_;
36
37public:
41 struct Stats {
42 xrpl::STAmount avg{}; // NOLINT(readability-redundant-member-init)
43 // standard deviation
44 xrpl::Number sd{}; // NOLINT(readability-redundant-member-init)
45 uint32_t size{0};
46 };
47
51 struct Output {
52 uint32_t time;
53 Stats extireStats{};
54 std::optional<Stats> trimStats;
55 std::string ledgerHash;
56 uint32_t ledgerIndex;
57 std::string median;
58 bool validated = true;
59 };
60
61 using Result = HandlerReturnType<Output>;
62
68 GetAggregatePriceHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
69 : sharedPtrBackend_(std::move(sharedPtrBackend))
70 {
71 }
72
80 [[nodiscard]] Result
81 process(Input const& input, Context const& ctx) const;
82
83private:
90 void
91 tracebackOracleObject(
92 boost::asio::yield_context yield,
93 xrpl::STObject const& oracleObject,
94 std::function<bool(xrpl::STObject const&)> const& callback
95 ) const;
96
103 friend void
104 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
105};
106
107} // namespace rpc
GetAggregatePriceHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new GetAggregatePrice handler object.
Definition GetAggregatePrice.hpp:68
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition GetAggregatePrice.cpp:248
Result process(Input const &input, Context const &ctx) const
Process the GetAggregatePrice command.
Definition GetAggregatePrice.cpp:39
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
spec::HandlerFor< InputT, boost::json::value > HandlerFor
The spec-driven base every typed handler inherits.
Definition SpecBackend.hpp:24
Context of an RPC call.
Definition Types.hpp:98
A struct to hold the output data of the command.
Definition GetAggregatePrice.hpp:51
A struct to hold the statistics.
Definition GetAggregatePrice.hpp:41
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:109