1#include <xrpld/rpc/handlers/account/AccountNFTs.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/protocol/AccountID.h>
12#include <xrpl/protocol/ErrorCodes.h>
13#include <xrpl/protocol/Indexes.h>
14#include <xrpl/protocol/LedgerFormats.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STArray.h>
17#include <xrpl/protocol/jss.h>
18#include <xrpl/protocol/nft.h>
19#include <xrpl/protocol/nftPageMask.h>
20#include <xrpl/resource/Fees.h>
22#include <rpcspec/Errors.hpp>
23#include <rpcspec/handlers/account_nfts/Types.hpp>
39std::expected<AccountNFTsHandler::Output, ::rpc::Status>
45 if (
auto const status =
getLedger(output.
ledger, input.ledger, context);
46 status != ::rpc::Status::kOK)
48 auto const& ledger = *output.
ledger;
49 auto const accountID = input.account;
58 bool const markerSet = input.marker.has_value();
64 auto cp = ledger.read(
65 Keylet(ltNFTOKEN_PAGE, ledger.succ(first.key, last.key.next()).value_or(last.key)));
70 bool pastMarker = marker.
isZero();
71 bool markerFound =
false;
75 auto const& pageNftokens = cp->getFieldArray(sfNFTokens);
77 for (
auto const& nftoken : pageNftokens)
90 UInt256 const nftokenID = nftoken[sfNFTokenID];
95 if (maskedNftokenID < maskedMarker)
98 if (maskedNftokenID == maskedMarker && nftokenID < marker)
101 if (nftokenID == marker)
108 if (markerSet && !markerFound)
115 if (++cnt == output.
limit)
117 output.
marker = nftokenID;
122 if (
auto const npm = (*cp)[~sfNextPageMin]; npm.has_value())
124 cp = ledger.read(
Keylet(ltNFTOKEN_PAGE, *npm));
132 if (markerSet && !markerFound)
145 for (
auto const& nftoken : output.
nfts)
150 UInt256 const nftokenID = nftoken[sfNFTokenID];
156 obj[sfTransferFee.jsonName] = xferFee;
159 if (output.
marker.has_value())
161 value[jss::limit] = output.
limit;
Value & append(Value const &value)
Append value to array at the end.
AccountNFTsHandler(JsonContext &context)
Construct a handler for a single request.
std::expected< Output, ::rpc::Status > process(Input const &input) const
Process the request.
void writeResult(json::Value &value, Output const &output) const
Write the output of process() into the response.
std::reference_wrapper< JsonContext > context_
@ Array
array value (ordered list)
Keylet nftokenPage(Keylet const &k, UInt256 const &token)
Keylet nftokenPageMin(AccountID const &owner)
NFT page keylets.
Keylet nftokenPageMax(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet account(AccountID const &id) noexcept
AccountID root.
std::uint32_t toUInt32(Taxon t)
std::uint32_t getSequence(UInt256 const &id)
std::uint16_t getFlags(UInt256 const &id)
AccountID getIssuer(UInt256 const &id)
std::uint16_t getTransferFee(UInt256 const &id)
constexpr UInt256 kPageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
Taxon getTaxon(UInt256 const &id)
Charge const kFeeMediumBurdenRpc
static constexpr LimitRange kAccountNfTokens
Limits for the account_nftokens command, in pages.
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.
std::string invalidFieldMessage(std::string const &name)
::rpc::Status getLedger(T &ledger, UInt256 const &ledgerHash, Context const &context)
Retrieves a ledger by its hash.
void injectLedgerFields(ReadView const &ledger, Context const &context, json::Value &result)
Writes the fields that identify a ledger into a result.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
std::string to_string(BaseUInt< Bits, Tag > const &a)
A pair of SHAMap key and LedgerEntryType.
The data an account_nfts request produces, written out by writeResult().
std::shared_ptr< ReadView const > ledger
The ledger the request selected.
std::uint32_t limit
The limit used; written only with a marker.
AccountID account
The account; written only on the last page.
std::vector< STObject > nfts
The NFTs on this page.
std::optional< uint256 > marker
Where the next page starts, if there is one.