rippled
Loading...
Searching...
No Matches
BookTip.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/tx/detail/BookTip.h>
21
22namespace ripple {
23
24BookTip::BookTip(ApplyView& view, Book const& book)
25 : view_(view)
26 , m_valid(false)
27 , m_book(getBookBase(book))
28 , m_end(getQualityNext(m_book))
29{
30}
31
32bool
34{
35 if (m_valid)
36 {
37 if (m_entry)
38 {
40 m_entry = nullptr;
41 }
42 }
43
44 for (;;)
45 {
46 // See if there's an entry at or worse than current quality. Notice
47 // that the quality is encoded only in the index of the first page
48 // of a directory.
49 auto const first_page = view_.succ(m_book, m_end);
50
51 if (!first_page)
52 return false;
53
54 unsigned int di = 0;
56
57 if (dirFirst(view_, *first_page, dir, di, m_index))
58 {
59 m_dir = dir->key();
61 m_quality = Quality(getQuality(*first_page));
62 m_valid = true;
63
64 // Next query should start before this directory
65 m_book = *first_page;
66
67 // The quality immediately before the next quality
68 --m_book;
69
70 break;
71 }
72
73 // There should never be an empty directory but just in case,
74 // we handle that case by advancing to the next directory.
75 m_book = *first_page;
76 }
77
78 return true;
79}
80
81} // namespace ripple
A generic endpoint for log messages.
Definition Journal.h:60
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:143
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
uint256 m_book
Definition BookTip.h:40
ApplyView & view_
Definition BookTip.h:38
BookTip(ApplyView &view, Book const &book)
Create the iterator.
Definition BookTip.cpp:24
uint256 m_index
Definition BookTip.h:43
bool step(beast::Journal j)
Erases the current offer and advance to the next offer.
Definition BookTip.cpp:33
uint256 m_end
Definition BookTip.h:41
uint256 const & dir() const noexcept
Definition BookTip.h:52
std::shared_ptr< SLE > m_entry
Definition BookTip.h:44
Quality m_quality
Definition BookTip.h:45
uint256 m_dir
Definition BookTip.h:42
Specifies an order book.
Definition Book.h:36
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:274
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
std::uint64_t getQuality(uint256 const &uBase)
Definition Indexes.cpp:149
bool dirFirst(ApplyView &view, uint256 const &root, std::shared_ptr< SLE > &page, unsigned int &index, uint256 &entry)
Definition View.cpp:123
uint256 getQualityNext(uint256 const &uBase)
Definition Indexes.cpp:141
uint256 getBookBase(Book const &book)
Definition Indexes.cpp:115
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition View.cpp:1634