rippled
Loading...
Searching...
No Matches
OfferCancel.cpp
1#include <xrpl/ledger/View.h>
2#include <xrpl/ledger/helpers/OfferHelpers.h>
3#include <xrpl/protocol/st.h>
4#include <xrpl/tx/transactors/dex/OfferCancel.h>
5
6namespace xrpl {
7
10{
11 if (ctx.tx[sfOfferSequence] == 0u)
12 {
13 JLOG(ctx.j.trace()) << "OfferCancel::preflight: missing sequence";
14 return temBAD_SEQUENCE;
15 }
16
17 return tesSUCCESS;
18}
19
20//------------------------------------------------------------------------------
21
22TER
24{
25 auto const id = ctx.tx[sfAccount];
26 auto const offerSequence = ctx.tx[sfOfferSequence];
27
28 auto const sle = ctx.view.read(keylet::account(id));
29 if (!sle)
30 return terNO_ACCOUNT;
31
32 if ((*sle)[sfSequence] <= offerSequence)
33 {
34 JLOG(ctx.j.trace()) << "Malformed transaction: "
35 << "Sequence " << offerSequence << " is invalid.";
36 return temBAD_SEQUENCE;
37 }
38
39 return tesSUCCESS;
40}
41
42//------------------------------------------------------------------------------
43
44TER
46{
47 auto const offerSequence = ctx_.tx[sfOfferSequence];
48
49 auto const sle = view().read(keylet::account(account_));
50 if (!sle)
51 return tefINTERNAL; // LCOV_EXCL_LINE
52
53 if (auto sleOffer = view().peek(keylet::offer(account_, offerSequence)))
54 {
55 JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
56 return offerDelete(view(), sleOffer, ctx_.registry.get().getJournal("View"));
57 }
58
59 JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
60 return tesSUCCESS;
61}
62
63} // namespace xrpl
Stream debug() const
Definition Journal.h:301
Stream trace() const
Severity stream access functions.
Definition Journal.h:295
STTx const & tx
std::reference_wrapper< ServiceRegistry > registry
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
static NotTEC preflight(PreflightContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
AccountID const account_
Definition Transactor.h:116
beast::Journal const j_
Definition Transactor.h:114
ApplyView & view()
Definition Transactor.h:132
ApplyContext & ctx_
Definition Transactor.h:112
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:243
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:197
@ tefINTERNAL
Definition TER.h:153
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
@ temBAD_SEQUENCE
Definition TER.h:84
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:582
@ tesSUCCESS
Definition TER.h:225
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:57
ReadView const & view
Definition Transactor.h:60
beast::Journal const j
Definition Transactor.h:65
State information when preflighting a tx.
Definition Transactor.h:14
beast::Journal const j
Definition Transactor.h:21