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