rippled
Loading...
Searching...
No Matches
BookTip.cpp
1#include <xrpld/app/tx/detail/BookTip.h>
2
3namespace xrpl {
4
5BookTip::BookTip(ApplyView& view, Book const& book)
6 : view_(view), m_valid(false), m_book(getBookBase(book)), m_end(getQualityNext(m_book))
7{
8}
9
10bool
12{
13 if (m_valid)
14 {
15 if (m_entry)
16 {
18 m_entry = nullptr;
19 }
20 }
21
22 for (;;)
23 {
24 // See if there's an entry at or worse than current quality. Notice
25 // that the quality is encoded only in the index of the first page
26 // of a directory.
27 auto const first_page = view_.succ(m_book, m_end);
28
29 if (!first_page)
30 return false;
31
32 unsigned int di = 0;
34
35 if (dirFirst(view_, *first_page, dir, di, m_index))
36 {
37 m_dir = dir->key();
39 m_quality = Quality(getQuality(*first_page));
40 m_valid = true;
41
42 // Next query should start before this directory
43 m_book = *first_page;
44
45 // The quality immediately before the next quality
46 --m_book;
47
48 break;
49 }
50
51 // There should never be an empty directory but just in case,
52 // we handle that case by advancing to the next directory.
53 m_book = *first_page;
54 }
55
56 return true;
57}
58
59} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:41
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:115
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:5
uint256 m_dir
Definition BookTip.h:23
bool step(beast::Journal j)
Erases the current offer and advance to the next offer.
Definition BookTip.cpp:11
ApplyView & view_
Definition BookTip.h:19
uint256 const & dir() const noexcept
Definition BookTip.h:33
uint256 m_index
Definition BookTip.h:24
std::shared_ptr< SLE > m_entry
Definition BookTip.h:25
bool m_valid
Definition BookTip.h:20
uint256 m_book
Definition BookTip.h:21
Quality m_quality
Definition BookTip.h:26
uint256 m_end
Definition BookTip.h:22
Specifies an order book.
Definition Book.h:17
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:235
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition View.cpp:89
std::uint64_t getQuality(uint256 const &uBase)
Definition Indexes.cpp:126
uint256 getQualityNext(uint256 const &uBase)
Definition Indexes.cpp:119
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.
Definition View.cpp:1672