Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
AccountOffers.hpp
1#pragma once
2
3#include "data/BackendInterface.hpp"
4#include "rpc/common/SpecBackend.hpp"
5#include "rpc/common/Types.hpp"
6
7#include <boost/json/conversion.hpp>
8#include <boost/json/value.hpp>
9#include <rpcspec/handlers/account_offers/Types.hpp>
10#include <xrpl/protocol/STAmount.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12
13#include <cstdint>
14#include <memory>
15#include <optional>
16#include <string>
17#include <utility>
18#include <vector>
19
20namespace rpc {
21
27class AccountOffersHandler : public rpc::HandlerFor<rpc::spec::handlers::account_offers::Input> {
28 std::shared_ptr<BackendInterface> sharedPtrBackend_;
29
30public:
34 static constexpr auto kLimitMin = rpc::spec::handlers::account_offers::kLimitMin;
38 static constexpr auto kLimitMax = rpc::spec::handlers::account_offers::kLimitMax;
42 static constexpr auto kLimitDefault = rpc::spec::handlers::account_offers::kLimitDefault;
43
47 struct Offer {
48 uint32_t flags{};
49 uint32_t seq{};
50 xrpl::STAmount takerGets;
51 xrpl::STAmount takerPays;
52 std::string quality;
53 std::optional<uint32_t> expiration;
54 };
55
59 struct Output {
60 std::string account;
61 std::string ledgerHash;
62 uint32_t ledgerIndex{};
63 std::vector<Offer> offers;
64 std::optional<std::string> marker;
65 // validated should be sent via framework
66 bool validated = true;
67 };
68
73
79 AccountOffersHandler(std::shared_ptr<BackendInterface> sharedPtrBackend)
80 : sharedPtrBackend_(std::move(sharedPtrBackend))
81 {
82 }
83
91 [[nodiscard]] Result
92 process(Input const& input, Context const& ctx) const;
93
94private:
95 static void
96 addOffer(std::vector<Offer>& offers, xrpl::SLE const& offerSle);
97
104 friend void
105 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
106
113 friend void
114 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Offer const& offer);
115};
116} // namespace rpc
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition AccountOffers.cpp:105
static constexpr auto kLimitMin
Minimum accepted value for the limit request field.
Definition AccountOffers.hpp:34
static constexpr auto kLimitDefault
Value of limit used when the request does not specify one.
Definition AccountOffers.hpp:42
Result process(Input const &input, Context const &ctx) const
Process the AccountOffers command.
Definition AccountOffers.cpp:48
AccountOffersHandler(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new AccountOffersHandler object.
Definition AccountOffers.hpp:79
HandlerReturnType< Output > Result
The result type of the command: the Output on success or an error Status.
Definition AccountOffers.hpp:72
static constexpr auto kLimitMax
Maximum accepted value for the limit request field.
Definition AccountOffers.hpp:38
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 data for one offer response.
Definition AccountOffers.hpp:47
xrpl::STAmount takerPays
Amount the offer creator wants in return.
Definition AccountOffers.hpp:51
uint32_t seq
Sequence number of the transaction that created the offer.
Definition AccountOffers.hpp:49
uint32_t flags
Flags set on the offer.
Definition AccountOffers.hpp:48
std::optional< uint32_t > expiration
Time after which the offer is no longer active.
Definition AccountOffers.hpp:53
xrpl::STAmount takerGets
Amount the offer creator is selling.
Definition AccountOffers.hpp:50
std::string quality
Exchange rate of the offer (takerPays / takerGets).
Definition AccountOffers.hpp:52
A struct to hold the output data of the command.
Definition AccountOffers.hpp:59
std::string ledgerHash
Hash of the ledger used for the request.
Definition AccountOffers.hpp:61
std::string account
The account whose offers are returned.
Definition AccountOffers.hpp:60
uint32_t ledgerIndex
Sequence of the ledger used for the request.
Definition AccountOffers.hpp:62
bool validated
Whether the ledger is validated.
Definition AccountOffers.hpp:66
std::vector< Offer > offers
Offers owned by the account.
Definition AccountOffers.hpp:63
std::optional< std::string > marker
Pagination marker to resume from, if more results.
Definition AccountOffers.hpp:64
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