20 #ifndef RIPPLE_APP_BOOK_OFFER_H_INCLUDED
21 #define RIPPLE_APP_BOOK_OFFER_H_INCLUDED
23 #include <ripple/basics/contract.h>
24 #include <ripple/ledger/View.h>
25 #include <ripple/protocol/Quality.h>
26 #include <ripple/protocol/SField.h>
27 #include <ripple/protocol/STLedgerEntry.h>
33 template <
class TIn,
class TOut>
48 template <
class TIn = STAmount,
class TOut = STAmount>
90 TAmounts<TIn, TOut>
const&
112 Throw<std::logic_error>(
"can't consume more than is available.");
115 Throw<std::logic_error>(
"can't produce more than is available.");
141 TAmounts<TIn, TOut>
const& offrAmt,
143 bool fixReducedOffers,
147 limitIn(TAmounts<TIn, TOut>
const& offrAmt, TIn
const& limit)
const;
149 template <
typename... Args>
151 send(Args&&... args);
164 return {ofrInRate, ofrOutRate};
170 template <
class TIn,
class TOut>
174 , m_account(m_entry->getAccountID(
sfAccount))
176 auto const tp = m_entry->getFieldAmount(
sfTakerPays);
177 auto const tg = m_entry->getFieldAmount(
sfTakerGets);
178 m_amounts.in = toAmount<TIn>(tp);
179 m_amounts.out = toAmount<TOut>(tg);
180 this->issIn_ = tp.issue();
181 this->issOut_ = tg.issue();
190 , m_account(m_entry->getAccountID(
sfAccount))
197 template <
class TIn,
class TOut>
204 static_assert(
sizeof(TOut) == -1,
"Must be specialized");
208 template <
class TIn,
class TOut>
211 TAmounts<TIn, TOut>
const& offrAmt,
213 bool fixReducedOffers,
216 if (fixReducedOffers)
221 return quality().ceil_out_strict(offrAmt, limit, roundUp);
222 return m_quality.ceil_out(offrAmt, limit);
225 template <
class TIn,
class TOut>
230 return m_quality.ceil_in(offrAmt, limit);
233 template <
class TIn,
class TOut>
234 template <
typename... Args>
245 m_entry->setFieldAmount(
sfTakerPays, m_amounts.in);
246 m_entry->setFieldAmount(
sfTakerGets, m_amounts.out);
273 template <
class TIn,
class TOut>
284 return m_amounts.in.issue();
287 template <
class TIn,
class TOut>
291 return this->issOut_;
298 return m_amounts.out.issue();
301 template <
class TIn,
class TOut>
305 return os << offer.id();
Quality quality() const noexcept
Returns the quality of the offer.
Issue const & issueOut() const
TAmounts< TIn, TOut > m_amounts
A currency issued by an account.
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offrAmt, TOut const &limit, bool fixReducedOffers, bool roundUp) const
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
bool fully_consumed() const
Returns true if no more funds can flow through this offer.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Writeable view to a ledger, for applying a transaction.
TAmounts< TIn, TOut > const & amount() const
Returns the in and out amounts.
std::optional< uint256 > key() const
const SF_AMOUNT sfTakerPays
Issue const & issueIn() const
static TER send(Args &&... args)
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
AccountID const & owner() const
Returns the account id of the offer's owner.
const SF_AMOUNT sfTakerGets
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
Adjusts the offer to indicate that we consumed some (or all) of it.
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
const SF_ACCOUNT sfAccount
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offrAmt, TIn const &limit) const
static std::pair< std::uint32_t, std::uint32_t > adjustRates(std::uint32_t ofrInRate, std::uint32_t ofrOutRate)