xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
include
xrpl
tx
paths
OfferStream.h
1
#pragma once
2
3
#include <xrpl/basics/Log.h>
4
#include <xrpl/basics/base_uint.h>
5
#include <xrpl/basics/chrono.h>
6
#include <xrpl/beast/utility/Journal.h>
7
#include <xrpl/ledger/ApplyView.h>
8
#include <xrpl/protocol/Book.h>
9
#include <xrpl/protocol/Concepts.h>
10
#include <xrpl/tx/paths/BookTip.h>
11
#include <xrpl/tx/paths/Offer.h>
12
13
#include <boost/container/flat_set.hpp>
14
15
#include <
cstdint
>
16
#include <
optional
>
17
18
namespace
xrpl
{
19
20
template
<StepAmount TIn, StepAmount TOut>
21
class
TOfferStreamBase
22
{
23
public
:
24
class
StepCounter
25
{
26
private
:
27
std::uint32_t
const
limit_
;
28
std::uint32_t
count_
{0};
29
beast::Journal
j_
;
30
31
public
:
32
StepCounter
(
std::uint32_t
limit,
beast::Journal
j) :
limit_
(limit),
j_
(j)
33
{
34
}
35
36
bool
37
step
()
38
{
39
if
(
count_
>=
limit_
)
40
{
41
JLOG(
j_
.debug()) <<
"Exceeded "
<<
limit_
<<
" step limit."
;
42
return
false
;
43
}
44
count_
++;
45
return
true
;
46
}
47
[[nodiscard]]
std::uint32_t
48
count
()
const
49
{
50
return
count_
;
51
}
52
};
53
54
protected
:
55
beast::Journal
const
j_
;
56
ApplyView
&
view_
;
57
ApplyView
&
cancelView_
;
58
Book
book_
;
59
bool
validBook_
;
60
NetClock::time_point
const
expire_
;
61
BookTip
tip_
;
62
TOffer<TIn, TOut>
offer_
;
63
std::optional<TOut>
ownerFunds_
;
64
StepCounter
&
counter_
;
65
66
void
67
erase
(
ApplyView
& view);
68
69
virtual
void
70
permRmOffer
(
UInt256
const
& offerIndex) = 0;
71
72
template
<
class
TTakerPays,
class
TTakerGets>
73
requires
ValidTaker<TTakerPays, TTakerGets>
74
[[nodiscard]]
bool
75
shouldRmSmallIncreasedQOffer
()
const
;
76
77
public
:
78
TOfferStreamBase
(
79
ApplyView
& view,
80
ApplyView
& cancelView,
81
Book
const
& book,
82
NetClock::time_point
when,
83
StepCounter
& counter,
84
beast::Journal
journal);
85
86
virtual
~TOfferStreamBase
() =
default
;
87
93
[[nodiscard]]
TOffer<TIn, TOut>
&
94
tip
()
const
95
{
96
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast)
97
return
const_cast<
TOfferStreamBase
*
>
(
this
)->
offer_
;
98
}
99
108
bool
109
step
();
110
111
[[nodiscard]] TOut
112
ownerFunds
()
const
113
{
114
return
*
ownerFunds_
;
// NOLINT(bugprone-unchecked-optional-access) always set after step()
115
// is called
116
}
117
};
118
137
template
<StepAmount TIn, StepAmount TOut>
138
class
FlowOfferStream
:
public
TOfferStreamBase
<TIn, TOut>
139
{
140
private
:
141
boost::container::flat_set<UInt256>
permToRemove_
;
142
143
public
:
144
using
TOfferStreamBase
<TIn, TOut>
::TOfferStreamBase
;
145
146
// The following interface allows offer crossing to permanently
147
// remove self crossed offers. The motivation is somewhat
148
// unintuitive. See the discussion in the comments for
149
// BookOfferCrossingStep::limitSelfCrossQuality().
150
void
151
permRmOffer
(
UInt256
const
& offerIndex)
override
;
152
153
[[nodiscard]] boost::container::flat_set<UInt256>
const
&
154
permToRemove
()
const
155
{
156
return
permToRemove_
;
157
}
158
};
159
}
// 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
Iterates and consumes raw offers in an order book.
Definition
BookTip.h:20
xrpl::Book
Specifies an order book.
Definition
Book.h:28
xrpl::FlowOfferStream
Presents and consumes the offers in an order book.
Definition
OfferStream.h:139
xrpl::FlowOfferStream::permToRemove
boost::container::flat_set< UInt256 > const & permToRemove() const
Definition
OfferStream.h:154
xrpl::FlowOfferStream::permRmOffer
void permRmOffer(UInt256 const &offerIndex) override
Definition
OfferStream.cpp:404
xrpl::FlowOfferStream::permToRemove_
boost::container::flat_set< UInt256 > permToRemove_
Definition
OfferStream.h:141
xrpl::NetClock::time_point
std::chrono::time_point< NetClock > time_point
Definition
chrono.h:48
xrpl::TOfferStreamBase::StepCounter
Definition
OfferStream.h:25
xrpl::TOfferStreamBase::StepCounter::limit_
std::uint32_t const limit_
Definition
OfferStream.h:27
xrpl::TOfferStreamBase::StepCounter::count_
std::uint32_t count_
Definition
OfferStream.h:28
xrpl::TOfferStreamBase::StepCounter::j_
beast::Journal j_
Definition
OfferStream.h:29
xrpl::TOfferStreamBase::StepCounter::step
bool step()
Definition
OfferStream.h:37
xrpl::TOfferStreamBase::StepCounter::count
std::uint32_t count() const
Definition
OfferStream.h:48
xrpl::TOfferStreamBase::StepCounter::StepCounter
StepCounter(std::uint32_t limit, beast::Journal j)
Definition
OfferStream.h:32
xrpl::TOfferStreamBase::counter_
StepCounter & counter_
Definition
OfferStream.h:64
xrpl::TOfferStreamBase::ownerFunds_
std::optional< TOut > ownerFunds_
Definition
OfferStream.h:63
xrpl::TOfferStreamBase::book_
Book book_
Definition
OfferStream.h:58
xrpl::TOfferStreamBase::permRmOffer
virtual void permRmOffer(UInt256 const &offerIndex)=0
xrpl::TOfferStreamBase::TOfferStreamBase
TOfferStreamBase(ApplyView &view, ApplyView &cancelView, Book const &book, NetClock::time_point when, StepCounter &counter, beast::Journal journal)
Definition
OfferStream.cpp:53
xrpl::TOfferStreamBase::tip_
BookTip tip_
Definition
OfferStream.h:61
xrpl::TOfferStreamBase::tip
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
Definition
OfferStream.h:94
xrpl::TOfferStreamBase::validBook_
bool validBook_
Definition
OfferStream.h:59
xrpl::TOfferStreamBase::shouldRmSmallIncreasedQOffer
bool shouldRmSmallIncreasedQOffer() const
Definition
OfferStream.cpp:141
xrpl::TOfferStreamBase::cancelView_
ApplyView & cancelView_
Definition
OfferStream.h:57
xrpl::TOfferStreamBase::ownerFunds
TOut ownerFunds() const
Definition
OfferStream.h:112
xrpl::TOfferStreamBase::expire_
NetClock::time_point const expire_
Definition
OfferStream.h:60
xrpl::TOfferStreamBase::offer_
TOffer< TIn, TOut > offer_
Definition
OfferStream.h:62
xrpl::TOfferStreamBase::~TOfferStreamBase
virtual ~TOfferStreamBase()=default
xrpl::TOfferStreamBase::j_
beast::Journal const j_
Definition
OfferStream.h:55
xrpl::TOfferStreamBase::view_
ApplyView & view_
Definition
OfferStream.h:56
xrpl::TOfferStreamBase::step
bool step()
Advance to the next valid offer.
Definition
OfferStream.cpp:202
xrpl::TOfferStreamBase::erase
void erase(ApplyView &view)
Definition
OfferStream.cpp:76
xrpl::TOffer
Definition
tx/paths/Offer.h:30
xrpl::ValidTaker
Definition
Concepts.h:32
cstdint
std::uint32_t
xrpl
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:5
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
optional
Generated by
1.17.0