xrpld
Loading...
Searching...
No Matches
tx/transactors/dex/OfferCreate.h
1#pragma once
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Asset.h>
10#include <xrpl/protocol/Keylet.h>
11#include <xrpl/protocol/Quality.h>
12#include <xrpl/protocol/STAmount.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14#include <xrpl/protocol/STTx.h>
15#include <xrpl/protocol/TER.h>
16#include <xrpl/protocol/XRPAmount.h>
17#include <xrpl/tx/ApplyContext.h>
18#include <xrpl/tx/Transactor.h>
19
20#include <cstdint>
21#include <functional>
22#include <optional>
23#include <string>
24#include <utility>
25
26namespace xrpl {
27
28class PaymentSandbox;
29class Sandbox;
30
34class OfferCreate : public Transactor
35{
36public:
38
42 explicit OfferCreate(ApplyContext& ctx) : Transactor(ctx)
43 {
44 }
45
46 static TxConsequences
48
49 static bool
51
52 static std::uint32_t
54
58 static NotTEC
59 preflight(PreflightContext const& ctx);
60
64 static TER
65 preclaim(PreclaimContext const& ctx);
66
70 TER
71 doApply() override;
72
73 void
74 visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override;
75
76 [[nodiscard]] bool
78 STTx const& tx,
79 TER result,
80 XRPAmount fee,
81 ReadView const& view,
82 beast::Journal const& j) override;
83
84private:
86 applyGuts(Sandbox& view, Sandbox& viewCancel);
87
88 // Determine if we are authorized to hold the asset we want to get.
89 static TER
91 ReadView const& view,
92 ApplyFlags const flags,
93 AccountID const id,
94 beast::Journal const j,
95 Asset const& asset);
96
97 // Use the payment flow code to perform offer crossing.
100 PaymentSandbox& psb,
101 PaymentSandbox& psbCancel,
102 Amounts const& takerAmount,
103 std::optional<UInt256> const& domainID);
104
105 static std::string
106 formatAmount(STAmount const& amount);
107
108 TER
110 Sandbox& sb,
111 STLedgerEntry::pointer sleOffer,
112 Keylet const& offerIndex,
113 STAmount const& saTakerPays,
114 STAmount const& saTakerGets,
115 std::uint64_t openRate,
116 std::function<void(SLE::Ref, std::optional<UInt256>)> const& setDir);
117};
118
119} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
State information when applying a tx.
static TER preclaim(PreclaimContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
static TER checkAcceptAsset(ReadView const &view, ApplyFlags const flags, AccountID const id, beast::Journal const j, Asset const &asset)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
TER doApply() override
Precondition: fee collection is likely.
static TxConsequences makeTxConsequences(PreflightContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
OfferCreate(ApplyContext &ctx)
Construct a Transactor subclass that creates an offer in the ledger.
void visitInvariantEntry(bool isDelete, SLE::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
Enforce constraints beyond those of the Transactor base class.
std::pair< TER, bool > applyGuts(Sandbox &view, Sandbox &viewCancel)
static constexpr auto kConsequencesFactory
std::pair< TER, Amounts > flowCross(PaymentSandbox &psb, PaymentSandbox &psbCancel, Amounts const &takerAmount, std::optional< UInt256 > const &domainID)
static std::string formatAmount(STAmount const &amount)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
TER applyHybrid(Sandbox &sb, STLedgerEntry::pointer sleOffer, Keylet const &offerIndex, STAmount const &saTakerPays, STAmount const &saTakerGets, std::uint64_t openRate, std::function< void(SLE::Ref, std::optional< UInt256 >)> const &setDir)
A wrapper which makes credits unavailable to balances.
A view into a ledger.
Definition ReadView.h:41
std::shared_ptr< STLedgerEntry > pointer
std::shared_ptr< STLedgerEntry const > const & ConstRef
std::shared_ptr< STLedgerEntry > const & Ref
Discardable, editable view to a ledger.
Definition Sandbox.h:18
ApplyView & view()
Definition Transactor.h:184
Transactor(Transactor const &)=delete
Class describing the consequences to the account of applying a transaction if the transaction consume...
Definition applySteps.h:53
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
TAmounts< STAmount, STAmount > Amounts
Definition Quality.h:69
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:614
bool after(NetClock::time_point now, std::uint32_t mark)
Has the specified time passed?
Definition View.cpp:644
ApplyFlags
Definition ApplyView.h:27
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
TERSubset< CanCvtToTER > TER
Definition TER.h:654
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:20
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:92
State information when preflighting a tx.
Definition Transactor.h:39