xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
tx
paths
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
11
namespace
xrpl
{
12
13
BookTip::BookTip
(
ApplyView
& view,
Book
const
& book)
14
:
view_
(view),
book_
(
getBookBase
(book)),
end_
(
getQualityNext
(
book_
))
15
{
16
}
17
18
bool
19
BookTip::step
(
beast::Journal
j)
20
{
21
if
(
valid_
)
22
{
23
if
(
entry_
)
24
{
25
offerDelete
(
view_
,
entry_
, j);
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;
41
SLE::pointer
dir
;
42
43
if
(
dirFirst
(
view_
, *firstPage,
dir
, di,
index_
))
44
{
45
dir_
=
dir
->key();
46
entry_
=
view_
.peek(
keylet::offer
(
index_
));
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
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
xrpl::ApplyView
Writeable view to a ledger, for applying a transaction.
Definition
ApplyView.h:141
xrpl::BookTip::BookTip
BookTip(ApplyView &view, Book const &book)
Create the iterator.
Definition
BookTip.cpp:13
xrpl::BookTip::step
bool step(beast::Journal j)
Erases the current offer and advance to the next offer.
Definition
BookTip.cpp:19
xrpl::BookTip::book_
UInt256 book_
Definition
BookTip.h:24
xrpl::BookTip::view_
ApplyView & view_
Definition
BookTip.h:22
xrpl::BookTip::dir
UInt256 const & dir() const noexcept
Definition
BookTip.h:38
xrpl::BookTip::entry_
SLE::pointer entry_
Definition
BookTip.h:28
xrpl::BookTip::valid_
bool valid_
Definition
BookTip.h:23
xrpl::BookTip::quality_
Quality quality_
Definition
BookTip.h:29
xrpl::BookTip::dir_
UInt256 dir_
Definition
BookTip.h:26
xrpl::BookTip::index_
UInt256 index_
Definition
BookTip.h:27
xrpl::BookTip::end_
UInt256 end_
Definition
BookTip.h:25
xrpl::Book
Specifies an order book.
Definition
Book.h:28
xrpl::Quality
Represents the logical ratio of output currency to input currency.
Definition
Quality.h:90
xrpl::STLedgerEntry::pointer
std::shared_ptr< STLedgerEntry > pointer
Definition
STLedgerEntry.h:34
xrpl::keylet::offer
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Definition
Indexes.cpp:298
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::offerDelete
TER offerDelete(ApplyView &view, SLE::Ref sle, beast::Journal j)
Delete an offer.
Definition
OfferHelpers.cpp:18
xrpl::getBookBase
UInt256 getBookBase(Book const &book)
Definition
Indexes.cpp:123
xrpl::getQuality
std::uint64_t getQuality(UInt256 const &uBase)
Definition
Indexes.cpp:194
xrpl::getQualityNext
UInt256 getQualityNext(UInt256 const &uBase)
Definition
Indexes.cpp:186
xrpl::dirFirst
bool dirFirst(ApplyView &view, UInt256 const &root, SLE::pointer &page, unsigned int &index, UInt256 &entry)
Definition
DirectoryHelpers.cpp:19
Generated by
1.17.0