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/basics/base_uint.h>
7#include <xrpl/beast/utility/Zero.h>
8#include <xrpl/json/json_value.h>
9#include <xrpl/ledger/ReadView.h>
10#include <xrpl/protocol/AccountID.h>
11#include <xrpl/protocol/ErrorCodes.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/LedgerFormats.h>
14#include <xrpl/protocol/RPCErr.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/jss.h>
17#include <xrpl/protocol/nftPageMask.h>
18#include <xrpl/resource/Fees.h>
49 if (!dirIndex.
isZero() && !ledger.
read({ltDIR_NODE, dirIndex}))
55 return it != typeFilter.
end();
60 bool iterateNFTPages =
61 (!typeFilter.has_value() || typeMatchesFilter(typeFilter.value(), ltNFTOKEN_PAGE)) &&
67 if (iterateNFTPages && entryIndex.
isNonZero())
73 iterateNFTPages =
false;
80 uint32_t limitLeft = limit;
86 entryIndex.
isZero() ? firstNFTPage :
Keylet{ltNFTOKEN_PAGE, entryIndex};
92 auto currentPage = ledger.
read(
Keylet{ltNFTOKEN_PAGE, currentKey});
97 auto const npm = (*currentPage)[~sfNextPageMin];
100 currentPage = ledger.
read(
Keylet(ltNFTOKEN_PAGE, *npm));
104 currentPage =
nullptr;
107 if (--limitLeft == 0 && currentPage)
109 jvResult[jss::limit] = limit;
124 entryIndex = beast::kZero;
128 auto startEntryFound =
false;
133 startEntryFound =
true;
136 auto dir = ledger.
read({ltDIR_NODE, dirIndex});
142 if (limitLeft >= limit)
157 auto const& dirEntries = dir->getFieldV256(sfIndexes);
158 auto entryIter = dirEntries.begin();
160 if (!startEntryFound)
162 entryIter =
std::find(entryIter, dirEntries.end(), entryIndex);
163 if (entryIter == dirEntries.end())
166 startEntryFound =
true;
171 if (itemsAdded == limitLeft && limitLeft < limit && entryIter != dirEntries.end())
173 jvResult[jss::limit] = limit;
178 for (; entryIter != dirEntries.end(); ++entryIter)
182 if (!typeFilter.has_value() ||
183 typeMatchesFilter(typeFilter.value(), sleNode->getType()))
188 if (++itemsAdded == limitLeft)
190 if (++entryIter != dirEntries.end())
192 jvResult[jss::limit] = limit;
201 auto const nodeIndex = dir->getFieldU64(sfIndexNext);
206 dir = ledger.
read({ltDIR_NODE, dirIndex});
210 if (itemsAdded == limitLeft)
212 auto const& currentDirEntries = dir->getFieldV256(sfIndexes);
213 if (!currentDirEntries.empty())
215 jvResult[jss::limit] = limit;
216 jvResult[jss::marker] =
228 auto const& params = context.
params;
229 if (!params.isMember(jss::account))
232 if (!params[jss::account].isString())
237 if (ledger ==
nullptr)
246 auto const accountID{
id.value()};
253 if (params.isMember(jss::deletion_blockers_only) &&
254 params[jss::deletion_blockers_only].asBool())
260 }
static constexpr kDeletionBlockers[] = {
261 {.name = jss::check, .type = ltCHECK},
262 {.name = jss::escrow, .type = ltESCROW},
263 {.name = jss::nft_page, .type = ltNFTOKEN_PAGE},
264 {.name = jss::payment_channel, .type = ltPAYCHAN},
265 {.name = jss::state, .type = ltRIPPLE_STATE},
266 {.name = jss::xchain_owned_claim_id, .type = ltXCHAIN_OWNED_CLAIM_ID},
267 {.name = jss::xchain_owned_create_account_claim_id,
268 .type = ltXCHAIN_OWNED_CREATE_ACCOUNT_CLAIM_ID},
269 {.name = jss::bridge, .type = ltBRIDGE},
270 {.name = jss::mpt_issuance, .type = ltMPTOKEN_ISSUANCE},
271 {.name = jss::mptoken, .type = ltMPTOKEN},
272 {.name = jss::permissioned_domain, .type = ltPERMISSIONED_DOMAIN},
273 {.name = jss::vault, .type = ltVAULT},
277 typeFilter->reserve(
std::size(kDeletionBlockers));
279 for (
auto [name, type] : kDeletionBlockers)
281 if (params.isMember(jss::type) && name != params[jss::type])
286 typeFilter->push_back(type);
299 rpcStatus.inject(result);
308 unsigned int limit = 0;
314 if (params.isMember(jss::marker))
316 auto const& marker = params[jss::marker];
317 if (!marker.isString())
320 auto const& markerStr = marker.asString();
321 auto const& idx = markerStr.find(
',');
322 if (idx == std::string::npos)
325 if (!dirIndex.
parseHex(markerStr.substr(0, idx)))
328 if (!entryIndex.
parseHex(markerStr.substr(idx + 1)))
332 if (!
getAccountObjects(*ledger, accountID, typeFilter, dirIndex, entryIndex, limit, result))
335 result[jss::account] =
toBase58(accountID);
Lightweight wrapper to tag static string.
constexpr bool parseHex(std::string_view sv)
Parse a hex string into a base_uint.
virtual SLE::const_pointer 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.
@ Array
array value (ordered list)
static constexpr LimitRange kAccountObjects
Limits for the account_objects command.
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.
bool isAccountObjectsValidType(LedgerEntryType const &type)
Checks if the type is a valid filtering type for the account_objects method.
void injectError(ErrorCodeI code, json::Value &json)
Add or update the json update to reflect the error code.
json::Value invalidFieldError(std::string const &name)
json::Value missingFieldError(std::string const &name)
std::pair< RPC::Status, LedgerEntryType > chooseLedgerEntryType(json::Value const ¶ms)
Chooses the ledger entry type based on RPC parameters.
json::Value expectedFieldError(std::string const &name, std::string const &type)
Charge const kFeeMediumBurdenRpc
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet nftokenPageMin(AccountID const &owner)
NFT page keylets.
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet nftokenPageMax(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
constexpr uint256 kPageMask(std::string_view("0000000000000000000000000000000000000000ffffffffffffffffffffffff"))
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Number root(Number f, unsigned d)
std::string to_string(BaseUInt< Bits, Tag > const &a)
json::Value rpcError(ErrorCodeI iError)
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.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
json::Value doAccountObjects(RPC::JsonContext &context)
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