xrpld
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/protocol/Concepts.h>
8#include <xrpl/tx/paths/BookTip.h>
9#include <xrpl/tx/paths/Offer.h>
10
11#include <boost/container/flat_set.hpp>
12
13namespace xrpl {
14
15template <StepAmount TIn, StepAmount 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 }
42 [[nodiscard]] std::uint32_t
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>
69 [[nodiscard]] bool
71
72public:
74 ApplyView& view,
75 ApplyView& cancelView,
76 Book const& book,
78 StepCounter& counter,
79 beast::Journal journal);
80
81 virtual ~TOfferStreamBase() = default;
82
87 [[nodiscard]] TOffer<TIn, TOut>&
88 tip() const
89 {
90 return const_cast<TOfferStreamBase*>(this)->offer_;
91 }
92
100 bool
101 step();
102
103 [[nodiscard]] TOut
105 {
106 return *ownerFunds_; // NOLINT(bugprone-unchecked-optional-access) always set after step()
107 // is called
108 }
109};
110
128template <StepAmount TIn, StepAmount TOut>
129class FlowOfferStream : public TOfferStreamBase<TIn, TOut>
130{
131private:
132 boost::container::flat_set<uint256> permToRemove_;
133
134public:
135 using TOfferStreamBase<TIn, TOut>::TOfferStreamBase;
136
137 // The following interface allows offer crossing to permanently
138 // remove self crossed offers. The motivation is somewhat
139 // unintuitive. See the discussion in the comments for
140 // BookOfferCrossingStep::limitSelfCrossQuality().
141 void
142 permRmOffer(uint256 const& offerIndex) override;
143
144 [[nodiscard]] boost::container::flat_set<uint256> const&
146 {
147 return permToRemove_;
148 }
149};
150} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Writeable view to a ledger, for applying a transaction.
Definition ApplyView.h:118
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
std::chrono::time_point< NetClock > time_point
Definition chrono.h:46
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
TOfferStreamBase(ApplyView &view, ApplyView &cancelView, Book const &book, NetClock::time_point when, StepCounter &counter, beast::Journal journal)
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
Definition OfferStream.h:88
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
BaseUInt< 256 > uint256
Definition base_uint.h:562