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