1#include <xrpld/rpc/Context.h>
2#include <xrpld/rpc/detail/RPCHelpers.h>
3#include <xrpld/rpc/detail/RPCLedgerHelpers.h>
4#include <xrpld/rpc/detail/Tuning.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/ErrorCodes.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerFormats.h>
10#include <xrpl/protocol/RPCErr.h>
11#include <xrpl/protocol/jss.h>
12#include <xrpl/protocol/nftPageMask.h>
13#include <xrpl/resource/Fees.h>
39 if (!dirIndex.
isZero() && !ledger.
read({ltDIR_NODE, dirIndex}))
45 return it != typeFilter.
end();
50 bool iterateNFTPages =
51 (!typeFilter.has_value() || typeMatchesFilter(typeFilter.value(), ltNFTOKEN_PAGE)) &&
52 dirIndex == beast::zero;
57 if (iterateNFTPages && entryIndex != beast::zero)
63 iterateNFTPages =
false;
70 uint32_t mlimit = limit;
76 entryIndex == beast::zero ? firstNFTPage :
Keylet{ltNFTOKEN_PAGE, entryIndex};
84 auto cp = ledger.
read(
Keylet{ltNFTOKEN_PAGE, ck});
89 auto const npm = (*cp)[~sfNextPageMin];
92 cp = ledger.
read(
Keylet(ltNFTOKEN_PAGE, *npm));
103 jvResult[jss::limit] = limit;
119 entryIndex = beast::zero;
131 auto dir = ledger.
read({ltDIR_NODE, dirIndex});
152 auto const& entries = dir->getFieldV256(sfIndexes);
153 auto iter = entries.begin();
157 iter =
std::find(iter, entries.end(), entryIndex);
158 if (iter == entries.end())
166 if (i == mlimit && mlimit < limit)
168 jvResult[jss::limit] = limit;
173 for (; iter != entries.end(); ++iter)
177 if (!typeFilter.has_value() ||
178 typeMatchesFilter(typeFilter.value(), sleNode->getType()))
185 if (++iter != entries.end())
187 jvResult[jss::limit] = limit;
196 auto const nodeIndex = dir->getFieldU64(sfIndexNext);
201 dir = ledger.
read({ltDIR_NODE, dirIndex});
207 auto const& e = dir->getFieldV256(sfIndexes);
210 jvResult[jss::limit] = limit;
222 auto const& params = context.
params;
223 if (!params.isMember(jss::account))
226 if (!params[jss::account].isString())
231 if (ledger ==
nullptr)
234 auto const id = parseBase58<AccountID>(params[jss::account].asString());
240 auto const accountID{
id.value()};
247 if (params.isMember(jss::deletion_blockers_only) &&
248 params[jss::deletion_blockers_only].asBool())
254 }
static constexpr deletionBlockers[] = {
255 {jss::check, ltCHECK},
256 {jss::escrow, ltESCROW},
257 {jss::nft_page, ltNFTOKEN_PAGE},
258 {jss::payment_channel, ltPAYCHAN},
259 {jss::state, ltRIPPLE_STATE},
260 {jss::xchain_owned_claim_id, ltXCHAIN_OWNED_CLAIM_ID},
261 {jss::xchain_owned_create_account_claim_id, ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID},
262 {jss::bridge, ltBRIDGE},
263 {jss::mpt_issuance, ltMPTOKEN_ISSUANCE},
264 {jss::mptoken, ltMPTOKEN},
265 {jss::permissioned_domain, ltPERMISSIONED_DOMAIN},
266 {jss::vault, ltVAULT},
270 typeFilter->reserve(
std::size(deletionBlockers));
272 for (
auto [name, type] : deletionBlockers)
274 if (params.isMember(jss::type) && name != params[jss::type])
279 typeFilter->push_back(type);
292 rpcStatus.inject(result);
301 unsigned int limit = 0;
307 if (params.isMember(jss::marker))
309 auto const& marker = params[jss::marker];
310 if (!marker.isString())
313 auto const& markerStr = marker.asString();
314 auto const& idx = markerStr.find(
',');
315 if (idx == std::string::npos)
318 if (!dirIndex.
parseHex(markerStr.substr(0, idx)))
321 if (!entryIndex.
parseHex(markerStr.substr(idx + 1)))
325 if (!
getAccountObjects(*ledger, accountID, typeFilter, dirIndex, entryIndex, limit, result))
328 result[jss::account] =
toBase58(accountID);
Lightweight wrapper to tag static string.
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 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 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.
uint256 constexpr pageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
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.
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