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(
78 ledger->succ(first.key, last.key.next()).value_or(last.key)));
84 bool pastMarker = marker.
isZero();
85 bool markerFound =
false;
89 auto arr = cp->getFieldArray(sfNFTokens);
91 for (
auto const& o : arr)
104 uint256 const nftokenID = o[sfNFTokenID];
109 if (maskedNftokenID < maskedMarker)
112 if (maskedNftokenID == maskedMarker && nftokenID < marker)
115 if (nftokenID == marker)
122 if (markerSet && !markerFound)
133 obj[sfNFTokenTaxon.jsonName] =
137 obj[sfTransferFee.jsonName] = xferFee;
142 result[jss::limit] = limit;
143 result[jss::marker] =
to_string(o.getFieldH256(sfNFTokenID));
148 if (
auto npm = (*cp)[~sfNextPageMin])
149 cp = ledger->read(
Keylet(ltNFTOKEN_PAGE, *npm));
154 if (markerSet && !markerFound)
157 result[jss::account] =
toBase58(accountID);
173 if (!dirIndex.
isZero() && !ledger.
read({ltDIR_NODE, dirIndex}))
179 return it != typeFilter.
end();
184 bool iterateNFTPages =
185 (!typeFilter.has_value() ||
186 typeMatchesFilter(typeFilter.value(), ltNFTOKEN_PAGE)) &&
187 dirIndex == beast::zero;
192 if (iterateNFTPages && entryIndex != beast::zero)
198 iterateNFTPages =
false;
205 uint32_t mlimit = limit;
210 Keylet const first = entryIndex == beast::zero
212 :
Keylet{ltNFTOKEN_PAGE, entryIndex};
220 auto cp = ledger.
read(
Keylet{ltNFTOKEN_PAGE, ck});
225 auto const npm = (*cp)[~sfNextPageMin];
227 cp = ledger.
read(
Keylet(ltNFTOKEN_PAGE, *npm));
235 jvResult[jss::limit] = limit;
251 entryIndex = beast::zero;
263 auto dir = ledger.
read({ltDIR_NODE, dirIndex});
284 auto const& entries = dir->getFieldV256(sfIndexes);
285 auto iter = entries.begin();
289 iter =
std::find(iter, entries.end(), entryIndex);
290 if (iter == entries.end())
298 if (i == mlimit && mlimit < limit)
300 jvResult[jss::limit] = limit;
301 jvResult[jss::marker] =
306 for (; iter != entries.end(); ++iter)
310 if (!typeFilter.has_value() ||
311 typeMatchesFilter(typeFilter.value(), sleNode->getType()))
318 if (++iter != entries.end())
320 jvResult[jss::limit] = limit;
321 jvResult[jss::marker] =
330 auto const nodeIndex = dir->getFieldU64(sfIndexNext);
335 dir = ledger.
read({ltDIR_NODE, dirIndex});
341 auto const& e = dir->getFieldV256(sfIndexes);
344 jvResult[jss::limit] = limit;
345 jvResult[jss::marker] =
357 auto const& params = context.
params;
358 if (!params.isMember(jss::account))
361 if (!params[jss::account].isString())
366 if (ledger ==
nullptr)
369 auto const id = parseBase58<AccountID>(params[jss::account].asString());
375 auto const accountID{
id.value()};
382 if (params.isMember(jss::deletion_blockers_only) &&
383 params[jss::deletion_blockers_only].asBool())
389 }
static constexpr deletionBlockers[] = {
390 {jss::check, ltCHECK},
391 {jss::escrow, ltESCROW},
392 {jss::nft_page, ltNFTOKEN_PAGE},
393 {jss::payment_channel, ltPAYCHAN},
394 {jss::state, ltRIPPLE_STATE},
395 {jss::xchain_owned_claim_id, ltXCHAIN_OWNED_CLAIM_ID},
396 {jss::xchain_owned_create_account_claim_id,
397 ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID},
398 {jss::bridge, ltBRIDGE},
399 {jss::mpt_issuance, ltMPTOKEN_ISSUANCE},
400 {jss::mptoken, ltMPTOKEN},
401 {jss::permissioned_domain, ltPERMISSIONED_DOMAIN},
402 {jss::vault, ltVAULT},
406 typeFilter->reserve(
std::size(deletionBlockers));
408 for (
auto [name, type] : deletionBlockers)
410 if (params.isMember(jss::type) && name != params[jss::type])
415 typeFilter->push_back(type);
428 rpcStatus.inject(result);
431 else if (type !=
ltANY)
443 if (params.isMember(jss::marker))
445 auto const& marker = params[jss::marker];
446 if (!marker.isString())
449 auto const& markerStr = marker.asString();
450 auto const& idx = markerStr.find(
',');
451 if (idx == std::string::npos)
454 if (!dirIndex.
parseHex(markerStr.substr(0, idx)))
457 if (!entryIndex.
parseHex(markerStr.substr(idx + 1)))
471 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::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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.
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)
bool isAccountObjectsValidType(LedgerEntryType const &type)
Check if the type is a valid filtering type for account_objects method.
void inject_error(error_code_i code, JsonValue &json)
Add or update the json update to reflect the error code.
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(Json::Value const ¶ms)
Json::Value expected_field_error(std::string const &name, std::string const &type)
Status lookupLedger(std::shared_ptr< ReadView const > &ledger, JsonContext &context, Json::Value &result)
Look up a ledger from a request and fill a Json::Result with the data representing a ledger.
Json::Value missing_field_error(std::string const &name)
Charge const feeMediumBurdenRPC
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet nftpage(Keylet const &k, uint256 const &token)
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Keylet nftpage_min(AccountID const &owner)
NFT page keylets.
Keylet nftpage_max(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
std::uint16_t getTransferFee(uint256 const &id)
std::uint16_t getFlags(uint256 const &id)
std::uint32_t toUInt32(Taxon t)
Taxon getTaxon(uint256 const &id)
AccountID getIssuer(uint256 const &id)
std::uint32_t getSerial(uint256 const &id)
uint256 constexpr pageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Json::Value rpcError(int iError)
Json::Value doAccountObjects(RPC::JsonContext &context)
Json::Value doAccountNFTs(RPC::JsonContext &context)
General RPC command that can retrieve objects in the account root.
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)
std::string to_string(base_uint< Bits, Tag > const &a)
LedgerEntryType
Identifiers for on-ledger objects.
@ ltANY
A special type, matching any ledger entry type.
Number root(Number f, unsigned d)
A pair of SHAMap key and LedgerEntryType.
Resource::Charge & loadType