1#include <xrpld/rpc/handlers/orderbook/NFTOffersCommon.h>
3#include <xrpld/rpc/Context.h>
4#include <xrpld/rpc/detail/RPCHelpers.h>
5#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
6#include <xrpld/rpc/detail/Tuning.h>
8#include <xrpl/basics/base_uint.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/ledger/ReadView.h>
11#include <xrpl/ledger/helpers/DirectoryHelpers.h>
12#include <xrpl/protocol/AccountID.h>
13#include <xrpl/protocol/ErrorCodes.h>
14#include <xrpl/protocol/Indexes.h>
15#include <xrpl/protocol/Keylet.h>
16#include <xrpl/protocol/LedgerFormats.h>
17#include <xrpl/protocol/SField.h>
18#include <xrpl/protocol/STLedgerEntry.h>
19#include <xrpl/protocol/jss.h>
20#include <xrpl/resource/Fees.h>
22#include <rpcspec/Errors.hpp>
23#include <rpcspec/handlers/nft_offers_common/Types.hpp>
31static_assert(::rpc::spec::handlers::nft_offers_common::kLimitMin ==
tuning::kNftOffers.rmin);
33 ::rpc::spec::handlers::nft_offers_common::kLimitDefault ==
tuning::kNftOffers.rDefault);
34static_assert(::rpc::spec::handlers::nft_offers_common::kLimitMax ==
tuning::kNftOffers.rmax);
39appendNftOfferJson(
SLE const& offer, json::Value& offers)
44 obj[jss::flags] =
offer[sfFlags];
47 if (
offer.isFieldPresent(sfDestination))
48 obj[jss::destination] =
toBase58(
offer.getAccountID(sfDestination));
50 if (
offer.isFieldPresent(sfExpiration))
51 obj[jss::expiration] =
offer.getFieldU32(sfExpiration);
53 offer.getFieldAmount(sfAmount).setJson(obj[jss::amount]);
62std::expected<NFTOffersHandlerBase::Output, ::rpc::Status>
69 if (
auto const status =
getLedger(ledger, input.ledger, context); status != ::rpc::Status::kOK)
76 output.
nftID = input.nftID;
78 unsigned int reserve(limit);
82 if (input.marker.has_value())
86 startAfter = *input.marker;
90 if (!sle || input.nftID != sle->getFieldH256(sfNFTokenID))
99 auto const offerDir = sle->isFlag(lsfSellNFToken) ?
keylet::nftSells(input.nftID)
104 startHint = sle->getFieldU64(sfNFTokenOfferNode);
105 output.
offers.reserve(reserve + 1);
106 output.
offers.emplace_back(sle);
111 output.
offers.reserve(++reserve);
114 auto const resumed = output.
offers.size();
117 if (offer->getType() == ltNFTOKEN_OFFER)
119 output.
offers.emplace_back(offer);
129 if (output.
offers.size() - resumed == reserve)
131 output.
limit = limit;
146 for (
auto const& offer : output.
offers)
147 appendNftOfferJson(*offer, offers);
149 if (output.
marker.has_value())
151 value[jss::limit] = output.
limit;
Value & append(Value const &value)
Append value to array at the end.
std::shared_ptr< STLedgerEntry const > const & ConstRef
NFTOffersHandlerBase(JsonContext &context)
Construct a handler for a single request.
std::reference_wrapper< JsonContext > context_
std::expected< Output, ::rpc::Status > enumerateOffers(Input const &input, Keylet const &directory) const
Enumerate one page of an NFT offer directory.
static void writeResult(json::Value &value, Output const &output)
Write the output of process() into the response.
@ Array
array value (ordered list)
@ Object
object value (collection of name/value pairs).
Keylet nftokenOffer(AccountID const &owner, SeqProxy const &seq)
An offer from an account to buy or sell an NFT.
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Keylet nftSells(UInt256 const &id) noexcept
The directory of sell offers for the specified NFT.
Keylet nftBuys(UInt256 const &id) noexcept
The directory of buy offers for the specified NFT.
Charge const kFeeMediumBurdenRpc
static constexpr LimitRange kNftOffers
Limits for the nft_buy_offers & nft_sell_offers commands.
The api_version numbers this server serves.
unsigned int clampLimit(unsigned int limit, tuning::LimitRange const &range, Role const &role)
Clamps a requested limit to the range a role may use.
::rpc::Status getLedger(T &ledger, UInt256 const &ledgerHash, Context const &context)
Retrieves a ledger by its hash.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string to_string(BaseUInt< Bits, Tag > const &a)
bool forEachItemAfter(ReadView const &view, Keylet const &root, UInt256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(SLE::ConstRef)> const &f)
Iterate all items after an item in the given directory.
A pair of SHAMap key and LedgerEntryType.
The data an NFT offers request produces, written out by writeResult().
UInt256 nftID
The NFT whose offers are listed.
std::vector< SLE::const_pointer > offers
The offers on this page.
std::optional< UInt256 > marker
Where the next page starts, if there is one.
std::uint32_t limit
The limit used; written only with a marker.