20#ifndef RIPPLE_APP_BOOK_OFFER_H_INCLUDED 
   21#define RIPPLE_APP_BOOK_OFFER_H_INCLUDED 
   23#include <xrpl/basics/Log.h> 
   24#include <xrpl/basics/contract.h> 
   25#include <xrpl/ledger/View.h> 
   26#include <xrpl/protocol/Quality.h> 
   27#include <xrpl/protocol/Rules.h> 
   28#include <xrpl/protocol/SField.h> 
   29#include <xrpl/protocol/STLedgerEntry.h> 
   35template <
class TIn, 
class TOut>
 
   50template <
class TIn = STAmount, 
class TOut = STAmount>
 
   92    TAmounts<TIn, TOut> 
const&
 
  114            Throw<std::logic_error>(
"can't consume more than is available.");
 
  117            Throw<std::logic_error>(
"can't produce more than is available.");
 
 
  143        TAmounts<TIn, TOut> 
const& offrAmt,
 
  148    limitIn(TAmounts<TIn, TOut> 
const& offrAmt, TIn 
const& limit, 
bool roundUp)
 
  151    template <
typename... Args>
 
  166        return {ofrInRate, ofrOutRate};
 
 
  182                << 
"AMMOffer::checkInvariant failed: consumed " 
 
  197template <
class TIn, 
class TOut>
 
  201    , m_account(m_entry->getAccountID(sfAccount))
 
  203    auto const tp = 
m_entry->getFieldAmount(sfTakerPays);
 
  204    auto const tg = 
m_entry->getFieldAmount(sfTakerGets);
 
  207    this->
issIn_ = tp.issue();
 
 
  217    , m_account(m_entry->getAccountID(sfAccount))
 
  219          m_entry->getFieldAmount(sfTakerPays),
 
  220          m_entry->getFieldAmount(sfTakerGets))
 
 
  224template <
class TIn, 
class TOut>
 
  230    UNREACHABLE(
"ripple::TOffer::setFieldAmounts : must be specialized");
 
  232    static_assert(
sizeof(TOut) == -1, 
"Must be specialized");
 
 
  237template <
class TIn, 
class TOut>
 
  240    TAmounts<TIn, TOut> 
const& offrAmt,
 
  246    return quality().ceil_out_strict(offrAmt, limit, roundUp);
 
 
  249template <
class TIn, 
class TOut>
 
  252    TAmounts<TIn, TOut> 
const& offrAmt,
 
  257        rules && rules->enabled(fixReducedOffersV2))
 
  262        return quality().ceil_in_strict(offrAmt, limit, roundUp);
 
  263    return m_quality.ceil_in(offrAmt, limit);
 
 
  266template <
class TIn, 
class TOut>
 
  267template <
typename... Args>
 
 
  278    m_entry->setFieldAmount(sfTakerPays, m_amounts.in);
 
  279    m_entry->setFieldAmount(sfTakerGets, m_amounts.out);
 
 
  286    m_entry->setFieldAmount(sfTakerPays, 
toSTAmount(m_amounts.in, issIn_));
 
  287    m_entry->setFieldAmount(sfTakerGets, 
toSTAmount(m_amounts.out, issOut_));
 
 
  294    m_entry->setFieldAmount(sfTakerPays, 
toSTAmount(m_amounts.in, issIn_));
 
  295    m_entry->setFieldAmount(sfTakerGets, 
toSTAmount(m_amounts.out));
 
 
  302    m_entry->setFieldAmount(sfTakerPays, 
toSTAmount(m_amounts.in));
 
  303    m_entry->setFieldAmount(sfTakerGets, 
toSTAmount(m_amounts.out, issOut_));
 
 
  306template <
class TIn, 
class TOut>
 
  317    return m_amounts.in.issue();
 
 
  320template <
class TIn, 
class TOut>
 
  324    return this->issOut_;
 
 
  331    return m_amounts.out.issue();
 
 
  334template <
class TIn, 
class TOut>
 
  338    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 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.
 
bool checkInvariant(TAmounts< TIn, TOut > const &consumed, beast::Journal j) const
Check any required invariant.
 
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.
 
bool isFeatureEnabled(uint256 const &feature)
 
STAmount toSTAmount(IOUAmount const &iou, Issue const &iss)
 
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
 
TER accountSend(ApplyView &view, AccountID const &from, AccountID const &to, STAmount const &saAmount, beast::Journal j, WaiveTransferFee waiveFee=WaiveTransferFee::No)
Calls static accountSendIOU if saAmount represents Issue.
 
std::string to_string(base_uint< Bits, Tag > const &a)
 
std::optional< Rules > const & getCurrentTransactionRules()