Clio  develop
The XRP Ledger API server.
Loading...
Searching...
No Matches
NFTOffersCommon.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/asio/spawn.hpp>
8#include <boost/json/conversion.hpp>
9#include <boost/json/value.hpp>
10#include <rpcspec/handlers/nft_offers_common/Types.hpp>
11#include <xrpl/basics/base_uint.h>
12#include <xrpl/protocol/Keylet.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14
15#include <cstdint>
16#include <memory>
17#include <optional>
18#include <string>
19#include <utility>
20#include <vector>
21
22namespace rpc {
23
27class NFTOffersHandlerBase : public rpc::HandlerFor<rpc::spec::handlers::nft_offers_common::Input> {
28 std::shared_ptr<BackendInterface> sharedPtrBackend_;
29
30public:
34 static constexpr auto kLimitMin = rpc::spec::handlers::nft_offers_common::kLimitMin;
38 static constexpr auto kLimitMax = rpc::spec::handlers::nft_offers_common::kLimitMax;
42 static constexpr auto kLimitDefault = rpc::spec::handlers::nft_offers_common::kLimitDefault;
43
47 struct Output {
48 std::string nftID;
49 std::vector<xrpl::SLE> offers;
50
51 // validated should be sent via framework
52 bool validated = true;
53 std::optional<uint32_t> limit;
54 std::optional<std::string> marker;
55 };
56
61
67 NFTOffersHandlerBase(std::shared_ptr<BackendInterface> sharedPtrBackend)
68 : sharedPtrBackend_(std::move(sharedPtrBackend))
69 {
70 }
71
72protected:
82 [[nodiscard]] Result
84 Input input,
85 xrpl::uint256 const& tokenID,
86 xrpl::Keylet const& directory,
87 boost::asio::yield_context yield
88 ) const;
89
90private:
97 friend void
98 tag_invoke(boost::json::value_from_tag, boost::json::value& jv, Output const& output);
99};
100
101} // namespace rpc
Result iterateOfferDirectory(Input input, xrpl::uint256 const &tokenID, xrpl::Keylet const &directory, boost::asio::yield_context yield) const
Iterate the NFT offer directory.
Definition NFTOffersCommon.cpp:66
friend void tag_invoke(boost::json::value_from_tag, boost::json::value &jv, Output const &output)
Convert the Output to a JSON object.
Definition NFTOffersCommon.cpp:160
HandlerReturnType< Output > Result
The result type of the command: either the Output or an error status.
Definition NFTOffersCommon.hpp:60
static constexpr auto kLimitMin
Minimum allowed value of the limit parameter.
Definition NFTOffersCommon.hpp:34
NFTOffersHandlerBase(std::shared_ptr< BackendInterface > sharedPtrBackend)
Construct a new NFTOffersHandlerBase object.
Definition NFTOffersCommon.hpp:67
static constexpr auto kLimitDefault
Default value of the limit parameter.
Definition NFTOffersCommon.hpp:42
static constexpr auto kLimitMax
Maximum allowed value of the limit parameter.
Definition NFTOffersCommon.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 the output data of the command.
Definition NFTOffersCommon.hpp:47
std::vector< xrpl::SLE > offers
NFT offer ledger objects.
Definition NFTOffersCommon.hpp:49
std::optional< uint32_t > limit
Limit used, set only if more offers remain.
Definition NFTOffersCommon.hpp:53
std::optional< std::string > marker
Key of the next page's first offer, if any.
Definition NFTOffersCommon.hpp:54
std::string nftID
ID of the NFT the offers are for.
Definition NFTOffersCommon.hpp:48
bool validated
Whether the ledger is validated.
Definition NFTOffersCommon.hpp:52
Result type used to return responses or error statuses to the Webserver subsystem.
Definition Types.hpp:132