rippled
Loading...
Searching...
No Matches
OfferStream.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_APP_BOOK_OFFERSTREAM_H_INCLUDED
21#define RIPPLE_APP_BOOK_OFFERSTREAM_H_INCLUDED
22
23#include <xrpld/app/tx/detail/BookTip.h>
24#include <xrpld/app/tx/detail/Offer.h>
25#include <xrpld/ledger/View.h>
26
27#include <xrpl/basics/Log.h>
28#include <xrpl/basics/chrono.h>
29#include <xrpl/beast/utility/Journal.h>
30
31#include <boost/container/flat_set.hpp>
32
33namespace ripple {
34
35template <class TIn, class TOut>
37{
38public:
40 {
41 private:
45
46 public:
48 : limit_(limit), count_(0), j_(j)
49 {
50 }
51
52 bool
54 {
55 if (count_ >= limit_)
56 {
57 JLOG(j_.debug()) << "Exceeded " << limit_ << " step limit.";
58 return false;
59 }
60 count_++;
61 return true;
62 }
64 count() const
65 {
66 return count_;
67 }
68 };
69
70protected:
81
82 void
83 erase(ApplyView& view);
84
85 virtual void
86 permRmOffer(uint256 const& offerIndex) = 0;
87
88 template <class TTakerPays, class TTakerGets>
89 bool
91
92public:
94 ApplyView& view,
95 ApplyView& cancelView,
96 Book const& book,
98 StepCounter& counter,
99 beast::Journal journal);
100
101 virtual ~TOfferStreamBase() = default;
102
108 tip() const
109 {
110 return const_cast<TOfferStreamBase*>(this)->offer_;
111 }
112
120 bool
121 step();
122
123 TOut
125 {
126 return *ownerFunds_;
127 }
128};
129
147class OfferStream : public TOfferStreamBase<STAmount, STAmount>
148{
149protected:
150 void
151 permRmOffer(uint256 const& offerIndex) override;
152
153public:
154 using TOfferStreamBase<STAmount, STAmount>::TOfferStreamBase;
155};
156
174template <class TIn, class TOut>
175class FlowOfferStream : public TOfferStreamBase<TIn, TOut>
176{
177private:
178 boost::container::flat_set<uint256> permToRemove_;
179
180public:
181 using TOfferStreamBase<TIn, TOut>::TOfferStreamBase;
182
183 // The following interface allows offer crossing to permanently
184 // remove self crossed offers. The motivation is somewhat
185 // unintuitive. See the discussion in the comments for
186 // BookOfferCrossingStep::limitSelfCrossQuality().
187 void
188 permRmOffer(uint256 const& offerIndex) override;
189
190 boost::container::flat_set<uint256> const&
192 {
193 return permToRemove_;
194 }
195};
196} // namespace ripple
197
198#endif
A generic endpoint for log messages.
Definition: Journal.h:60
Stream debug() const
Definition: Journal.h:328
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:144
Iterates and consumes raw offers in an order book.
Definition: BookTip.h:37
Specifies an order book.
Definition: Book.h:35
Presents and consumes the offers in an order book.
Definition: OfferStream.h:176
boost::container::flat_set< uint256 > const & permToRemove() const
Definition: OfferStream.h:191
void permRmOffer(uint256 const &offerIndex) override
boost::container::flat_set< uint256 > permToRemove_
Definition: OfferStream.h:178
Presents and consumes the offers in an order book.
Definition: OfferStream.h:148
void permRmOffer(uint256 const &offerIndex) override
StepCounter(std::uint32_t limit, beast::Journal j)
Definition: OfferStream.h:47
std::optional< TOut > ownerFunds_
Definition: OfferStream.h:79
void erase(ApplyView &view)
Definition: OfferStream.cpp:63
bool step()
Advance to the next valid offer.
beast::Journal const j_
Definition: OfferStream.h:71
virtual ~TOfferStreamBase()=default
TOffer< TIn, TOut > offer_
Definition: OfferStream.h:78
NetClock::time_point const expire_
Definition: OfferStream.h:76
bool shouldRmSmallIncreasedQOffer() const
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
Definition: OfferStream.h:108
StepCounter & counter_
Definition: OfferStream.h:80
virtual void permRmOffer(uint256 const &offerIndex)=0
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26