rippled
Loading...
Searching...
No Matches
OfferStream.h
1#pragma once
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/chrono.h>
5#include <xrpl/beast/utility/Journal.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/tx/paths/BookTip.h>
8#include <xrpl/tx/paths/Offer.h>
9
10#include <boost/container/flat_set.hpp>
11
12namespace xrpl {
13
14template <class TIn, class TOut>
16{
17public:
19 {
20 private:
24
25 public:
27 {
28 }
29
30 bool
32 {
33 if (count_ >= limit_)
34 {
35 JLOG(j_.debug()) << "Exceeded " << limit_ << " step limit.";
36 return false;
37 }
38 count_++;
39 return true;
40 }
42 count() const
43 {
44 return count_;
45 }
46 };
47
48protected:
59
60 void
61 erase(ApplyView& view);
62
63 virtual void
64 permRmOffer(uint256 const& offerIndex) = 0;
65
66 template <class TTakerPays, class TTakerGets>
67 bool
69
70public:
72 ApplyView& view,
73 ApplyView& cancelView,
74 Book const& book,
76 StepCounter& counter,
77 beast::Journal journal);
78
79 virtual ~TOfferStreamBase() = default;
80
86 tip() const
87 {
88 return const_cast<TOfferStreamBase*>(this)->offer_;
89 }
90
98 bool
99 step();
100
101 TOut
103 {
104 return *ownerFunds_;
105 }
106};
107
125class OfferStream : public TOfferStreamBase<STAmount, STAmount>
126{
127protected:
128 void
129 permRmOffer(uint256 const& offerIndex) override;
130
131public:
132 using TOfferStreamBase<STAmount, STAmount>::TOfferStreamBase;
133};
134
152template <class TIn, class TOut>
153class FlowOfferStream : public TOfferStreamBase<TIn, TOut>
154{
155private:
156 boost::container::flat_set<uint256> permToRemove_;
157
158public:
159 using TOfferStreamBase<TIn, TOut>::TOfferStreamBase;
160
161 // The following interface allows offer crossing to permanently
162 // remove self crossed offers. The motivation is somewhat
163 // unintuitive. See the discussion in the comments for
164 // BookOfferCrossingStep::limitSelfCrossQuality().
165 void
166 permRmOffer(uint256 const& offerIndex) override;
167
168 boost::container::flat_set<uint256> const&
170 {
171 return permToRemove_;
172 }
173};
174} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:40
Stream debug() const
Definition Journal.h:301
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:116
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:26
StepCounter & counter_
Definition OfferStream.h:58
std::optional< TOut > ownerFunds_
Definition OfferStream.h:57
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
Definition OfferStream.h:86
bool shouldRmSmallIncreasedQOffer() const
ApplyView & cancelView_
Definition OfferStream.h:51
TOut ownerFunds() const
NetClock::time_point const expire_
Definition OfferStream.h:54
TOffer< TIn, TOut > offer_
Definition OfferStream.h:56
virtual void permRmOffer(uint256 const &offerIndex)=0
virtual ~TOfferStreamBase()=default
beast::Journal const j_
Definition OfferStream.h:49
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