20#ifndef RIPPLE_APP_BOOK_OFFER_H_INCLUDED
21#define RIPPLE_APP_BOOK_OFFER_H_INCLUDED
23#include <xrpld/ledger/View.h>
24#include <xrpl/basics/contract.h>
25#include <xrpl/protocol/Quality.h>
26#include <xrpl/protocol/Rules.h>
27#include <xrpl/protocol/SField.h>
28#include <xrpl/protocol/STLedgerEntry.h>
34template <
class TIn,
class TOut>
49template <
class TIn = STAmount,
class TOut = STAmount>
91 TAmounts<TIn, TOut>
const&
113 Throw<std::logic_error>(
"can't consume more than is available.");
116 Throw<std::logic_error>(
"can't produce more than is available.");
142 TAmounts<TIn, TOut>
const& offrAmt,
147 limitIn(TAmounts<TIn, TOut>
const& offrAmt, TIn
const& limit,
bool roundUp)
150 template <
typename... Args>
165 return {ofrInRate, ofrOutRate};
180template <
class TIn,
class TOut>
184 , m_account(m_entry->getAccountID(sfAccount))
186 auto const tp =
m_entry->getFieldAmount(sfTakerPays);
187 auto const tg =
m_entry->getFieldAmount(sfTakerGets);
190 this->
issIn_ = tp.issue();
200 , m_account(m_entry->getAccountID(sfAccount))
202 m_entry->getFieldAmount(sfTakerPays),
203 m_entry->getFieldAmount(sfTakerGets))
207template <
class TIn,
class TOut>
212 UNREACHABLE(
"ripple::TOffer::setFieldAmounts : must be specialized");
214 static_assert(
sizeof(TOut) == -1,
"Must be specialized");
218template <
class TIn,
class TOut>
221 TAmounts<TIn, TOut>
const& offrAmt,
226 rules && rules->enabled(fixReducedOffersV1))
231 return quality().ceil_out_strict(offrAmt, limit, roundUp);
232 return m_quality.ceil_out(offrAmt, limit);
235template <
class TIn,
class TOut>
238 TAmounts<TIn, TOut>
const& offrAmt,
243 rules && rules->enabled(fixReducedOffersV2))
248 return quality().ceil_in_strict(offrAmt, limit, roundUp);
249 return m_quality.ceil_in(offrAmt, limit);
252template <
class TIn,
class TOut>
253template <
typename... Args>
264 m_entry->setFieldAmount(sfTakerPays, m_amounts.in);
265 m_entry->setFieldAmount(sfTakerGets, m_amounts.out);
272 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
273 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
280 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in, issIn_));
281 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out));
288 m_entry->setFieldAmount(sfTakerPays,
toSTAmount(m_amounts.in));
289 m_entry->setFieldAmount(sfTakerGets,
toSTAmount(m_amounts.out, issOut_));
292template <
class TIn,
class TOut>
303 return m_amounts.in.issue();
306template <
class TIn,
class TOut>
310 return this->issOut_;
317 return m_amounts.out.issue();
320template <
class TIn,
class TOut>
324 return os << offer.id();
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
A currency issued by an account.
bool checkInvariant(TAmounts< TIn, TOut > const &, beast::Journal j) const
Check any required invariant.
bool fully_consumed() const
Returns true if no more funds can flow through this offer.
Issue const & issueIn() const
TOffer(SLE::pointer const &entry, Quality quality)
Issue const & issueOut() const
Quality quality() const noexcept
Returns the quality of the offer.
TAmounts< TIn, TOut > limitIn(TAmounts< TIn, TOut > const &offrAmt, TIn const &limit, bool roundUp) const
TAmounts< TIn, TOut > limitOut(TAmounts< TIn, TOut > const &offrAmt, TOut const &limit, bool roundUp) const
AccountID const & owner() const
Returns the account id of the offer's owner.
TAmounts< TIn, TOut > const & amount() const
Returns the in and out amounts.
std::optional< uint256 > key() const
static std::pair< std::uint32_t, std::uint32_t > adjustRates(std::uint32_t ofrInRate, std::uint32_t ofrOutRate)
static TER send(Args &&... args)
TAmounts< TIn, TOut > m_amounts
void consume(ApplyView &view, TAmounts< TIn, TOut > const &consumed)
Adjusts the offer to indicate that we consumed some (or all) of it.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
std::string to_string(base_uint< Bits, Tag > const &a)
std::optional< Rules > const & getCurrentTransactionRules()
TER accountSend(ApplyView &view, AccountID const &uSenderID, AccountID const &uReceiverID, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee)
Calls static accountSendIOU if saAmount represents Issue.