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