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#include <xrpl/basics/Log.h>
27#include <xrpl/basics/chrono.h>
28#include <xrpl/beast/utility/Journal.h>
29
30#include <boost/container/flat_set.hpp>
31
32namespace ripple {
33
34template <class TIn, class TOut>
36{
37public:
39 {
40 private:
44
45 public:
47 : limit_(limit), count_(0), j_(j)
48 {
49 }
50
51 bool
53 {
54 if (count_ >= limit_)
55 {
56 JLOG(j_.debug()) << "Exceeded " << limit_ << " step limit.";
57 return false;
58 }
59 count_++;
60 return true;
61 }
63 count() const
64 {
65 return count_;
66 }
67 };
68
69protected:
80
81 void
82 erase(ApplyView& view);
83
84 virtual void
85 permRmOffer(uint256 const& offerIndex) = 0;
86
87 template <class TTakerPays, class TTakerGets>
88 bool
90
91public:
93 ApplyView& view,
94 ApplyView& cancelView,
95 Book const& book,
97 StepCounter& counter,
98 beast::Journal journal);
99
100 virtual ~TOfferStreamBase() = default;
101
107 tip() const
108 {
109 return const_cast<TOfferStreamBase*>(this)->offer_;
110 }
111
119 bool
120 step();
121
122 TOut
124 {
125 return *ownerFunds_;
126 }
127};
128
146class OfferStream : public TOfferStreamBase<STAmount, STAmount>
147{
148protected:
149 void
150 permRmOffer(uint256 const& offerIndex) override;
151
152public:
153 using TOfferStreamBase<STAmount, STAmount>::TOfferStreamBase;
154};
155
173template <class TIn, class TOut>
174class FlowOfferStream : public TOfferStreamBase<TIn, TOut>
175{
176private:
177 boost::container::flat_set<uint256> permToRemove_;
178
179public:
180 using TOfferStreamBase<TIn, TOut>::TOfferStreamBase;
181
182 // The following interface allows offer crossing to permanently
183 // remove self crossed offers. The motivation is somewhat
184 // unintuitive. See the discussion in the comments for
185 // BookOfferCrossingStep::limitSelfCrossQuality().
186 void
187 permRmOffer(uint256 const& offerIndex) override;
188
189 boost::container::flat_set<uint256> const&
191 {
192 return permToRemove_;
193 }
194};
195} // namespace ripple
196
197#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:140
Iterates and consumes raw offers in an order book.
Definition: BookTip.h:36
Specifies an order book.
Definition: Book.h:35
Presents and consumes the offers in an order book.
Definition: OfferStream.h:175
boost::container::flat_set< uint256 > const & permToRemove() const
Definition: OfferStream.h:190
void permRmOffer(uint256 const &offerIndex) override
boost::container::flat_set< uint256 > permToRemove_
Definition: OfferStream.h:177
Presents and consumes the offers in an order book.
Definition: OfferStream.h:147
void permRmOffer(uint256 const &offerIndex) override
StepCounter(std::uint32_t limit, beast::Journal j)
Definition: OfferStream.h:46
std::optional< TOut > ownerFunds_
Definition: OfferStream.h:78
void erase(ApplyView &view)
Definition: OfferStream.cpp:62
bool step()
Advance to the next valid offer.
beast::Journal const j_
Definition: OfferStream.h:70
virtual ~TOfferStreamBase()=default
TOffer< TIn, TOut > offer_
Definition: OfferStream.h:77
NetClock::time_point const expire_
Definition: OfferStream.h:75
bool shouldRmSmallIncreasedQOffer() const
TOffer< TIn, TOut > & tip() const
Returns the offer at the tip of the order book.
Definition: OfferStream.h:107
StepCounter & counter_
Definition: OfferStream.h:79
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