1#include <xrpl/ledger/helpers/DirectoryHelpers.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/ledger/ApplyView.h>
6#include <xrpl/ledger/ReadView.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Keylet.h>
10#include <xrpl/protocol/LedgerFormats.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STLedgerEntry.h>
65 XRPL_ASSERT(
root.type == ltDIR_NODE,
"xrpl::forEachItem : valid root type");
67 if (
root.type != ltDIR_NODE)
74 auto sle = view.
read(pos);
77 for (
auto const& key : sle->getFieldV256(sfIndexes))
79 auto const next = sle->getFieldU64(sfIndexNext);
95 XRPL_ASSERT(
root.type == ltDIR_NODE,
"xrpl::forEachItemAfter : valid root type");
97 if (
root.type != ltDIR_NODE)
100 auto currentIndex =
root;
103 if (
after.isNonZero())
107 if (
auto hintDir = view.
read(hintIndex))
109 for (
auto const& key : hintDir->getFieldV256(sfIndexes))
114 currentIndex = hintIndex;
123 auto const ownerDir = view.
read(currentIndex);
126 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
139 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
149 auto const ownerDir = view.
read(currentIndex);
152 for (
auto const& key : ownerDir->getFieldV256(sfIndexes))
157 auto const uNodeNext = ownerDir->getFieldU64(sfIndexNext);
168 auto const sleNode = view.
read(k);
171 if (!sleNode->getFieldV256(sfIndexes).empty())
176 return sleNode->getFieldU64(sfIndexNext) == 0;
182 return [account](
SLE::ref sle) { (*sle)[sfOwner] = account; };
Writeable view to a ledger, for applying a transaction.
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry > const & ref
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & const_ref
std::shared_ptr< STLedgerEntry const > const_pointer
bool internalDirFirst(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
bool internalDirNext(V &view, uint256 const &root, std::shared_ptr< N > &page, unsigned int &index, uint256 &entry)
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
Number root(Number f, unsigned d)
bool dirNext(ApplyView &view, uint256 const &root, SLE::pointer &page, unsigned int &index, uint256 &entry)
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
bool cdirNext(ReadView const &view, uint256 const &root, SLE::const_pointer &page, unsigned int &index, uint256 &entry)
Returns the next entry in the directory, advancing the index.
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(SLE::const_ref)> const &f)
Iterate all items in the given directory.
bool cdirFirst(ReadView const &view, uint256 const &root, SLE::const_pointer &page, unsigned int &index, uint256 &entry)
Returns the first entry in the directory, advancing the index.
bool forEachItemAfter(ReadView const &view, Keylet const &root, uint256 const &after, std::uint64_t const hint, unsigned int limit, std::function< bool(SLE::const_ref)> const &f)
Iterate all items after an item in the given directory.
bool dirFirst(ApplyView &view, uint256 const &root, SLE::pointer &page, unsigned int &index, uint256 &entry)
A pair of SHAMap key and LedgerEntryType.