rippled
Loading...
Searching...
No Matches
BookTip.cpp
1#include <xrpl/ledger/helpers/DirectoryHelpers.h>
2#include <xrpl/ledger/helpers/OfferHelpers.h>
3#include <xrpl/tx/paths/BookTip.h>
4
5namespace xrpl {
6
7BookTip::BookTip(ApplyView& view, Book const& book)
8 : view_(view), m_book(getBookBase(book)), m_end(getQualityNext(m_book))
9{
10}
11
12bool
14{
15 if (m_valid)
16 {
17 if (m_entry)
18 {
20 m_entry = nullptr;
21 }
22 }
23
24 for (;;)
25 {
26 // See if there's an entry at or worse than current quality. Notice
27 // that the quality is encoded only in the index of the first page
28 // of a directory.
29 auto const first_page = view_.succ(m_book, m_end);
30
31 if (!first_page)
32 return false;
33
34 unsigned int di = 0;
36
37 if (dirFirst(view_, *first_page, dir, di, m_index))
38 {
39 m_dir = dir->key();
41 m_quality = Quality(getQuality(*first_page));
42 m_valid = true;
43
44 // Next query should start before this directory
45 m_book = *first_page;
46
47 // The quality immediately before the next quality
48 --m_book;
49
50 break;
51 }
52
53 // There should never be an empty directory but just in case,
54 // we handle that case by advancing to the next directory.
55 m_book = *first_page;
56 }
57
58 return true;
59}
60
61} // 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
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
BookTip(ApplyView &view, Book const &book)
Create the iterator.
Definition BookTip.cpp:7
uint256 m_dir
Definition BookTip.h:22
bool step(beast::Journal j)
Erases the current offer and advance to the next offer.
Definition BookTip.cpp:13
ApplyView & view_
Definition BookTip.h:18
uint256 const & dir() const noexcept
Definition BookTip.h:32
uint256 m_index
Definition BookTip.h:23
std::shared_ptr< SLE > m_entry
Definition BookTip.h:24
bool m_valid
Definition BookTip.h:19
uint256 m_book
Definition BookTip.h:20
Quality m_quality
Definition BookTip.h:25
uint256 m_end
Definition BookTip.h:21
Specifies an order book.
Definition Book.h:16
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.
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:243
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
std::uint64_t getQuality(uint256 const &uBase)
Definition Indexes.cpp:131
uint256 getQualityNext(uint256 const &uBase)
Definition Indexes.cpp:123
uint256 getBookBase(Book const &book)
Definition Indexes.cpp:98
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.