xrpld
Loading...
Searching...
No Matches
BookTip.cpp
1#include <xrpl/tx/paths/BookTip.h>
2
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/helpers/DirectoryHelpers.h>
6#include <xrpl/ledger/helpers/OfferHelpers.h>
7#include <xrpl/protocol/Book.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/STLedgerEntry.h>
10
11namespace xrpl {
12
13BookTip::BookTip(ApplyView& view, Book const& book)
15{
16}
17
18bool
20{
21 if (valid_)
22 {
23 if (entry_)
24 {
26 entry_ = nullptr;
27 }
28 }
29
30 for (;;)
31 {
32 // See if there's an entry at or worse than current quality. Notice
33 // that the quality is encoded only in the index of the first page
34 // of a directory.
35 auto const firstPage = view_.succ(book_, end_);
36
37 if (!firstPage)
38 return false;
39
40 unsigned int di = 0;
42
43 if (dirFirst(view_, *firstPage, dir, di, index_))
44 {
45 dir_ = dir->key();
47 quality_ = Quality(getQuality(*firstPage));
48 valid_ = true;
49
50 // Next query should start before this directory
51 book_ = *firstPage;
52
53 // The quality immediately before the next quality
54 --book_;
55
56 break;
57 }
58
59 // There should never be an empty directory but just in case,
60 // we handle that case by advancing to the next directory.
61 book_ = *firstPage;
62 }
63
64 return true;
65}
66
67} // 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
uint256 end_
Definition BookTip.h:21
BookTip(ApplyView &view, Book const &book)
Create the iterator.
Definition BookTip.cpp:13
uint256 book_
Definition BookTip.h:20
bool step(beast::Journal j)
Erases the current offer and advance to the next offer.
Definition BookTip.cpp:19
uint256 dir_
Definition BookTip.h:22
ApplyView & view_
Definition BookTip.h:18
uint256 const & dir() const noexcept
Definition BookTip.h:32
SLE::pointer entry_
Definition BookTip.h:24
bool valid_
Definition BookTip.h:19
Quality quality_
Definition BookTip.h:25
uint256 index_
Definition BookTip.h:23
Specifies an order book.
Definition Book.h:16
Represents the logical ratio of output currency to input currency.
Definition Quality.h:91
std::shared_ptr< STLedgerEntry > pointer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:264
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::uint64_t getQuality(uint256 const &uBase)
Definition Indexes.cpp:152
TER offerDelete(ApplyView &view, SLE::ref sle, beast::Journal j)
Delete an offer.
uint256 getQualityNext(uint256 const &uBase)
Definition Indexes.cpp:144
uint256 getBookBase(Book const &book)
Definition Indexes.cpp:102
bool dirFirst(ApplyView &view, uint256 const &root, SLE::pointer &page, unsigned int &index, uint256 &entry)