rippled
Loading...
Searching...
No Matches
CancelOffer.cpp
1#include <xrpld/app/tx/detail/CancelOffer.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/View.h>
5#include <xrpl/protocol/st.h>
6
7namespace ripple {
8
11{
12 if (!ctx.tx[sfOfferSequence])
13 {
14 JLOG(ctx.j.trace()) << "CancelOffer::preflight: missing sequence";
15 return temBAD_SEQUENCE;
16 }
17
18 return tesSUCCESS;
19}
20
21//------------------------------------------------------------------------------
22
23TER
25{
26 auto const id = ctx.tx[sfAccount];
27 auto const offerSequence = ctx.tx[sfOfferSequence];
28
29 auto const sle = ctx.view.read(keylet::account(id));
30 if (!sle)
31 return terNO_ACCOUNT;
32
33 if ((*sle)[sfSequence] <= offerSequence)
34 {
35 JLOG(ctx.j.trace()) << "Malformed transaction: "
36 << "Sequence " << offerSequence << " is invalid.";
37 return temBAD_SEQUENCE;
38 }
39
40 return tesSUCCESS;
41}
42
43//------------------------------------------------------------------------------
44
45TER
47{
48 auto const offerSequence = ctx_.tx[sfOfferSequence];
49
50 auto const sle = view().read(keylet::account(account_));
51 if (!sle)
52 return tefINTERNAL; // LCOV_EXCL_LINE
53
54 if (auto sleOffer = view().peek(keylet::offer(account_, offerSequence)))
55 {
56 JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
57 return offerDelete(view(), sleOffer, ctx_.app.journal("View"));
58 }
59
60 JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
61 return tesSUCCESS;
62}
63
64} // namespace ripple
Stream debug() const
Definition Journal.h:309
Stream trace() const
Severity stream access functions.
Definition Journal.h:303
virtual beast::Journal journal(std::string const &name)=0
Application & app
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
TER doApply() override
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:128
ApplyView & view()
Definition Transactor.h:144
beast::Journal const j_
Definition Transactor.h:126
ApplyContext & ctx_
Definition Transactor.h:124
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:255
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ tefINTERNAL
Definition TER.h:154
@ tesSUCCESS
Definition TER.h:226
@ terNO_ACCOUNT
Definition TER.h:198
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition View.cpp:1628
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:590
@ temBAD_SEQUENCE
Definition TER.h:85
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
ReadView const & view
Definition Transactor.h:64
beast::Journal const j
Definition Transactor.h:69
State information when preflighting a tx.
Definition Transactor.h:16
beast::Journal const j
Definition Transactor.h:23