1#include <test/jtx/directory.h>
3#include <test/jtx/Env.h>
5#include <xrpl/basics/base_uint.h>
6#include <xrpl/beast/utility/Journal.h>
7#include <xrpl/core/ServiceRegistry.h>
8#include <xrpl/ledger/ApplyView.h>
9#include <xrpl/ledger/OpenView.h>
10#include <xrpl/ledger/Sandbox.h>
11#include <xrpl/protocol/Indexes.h>
12#include <xrpl/protocol/Keylet.h>
13#include <xrpl/protocol/LedgerFormats.h>
14#include <xrpl/protocol/SField.h>
31 std::expected<void, Error> res{};
44 auto const lastIndex = sleRoot->getFieldU64(sfIndexPrevious);
57 if (lastIndex >= newLastPage)
71 auto indexes = slePage->getFieldV256(sfIndexes);
72 auto prevIndex = slePage->at(~sfIndexPrevious);
73 auto owner = slePage->at(~sfOwner);
78 sleNew->setFieldH256(sfRootIndex,
directory.key);
79 sleNew->setFieldV256(sfIndexes, indexes);
81 sleNew->setAccountID(sfOwner, *owner);
83 sleNew->setFieldU64(sfIndexPrevious, *prevIndex);
87 sleRoot->setFieldU64(sfIndexPrevious, newLastPage);
88 if (prevIndex.valueOr(0) == 0)
90 sleRoot->setFieldU64(sfIndexNext, newLastPage);
100 slePrev->setFieldU64(sfIndexNext, newLastPage);
108 for (
auto const key : indexes)
110 if (!adjust(sb, key, newLastPage))
129 if (sle && sle->isFieldPresent(sfOwnerNode))
131 sle->setFieldU64(sfOwnerNode, page);
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
bool modify(modify_type const &f)
Modify the open ledger.
Writable ledger view that accumulates state and tx changes.
Discardable, editable view to a ledger.
virtual OpenLedger & getOpenLedger()=0
void insert(SLE::ref sle) override
Insert a new state SLE.
SLE::pointer peek(Keylet const &k) override
Prepare to modify the SLE associated with key.
void update(SLE::ref sle) override
Indicate changes to a peeked SLE.
void erase(SLE::ref sle) override
Remove a peeked SLE.
bool exists(Keylet const &k) const override
Determine if a state item exists.
A transaction testing environment.
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
auto bumpLastPage(Env &env, std::uint64_t newLastPage, Keylet directory, std::function< bool(ApplyView &, uint256, std::uint64_t)> adjust) -> std::expected< void, Error >
Move the position of the last page in the user's directory on open ledger to newLastPage.
bool adjustOwnerNode(ApplyView &view, uint256 key, std::uint64_t page)
Implementation of adjust for the most common ledger entry, i.e.
@ ltANY
A special type, matching any ledger entry type.
A pair of SHAMap key and LedgerEntryType.