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#include <utility>
27
28namespace ripple {
29
30class PaymentSandbox;
31class Sandbox;
32
34class CreateOffer : public Transactor
35{
36public:
38
41 : Transactor(ctx), stepCounter_(1000, j_)
42 {
43 }
44
45 static TxConsequences
47
49 static NotTEC
50 preflight(PreflightContext const& ctx);
51
53 static TER
54 preclaim(PreclaimContext const& ctx);
55
57 void
58 preCompute() override;
59
61 TER
62 doApply() override;
63
64private:
66 applyGuts(Sandbox& view, Sandbox& view_cancel);
67
68 // Determine if we are authorized to hold the asset we want to get.
69 static TER
71 ReadView const& view,
72 ApplyFlags const flags,
73 AccountID const id,
74 beast::Journal const j,
75 Issue const& issue);
76
77 bool
78 dry_offer(ApplyView& view, Offer const& offer);
79
82 bool have_direct,
83 OfferStream const& direct,
84 bool have_bridge,
85 OfferStream const& leg1,
86 OfferStream const& leg2);
87
90 Taker& taker,
92 ApplyView& view_cancel,
93 NetClock::time_point const when);
94
97 Taker& taker,
99 ApplyView& view_cancel,
100 NetClock::time_point const when);
101
102 // Step through the stream for as long as possible, skipping any offers
103 // that are from the taker or which cross the taker's threshold.
104 // Return false if the is no offer in the book, true otherwise.
105 static bool
106 step_account(OfferStream& stream, Taker const& taker);
107
108 // True if the number of offers that have been crossed
109 // exceeds the limit.
110 bool
111 reachedOfferCrossingLimit(Taker const& taker) const;
112
113 // Fill offer as much as possible by consuming offers already on the books,
114 // and adjusting account balances accordingly.
115 //
116 // Charges fees on top to taker.
118 takerCross(Sandbox& sb, Sandbox& sbCancel, Amounts const& takerAmount);
119
120 // Use the payment flow code to perform offer crossing.
122 flowCross(
123 PaymentSandbox& psb,
124 PaymentSandbox& psbCancel,
125 Amounts const& takerAmount);
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(Sandbox& sb, Sandbox& sbCancel, Amounts const& takerAmount);
133
134 static std::string
135 format_amount(STAmount const& amount);
136
137private:
138 // What kind of offer we are placing
140
141 // The number of steps to take through order books while crossing
142 OfferStream::StepCounter stepCounter_;
143};
144
146
147} // namespace ripple
148
149#endif
A generic endpoint for log messages.
Definition: Journal.h:59
State information when applying a tx.
Definition: ApplyContext.h:36
Writeable view to a ledger, for applying a transaction.
Definition: ApplyView.h:140
Transactor specialized for creating offers in the ledger.
Definition: CreateOffer.h:35
std::pair< TER, Amounts > bridged_cross(Taker &taker, ApplyView &view, ApplyView &view_cancel, NetClock::time_point const when)
OfferStream::StepCounter stepCounter_
Definition: CreateOffer.h:142
std::pair< TER, Amounts > flowCross(PaymentSandbox &psb, PaymentSandbox &psbCancel, Amounts const &takerAmount)
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:40
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:37
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:43
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
Definition: CreateOffer.cpp:32
CrossType cross_type_
Definition: CreateOffer.h:139
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)
A currency issued by an account.
Definition: Issue.h:36
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:55
Discardable, editable view to a ledger.
Definition: Sandbox.h:35
ApplyView & view()
Definition: Transactor.h:107
beast::Journal const j_
Definition: Transactor.h:89
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition: applySteps.h:58
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
ApplyFlags
Definition: ApplyView.h:30
CrossType
The flavor of an offer crossing.
Definition: Taker.h:36
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:53
State information when preflighting a tx.
Definition: Transactor.h:32