3#include "data/BackendInterface.hpp"
6#include "rpc/common/MetaProcessors.hpp"
7#include "rpc/common/Modifiers.hpp"
8#include "rpc/common/Specs.hpp"
9#include "rpc/common/Types.hpp"
10#include "rpc/common/Validators.hpp"
12#include <boost/asio/spawn.hpp>
13#include <boost/json/array.hpp>
14#include <boost/json/conversion.hpp>
15#include <xrpl/basics/Number.h>
16#include <xrpl/protocol/AccountID.h>
17#include <xrpl/protocol/STAmount.h>
18#include <xrpl/protocol/STObject.h>
19#include <xrpl/protocol/jss.h>
35 std::shared_ptr<BackendInterface> sharedPtrBackend_;
42 ripple::STAmount avg{};
54 std::optional<Stats> trimStats;
55 std::string ledgerHash;
58 bool validated =
true;
65 std::uint32_t documentId{0};
66 ripple::AccountID account;
73 std::optional<std::string> ledgerHash;
74 std::optional<std::uint32_t> ledgerIndex;
75 std::vector<Oracle> oracles;
76 std::string baseAsset;
77 std::string quoteAsset;
78 std::optional<std::uint32_t> timeThreshold;
79 std::optional<std::uint8_t> trim;
90 : sharedPtrBackend_(std::move(sharedPtrBackend))
101 spec([[maybe_unused]] uint32_t apiVersion)
103 static constexpr auto kORACLES_MAX = 200;
106 [](boost::json::value& value, std::string_view) ->
MaybeError {
107 if (!value.is_array() or value.as_array().empty() or
108 value.as_array().size() > kORACLES_MAX)
109 return Error{
Status{RippledError::rpcORACLE_MALFORMED}};
111 for (
auto& oracle : value.as_array()) {
112 if (!oracle.is_object() or
113 !oracle.as_object().contains(JS(oracle_document_id)) or
114 !oracle.as_object().contains(JS(account)))
115 return Error{
Status{RippledError::rpcORACLE_MALFORMED}};
118 oracle, JS(oracle_document_id)
128 oracle.as_object(), JS(account)
131 return Error{
Status{RippledError::rpcINVALID_PARAMS}};
138 static auto const kRPC_SPEC =
RpcSpec{
150 Status(RippledError::rpcINVALID_PARAMS)
156 Status(RippledError::rpcINVALID_PARAMS)
188 tracebackOracleObject(
189 boost::asio::yield_context yield,
190 ripple::STObject
const& oracleObject,
191 std::function<
bool(ripple::STObject
const&)>
const& callback
201 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output);
210 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value
const& jv);
GetAggregatePriceHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new GetAggregatePrice handler object.
Definition GetAggregatePrice.hpp:89
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition GetAggregatePrice.hpp:101
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:290
Result process(Input const &input, Context const &ctx) const
Process the GetAggregatePrice command.
Definition GetAggregatePrice.cpp:43
Customised modifier allowing user define how to modify input in provided callable.
Definition Modifiers.hpp:127
Validate that value is between specified min and max.
Definition Validators.hpp:159
This namespace contains all the RPC logic and handlers.
Definition AMMHelpers.cpp:18
RpcSpec const & RpcSpecConstRef
An alias for a const reference to RpcSpec.
Definition Specs.hpp:130
std::expected< OutputType, Status > HandlerReturnType
Return type for each individual handler.
Definition Types.hpp:62
std::expected< void, Status > MaybeError
Return type used for Validators that can return error but don't have specific value to return.
Definition Types.hpp:36
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:56
Context of an RPC call.
Definition Types.hpp:99
A struct to hold the input oracle data.
Definition GetAggregatePrice.hpp:64
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:110
Represents a Specification of an entire RPC command.
Definition Specs.hpp:82
A status returned from any RPC handler.
Definition Errors.hpp:65
static MaybeError modify(boost::json::value &value, std::string_view key)
Update the input string to integer if it can be converted to integer by stoi.
Definition Modifiers.hpp:103
static CustomValidator currencyValidator
Provides a commonly used validator for currency, including standard currency code and token code.
Definition Validators.hpp:557
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:489
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:551
static CustomValidator accountBase58Validator
Provides a commonly used validator for accounts.
Definition Validators.hpp:511
A validator that simply requires a field to be present.
Definition Validators.hpp:28
Validates that the type of the value is one of the given types.
Definition Validators.hpp:128
MaybeError verify(boost::json::value &value, std::string_view key) const
Verify that the JSON value is (one) of specified type(s).
Definition Validators.hpp:140