rippled
Loading...
Searching...
No Matches
OfferStream.h
1#ifndef XRPL_APP_BOOK_OFFERSTREAM_H_INCLUDED
2#define XRPL_APP_BOOK_OFFERSTREAM_H_INCLUDED
3
4#include <xrpld/app/tx/detail/BookTip.h>
5#include <xrpld/app/tx/detail/Offer.h>
6
7#include <xrpl/basics/Log.h>
8#include <xrpl/basics/chrono.h>
9#include <xrpl/beast/utility/Journal.h>
10#include <xrpl/ledger/View.h>
11
12#include <boost/container/flat_set.hpp>
13
14namespace ripple {
15
16template <class TIn, class TOut>
18{
19public:
21 {
22 private:
26
27 public:
29 : limit_(limit), count_(0), j_(j)
30 {
31 }
32
33 bool
35 {
36 if (count_ >= limit_)
37 {
38 JLOG(j_.debug()) << "Exceeded " << limit_ << " step limit.";
39 return false;
40 }
41 count_++;
42 return true;
43 }
45 count() const
46 {
47 return count_;
48 }
49 };
50
51protected:
62
63 void
64 erase(ApplyView& view);
65
66 virtual void
67 permRmOffer(uint256 const& offerIndex) = 0;
68
69 template <class TTakerPays, class TTakerGets>
70 bool
72
73public:
75 ApplyView& view,
76 ApplyView& cancelView,
77 Book const& book,
79 StepCounter& counter,
80 beast::Journal journal);
81
82 virtual ~TOfferStreamBase() = default;
83
89 tip() const
90 {
91 return const_cast<TOfferStreamBase*>(this)->offer_;
92 }
93
101 bool
102 step();
103
104 TOut
106 {
107 return *ownerFunds_;
108 }
109};
110
128class OfferStream : public TOfferStreamBase<STAmount, STAmount>
129{
130protected:
131 void
132 permRmOffer(uint256 const& offerIndex) override;
133
134public:
135 using TOfferStreamBase<STAmount, STAmount>::TOfferStreamBase;
136};
137
155template <class TIn, class TOut>
156class FlowOfferStream : public TOfferStreamBase<TIn, TOut>
157{
158private:
159 boost::container::flat_set<uint256> permToRemove_;
160
161public:
162 using TOfferStreamBase<TIn, TOut>::TOfferStreamBase;
163
164 // The following interface allows offer crossing to permanently
165 // remove self crossed offers. The motivation is somewhat
166 // unintuitive. See the discussion in the comments for
167 // BookOfferCrossingStep::limitSelfCrossQuality().
168 void
169 permRmOffer(uint256 const& offerIndex) override;
170
171 boost::container::flat_set<uint256> const&
173 {
174 return permToRemove_;
175 }
176};
177} // namespace ripple
178
179#endif
A generic endpoint for log messages.
Definition Journal.h:41
Stream debug() const
Definition Journal.h:309
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:124
Iterates and consumes raw offers in an order book.
Definition BookTip.h:17
Specifies an order book.
Definition Book.h:17
Presents and consumes the offers in an order book.
boost::container::flat_set< uint256 > const & permToRemove() const
void permRmOffer(uint256 const &offerIndex) override
boost::container::flat_set< uint256 > permToRemove_
Presents and consumes the offers in an order book.
void permRmOffer(uint256 const &offerIndex) override
StepCounter(std::uint32_t limit, beast::Journal j)
Definition OfferStream.h:28
std::optional< TOut > ownerFunds_
Definition OfferStream.h:60
void erase(ApplyView &view)
bool step()
Advance to the next valid offer.
beast::Journal const j_
Definition OfferStream.h:52
virtual ~TOfferStreamBase()=default
TOffer< TIn, TOut > offer_
Definition OfferStream.h:59
NetClock::time_point const expire_
Definition OfferStream.h:57
bool shouldRmSmallIncreasedQOffer() const
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
Definition OfferStream.h:89
virtual void permRmOffer(uint256 const &offerIndex)=0
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6