1#include <xrpld/app/tx/detail/NFTokenUtils.h>
2#include <xrpld/rpc/Context.h>
3#include <xrpld/rpc/detail/RPCHelpers.h>
4#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
5#include <xrpld/rpc/detail/Tuning.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/LedgerFormats.h>
11#include <xrpl/protocol/RPCErr.h>
12#include <xrpl/protocol/jss.h>
13#include <xrpl/protocol/nftPageMask.h>
14#include <xrpl/resource/Fees.h>
34 auto const& params = context.
params;
35 if (!params.isMember(jss::account))
38 if (!params[jss::account].isString())
41 auto id = parseBase58<AccountID>(params[jss::account].asString());
49 if (ledger ==
nullptr)
51 auto const accountID{
id.value()};
61 bool const markerSet = params.isMember(jss::marker);
65 auto const& m = params[jss::marker];
76 auto cp = ledger->read(
Keylet(ltNFTOKEN_PAGE, ledger->succ(first.key, last.key.next()).value_or(last.key)));
82 bool pastMarker = marker.
isZero();
83 bool markerFound =
false;
87 auto arr = cp->getFieldArray(sfNFTokens);
89 for (
auto const& o : arr)
102 uint256 const nftokenID = o[sfNFTokenID];
107 if (maskedNftokenID < maskedMarker)
110 if (maskedNftokenID == maskedMarker && nftokenID < marker)
113 if (nftokenID == marker)
120 if (markerSet && !markerFound)
134 obj[sfTransferFee.jsonName] = xferFee;
139 result[jss::limit] = limit;
140 result[jss::marker] =
to_string(o.getFieldH256(sfNFTokenID));
145 if (
auto npm = (*cp)[~sfNextPageMin])
146 cp = ledger->read(
Keylet(ltNFTOKEN_PAGE, *npm));
151 if (markerSet && !markerFound)
154 result[jss::account] =
toBase58(accountID);
179 if (!dirIndex.
isZero() && !ledger.
read({ltDIR_NODE, dirIndex}))
184 return it != typeFilter.
end();
189 bool iterateNFTPages =
190 (!typeFilter.has_value() || typeMatchesFilter(typeFilter.value(), ltNFTOKEN_PAGE)) && dirIndex == beast::zero;
195 if (iterateNFTPages && entryIndex != beast::zero)
201 iterateNFTPages =
false;
208 uint32_t mlimit = limit;
213 Keylet const first = entryIndex == beast::zero ? firstNFTPage :
Keylet{ltNFTOKEN_PAGE, entryIndex};
221 auto cp = ledger.
read(
Keylet{ltNFTOKEN_PAGE, ck});
226 auto const npm = (*cp)[~sfNextPageMin];
228 cp = ledger.
read(
Keylet(ltNFTOKEN_PAGE, *npm));
236 jvResult[jss::limit] = limit;
252 entryIndex = beast::zero;
264 auto dir = ledger.
read({ltDIR_NODE, dirIndex});
285 auto const& entries = dir->getFieldV256(sfIndexes);
286 auto iter = entries.begin();
290 iter =
std::find(iter, entries.end(), entryIndex);
291 if (iter == entries.end())
299 if (i == mlimit && mlimit < limit)
301 jvResult[jss::limit] = limit;
306 for (; iter != entries.end(); ++iter)
310 if (!typeFilter.has_value() || typeMatchesFilter(typeFilter.value(), sleNode->getType()))
317 if (++iter != entries.end())
319 jvResult[jss::limit] = limit;
328 auto const nodeIndex = dir->getFieldU64(sfIndexNext);
333 dir = ledger.
read({ltDIR_NODE, dirIndex});
339 auto const& e = dir->getFieldV256(sfIndexes);
342 jvResult[jss::limit] = limit;
354 auto const& params = context.
params;
355 if (!params.isMember(jss::account))
358 if (!params[jss::account].isString())
363 if (ledger ==
nullptr)
366 auto const id = parseBase58<AccountID>(params[jss::account].asString());
372 auto const accountID{
id.value()};
379 if (params.isMember(jss::deletion_blockers_only) && params[jss::deletion_blockers_only].asBool())
385 }
static constexpr deletionBlockers[] = {
386 {jss::check, ltCHECK},
387 {jss::escrow, ltESCROW},
388 {jss::nft_page, ltNFTOKEN_PAGE},
389 {jss::payment_channel, ltPAYCHAN},
390 {jss::state, ltRIPPLE_STATE},
391 {jss::xchain_owned_claim_id, ltXCHAIN_OWNED_CLAIM_ID},
392 {jss::xchain_owned_create_account_claim_id, ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID},
393 {jss::bridge, ltBRIDGE},
394 {jss::mpt_issuance, ltMPTOKEN_ISSUANCE},
395 {jss::mptoken, ltMPTOKEN},
396 {jss::permissioned_domain, ltPERMISSIONED_DOMAIN},
397 {jss::vault, ltVAULT},
401 typeFilter->reserve(
std::size(deletionBlockers));
403 for (
auto [name, type] : deletionBlockers)
405 if (params.isMember(jss::type) && name != params[jss::type])
410 typeFilter->push_back(type);
423 rpcStatus.inject(result);
426 else if (type !=
ltANY)
438 if (params.isMember(jss::marker))
440 auto const& marker = params[jss::marker];
441 if (!marker.isString())
444 auto const& markerStr = marker.asString();
445 auto const& idx = markerStr.find(
',');
446 if (idx == std::string::npos)
449 if (!dirIndex.
parseHex(markerStr.substr(0, idx)))
452 if (!entryIndex.
parseHex(markerStr.substr(idx + 1)))
456 if (!
getAccountObjects(*ledger, accountID, typeFilter, dirIndex, entryIndex, limit, result))
459 result[jss::account] =
toBase58(accountID);
Lightweight wrapper to tag static string.
Value & append(Value const &value)
Append value to array at the end.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
@ arrayValue
array value (ordered list)
static LimitRange constexpr accountNFTokens
Limits for the account_nftokens command, in pages.
static LimitRange constexpr accountObjects
Limits for the account_objects command.
Json::Value invalid_field_error(std::string const &name)
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const ¶ms)
Chooses the ledger entry type based on RPC parameters.
bool isAccountObjectsValidType(LedgerEntryType const &type)
Checks if the type is a valid filtering type for the account_objects method.
Json::Value expected_field_error(std::string const &name, std::string const &type)
Json::Value missing_field_error(std::string const &name)
void inject_error(error_code_i code, Json::Value &json)
Add or update the json update to reflect the error code.
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext const &context, Json::Value &result)
Looks up a ledger from a request and fills a Json::Value with ledger data.
Charge const feeMediumBurdenRPC
Keylet nftpage_max(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet nftpage(Keylet const &k, uint256 const &token)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet nftpage_min(AccountID const &owner)
NFT page keylets.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
std::uint32_t toUInt32(Taxon t)
Taxon getTaxon(uint256 const &id)
uint256 constexpr pageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
AccountID getIssuer(uint256 const &id)
std::uint16_t getTransferFee(uint256 const &id)
std::uint32_t getSerial(uint256 const &id)
std::uint16_t getFlags(uint256 const &id)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Json::Value doAccountNFTs(RPC::JsonContext &context)
General RPC command that can retrieve objects in the account root.
Number root(Number f, unsigned d)
bool getAccountObjects(ReadView const &ledger, AccountID const &account, std::optional< std::vector< LedgerEntryType > > const &typeFilter, uint256 dirIndex, uint256 entryIndex, std::uint32_t const limit, Json::Value &jvResult)
Gathers all objects for an account in a ledger.
Json::Value doAccountObjects(RPC::JsonContext &context)
Json::Value rpcError(error_code_i iError)
LedgerEntryType
Identifiers for on-ledger objects.
@ ltANY
A special type, matching any ledger entry type.
A pair of SHAMap key and LedgerEntryType.
Resource::Charge & loadType