xrpld
Loading...
Searching...
No Matches
OfferHelpers.cpp
1#include <xrpl/ledger/helpers/OfferHelpers.h>
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/helpers/AccountRootHelpers.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerFormats.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STArray.h> // IWYU pragma: keep
12#include <xrpl/protocol/STLedgerEntry.h>
13#include <xrpl/protocol/TER.h>
14
15namespace xrpl {
16
17TER
19{
20 if (!sle)
21 return tesSUCCESS;
22 auto offerIndex = sle->key();
23 auto owner = sle->getAccountID(sfAccount);
24
25 // Detect legacy directories.
26 uint256 const uDirectory = sle->getFieldH256(sfBookDirectory);
27
28 if (!view.dirRemove(keylet::ownerDir(owner), sle->getFieldU64(sfOwnerNode), offerIndex, false))
29 {
30 return tefBAD_LEDGER; // LCOV_EXCL_LINE
31 }
32
33 if (!view.dirRemove(keylet::page(uDirectory), sle->getFieldU64(sfBookNode), offerIndex, false))
34 {
35 return tefBAD_LEDGER; // LCOV_EXCL_LINE
36 }
37
38 if (sle->isFieldPresent(sfAdditionalBooks))
39 {
40 XRPL_ASSERT(
41 sle->isFlag(lsfHybrid) && sle->isFieldPresent(sfDomainID),
42 "xrpl::offerDelete : should be a hybrid domain offer");
43
44 auto const& additionalBookDirs = sle->getFieldArray(sfAdditionalBooks);
45
46 for (auto const& bookDir : additionalBookDirs)
47 {
48 auto const& dirIndex = bookDir.getFieldH256(sfBookDirectory);
49 auto const& dirNode = bookDir.getFieldU64(sfBookNode);
50
51 if (!view.dirRemove(keylet::page(dirIndex), dirNode, offerIndex, false))
52 {
53 return tefBAD_LEDGER; // LCOV_EXCL_LINE
54 }
55 }
56 }
57
58 adjustOwnerCount(view, view.peek(keylet::account(owner)), -1, j);
59
60 view.erase(sle);
61
62 return tesSUCCESS;
63}
64
65} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:118
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void erase(SLE::ref sle)=0
Remove a peeked SLE.
std::shared_ptr< STLedgerEntry > const & ref
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:357
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
Keylet page(uint256 const &root, std::uint64_t index=0) noexcept
A page in a directory.
Definition Indexes.cpp:363
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefBAD_LEDGER
Definition TER.h:160
TER offerDelete(ApplyView &view, SLE::ref sle, beast::Journal j)
Delete an offer.
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TERSubset< CanCvtToTER > TER
Definition TER.h:634
BaseUInt< 256 > uint256
Definition base_uint.h:562
@ tesSUCCESS
Definition TER.h:240