22#include "data/BackendInterface.hpp"
25#include "rpc/common/MetaProcessors.hpp"
26#include "rpc/common/Modifiers.hpp"
27#include "rpc/common/Specs.hpp"
28#include "rpc/common/Types.hpp"
29#include "rpc/common/Validators.hpp"
31#include <boost/asio/spawn.hpp>
32#include <boost/json/array.hpp>
33#include <boost/json/conversion.hpp>
34#include <xrpl/basics/Number.h>
35#include <xrpl/protocol/AccountID.h>
36#include <xrpl/protocol/STAmount.h>
37#include <xrpl/protocol/STObject.h>
38#include <xrpl/protocol/jss.h>
55 std::shared_ptr<BackendInterface> sharedPtrBackend_;
73 std::optional<Stats> trimStats;
74 std::string ledgerHash;
77 bool validated =
true;
85 Output(uint32_t time, std::string ledgerHash, uint32_t ledgerIndex)
86 : time(time), ledgerHash(std::move(ledgerHash)), ledgerIndex(ledgerIndex)
95 std::uint32_t documentId{0};
96 ripple::AccountID account;
103 std::optional<std::string> ledgerHash;
104 std::optional<std::uint32_t> ledgerIndex;
105 std::vector<Oracle> oracles;
106 std::string baseAsset;
107 std::string quoteAsset;
108 std::optional<std::uint32_t> timeThreshold;
109 std::optional<std::uint8_t> trim;
120 : sharedPtrBackend_(sharedPtrBackend)
131 spec([[maybe_unused]] uint32_t apiVersion)
133 static constexpr auto kORACLES_MAX = 200;
135 static auto const kORACLES_VALIDATOR =
137 if (!value.is_array() or value.as_array().empty() or value.as_array().size() > kORACLES_MAX)
138 return Error{
Status{RippledError::rpcORACLE_MALFORMED}};
140 for (
auto& oracle : value.as_array()) {
141 if (!oracle.is_object() or !oracle.as_object().contains(JS(oracle_document_id)) or
142 !oracle.as_object().contains(JS(account)))
143 return Error{
Status{RippledError::rpcORACLE_MALFORMED}};
146 oracle.as_object(), JS(oracle_document_id)
158 return Error{
Status{RippledError::rpcINVALID_PARAMS}};
164 static auto const kRPC_SPEC =
RpcSpec{
210 tracebackOracleObject(
211 boost::asio::yield_context yield,
212 ripple::STObject
const& oracleObject,
213 std::function<
bool(ripple::STObject
const&)>
const& callback
223 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output
const& output);
232 tag_invoke(boost::json::value_to_tag<Input>, boost::json::value
const& jv);
The get_aggregate_price method.
Definition GetAggregatePrice.hpp:54
static RpcSpecConstRef spec(uint32_t apiVersion)
Returns the API specification for the command.
Definition GetAggregatePrice.hpp:131
GetAggregatePriceHandler(std::shared_ptr< BackendInterface > const &sharedPtrBackend)
Construct a new GetAggregatePrice handler object.
Definition GetAggregatePrice.hpp:119
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:287
Result process(Input input, Context const &ctx) const
Process the GetAggregatePrice command.
Definition GetAggregatePrice.cpp:62
Customised modifier allowing user define how to modify input in provided callable.
Definition Modifiers.hpp:145
Validate that value is between specified min and max.
Definition Validators.hpp:170
MaybeError verify(boost::json::value const &value, std::string_view key) const
Verify that the JSON value is valid according to the custom validation function stored.
Definition Validators.cpp:77
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
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:55
std::unexpected< Status > Error
The type that represents just the error part of MaybeError.
Definition Types.hpp:75
Context of an RPC call.
Definition Types.hpp:118
A struct to hold the input oracle data.
Definition GetAggregatePrice.hpp:94
A struct to hold the output data of the command.
Definition GetAggregatePrice.hpp:70
Output(uint32_t time, std::string ledgerHash, uint32_t ledgerIndex)
Construct a new Output object.
Definition GetAggregatePrice.hpp:85
A struct to hold the statistics.
Definition GetAggregatePrice.hpp:61
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:129
Represents a Specification of an entire RPC command.
Definition Specs.hpp:98
A status returned from any RPC handler.
Definition Errors.hpp:82
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:121
static CustomValidator currencyValidator
Provides a commonly used validator for currency, including standard currency code and token code.
Definition Validators.hpp:535
static CustomValidator ledgerIndexValidator
Provides a commonly used validator for ledger index.
Definition Validators.hpp:484
static CustomValidator uint256HexStringValidator
Provides a commonly used validator for uint256 hex string.
Definition Validators.hpp:530
static CustomValidator accountBase58Validator
Provides a commonly used validator for accounts.
Definition Validators.hpp:498
A validator that simply requires a field to be present.
Definition Validators.hpp:47
Validates that the type of the value is one of the given types.
Definition Validators.hpp:142
MaybeError verify(boost::json::value const &value, std::string_view key) const
Verify that the JSON value is (one) of specified type(s).
Definition Validators.hpp:151