rippled
Loading...
Searching...
No Matches
CreateOffer.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 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_TX_CREATEOFFER_H_INCLUDED
21#define RIPPLE_TX_CREATEOFFER_H_INCLUDED
22
23#include <xrpld/app/tx/detail/OfferStream.h>
24#include <xrpld/app/tx/detail/Taker.h>
25#include <xrpld/app/tx/detail/Transactor.h>
26
27namespace ripple {
28
29class PaymentSandbox;
30class Sandbox;
31
33class CreateOffer : public Transactor
34{
35public:
37
40 : Transactor(ctx), stepCounter_(1000, j_)
41 {
42 }
43
44 static TxConsequences
46
48 static NotTEC
49 preflight(PreflightContext const& ctx);
50
52 static TER
53 preclaim(PreclaimContext const& ctx);
54
56 void
57 preCompute() override;
58
60 TER
61 doApply() override;
62
63private:
65 applyGuts(Sandbox& view, Sandbox& view_cancel);
66
67 // Determine if we are authorized to hold the asset we want to get.
68 static TER
70 ReadView const& view,
71 ApplyFlags const flags,
72 AccountID const id,
73 beast::Journal const j,
74 Issue const& issue);
75
76 bool
77 dry_offer(ApplyView& view, Offer const& offer);
78
81 bool have_direct,
82 OfferStream const& direct,
83 bool have_bridge,
84 OfferStream const& leg1,
85 OfferStream const& leg2);
86
89 Taker& taker,
91 ApplyView& view_cancel,
92 NetClock::time_point const when);
93
96 Taker& taker,
98 ApplyView& view_cancel,
99 NetClock::time_point const when);
100
101 // Step through the stream for as long as possible, skipping any offers
102 // that are from the taker or which cross the taker's threshold.
103 // Return false if the is no offer in the book, true otherwise.
104 static bool
105 step_account(OfferStream& stream, Taker const& taker);
106
107 // True if the number of offers that have been crossed
108 // exceeds the limit.
109 bool
110 reachedOfferCrossingLimit(Taker const& taker) const;
111
112 // Fill offer as much as possible by consuming offers already on the books,
113 // and adjusting account balances accordingly.
114 //
115 // Charges fees on top to taker.
117 takerCross(Sandbox& sb, Sandbox& sbCancel, Amounts const& takerAmount);
118
119 // Use the payment flow code to perform offer crossing.
121 flowCross(
122 PaymentSandbox& psb,
123 PaymentSandbox& psbCancel,
124 Amounts const& takerAmount,
125 std::optional<uint256> const& domainID);
126
127 // Temporary
128 // This is a central location that invokes both versions of cross
129 // so the results can be compared. Eventually this layer will be
130 // removed once flowCross is determined to be stable.
132 cross(
133 Sandbox& sb,
134 Sandbox& sbCancel,
135 Amounts const& takerAmount,
136 std::optional<uint256> const& domainID);
137
138 static std::string
139 format_amount(STAmount const& amount);
140
141 TER
143 Sandbox& sb,
145 Keylet const& offer_index,
146 STAmount const& saTakerPays,
147 STAmount const& saTakerGets,
148 std::function<void(SLE::ref, std::optional<uint256>)> const& setDir);
149
150private:
151 // What kind of offer we are placing
153
154 // The number of steps to take through order books while crossing
155 OfferStream::StepCounter stepCounter_;
156};
157
159
160} // namespace ripple
161
162#endif
A generic endpoint for log messages.
Definition: Journal.h:60
State information when applying a tx.
Definition: ApplyContext.h:37
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:144
Transactor specialized for creating offers in the ledger.
Definition: CreateOffer.h:34
std::pair< TER, Amounts > flowCross(PaymentSandbox &psb, PaymentSandbox &psbCancel, Amounts const &takerAmount, std::optional< uint256 > const &domainID)
std::pair< TER, Amounts > bridged_cross(Taker &taker, ApplyView &view, ApplyView &view_cancel, NetClock::time_point const when)
OfferStream::StepCounter stepCounter_
Definition: CreateOffer.h:155
static TER checkAcceptAsset(ReadView const &view, ApplyFlags const flags, AccountID const id, beast::Journal const j, Issue const &issue)
CreateOffer(ApplyContext &ctx)
Construct a Transactor subclass that creates an offer in the ledger.
Definition: CreateOffer.h:39
void preCompute() override
Gather information beyond what the Transactor base class gathers.
bool dry_offer(ApplyView &view, Offer const &offer)
static TER preclaim(PreclaimContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
static bool step_account(OfferStream &stream, Taker const &taker)
static std::string format_amount(STAmount const &amount)
static constexpr ConsequencesFactoryType ConsequencesFactory
Definition: CreateOffer.h:36
bool reachedOfferCrossingLimit(Taker const &taker) const
std::pair< TER, Amounts > takerCross(Sandbox &sb, Sandbox &sbCancel, Amounts const &takerAmount)
std::pair< TER, Amounts > direct_cross(Taker &taker, ApplyView &view, ApplyView &view_cancel, NetClock::time_point const when)
static NotTEC preflight(PreflightContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
Definition: CreateOffer.cpp:47
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
Definition: CreateOffer.cpp:36
TER applyHybrid(Sandbox &sb, std::shared_ptr< STLedgerEntry > sleOffer, Keylet const &offer_index, STAmount const &saTakerPays, STAmount const &saTakerGets, std::function< void(SLE::ref, std::optional< uint256 >)> const &setDir)
CrossType cross_type_
Definition: CreateOffer.h:152
TER doApply() override
Precondition: fee collection is likely.
std::pair< TER, bool > applyGuts(Sandbox &view, Sandbox &view_cancel)
static std::pair< bool, Quality > select_path(bool have_direct, OfferStream const &direct, bool have_bridge, OfferStream const &leg1, OfferStream const &leg2)
std::pair< TER, Amounts > cross(Sandbox &sb, Sandbox &sbCancel, Amounts const &takerAmount, std::optional< uint256 > const &domainID)
A currency issued by an account.
Definition: Issue.h:33
Presents and consumes the offers in an order book.
Definition: OfferStream.h:148
A wrapper which makes credits unavailable to balances.
A view into a ledger.
Definition: ReadView.h:52
Discardable, editable view to a ledger.
Definition: Sandbox.h:35
ApplyView & view()
Definition: Transactor.h:159
beast::Journal const j_
Definition: Transactor.h:141
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:59
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:25
ApplyFlags
Definition: ApplyView.h:31
CrossType
The flavor of an offer crossing.
Definition: Taker.h:35
A pair of SHAMap key and LedgerEntryType.
Definition: Keylet.h:39
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:79
State information when preflighting a tx.
Definition: Transactor.h:34