xrpld
Loading...
Searching...
No Matches
OfferCancel.cpp
1#include <xrpl/tx/transactors/dex/OfferCancel.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/helpers/OfferHelpers.h>
5#include <xrpl/protocol/Indexes.h>
6#include <xrpl/protocol/SField.h>
7#include <xrpl/protocol/STLedgerEntry.h>
8#include <xrpl/protocol/STTx.h>
9#include <xrpl/protocol/SeqProxy.h>
10#include <xrpl/protocol/TER.h>
11#include <xrpl/protocol/XRPAmount.h>
12#include <xrpl/tx/Transactor.h>
13
14namespace xrpl {
15
18{
19 if (ctx.tx[sfOfferSequence] == 0u)
20 {
21 JLOG(ctx.j.trace()) << "OfferCancel::preflight: missing sequence";
22 return temBAD_SEQUENCE;
23 }
24
25 return tesSUCCESS;
26}
27
28//------------------------------------------------------------------------------
29
30TER
32{
33 auto const id = ctx.tx[sfAccount];
34 auto const offerSequence = ctx.tx[sfOfferSequence];
35
36 auto const sle = ctx.view.read(keylet::account(id));
37 if (!sle)
38 return terNO_ACCOUNT;
39
40 if ((*sle)[sfSequence] <= offerSequence)
41 {
42 JLOG(ctx.j.trace()) << "Malformed transaction: "
43 << "Sequence " << offerSequence << " is invalid.";
44 return temBAD_SEQUENCE;
45 }
46
47 return tesSUCCESS;
48}
49
50//------------------------------------------------------------------------------
51
52TER
54{
55 auto const offerSequence = ctx_.tx[sfOfferSequence];
56
57 auto const sle = view().read(keylet::account(accountID_));
58 if (!sle)
59 return tefINTERNAL; // LCOV_EXCL_LINE
60
61 auto const seqProxy = SeqProxy::rawSequence(offerSequence);
62 if (auto sleOffer = view().peek(keylet::offer(accountID_, seqProxy)))
63 {
64 JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
65 return offerDelete(view(), sleOffer, ctx_.registry.get().getJournal("View"));
66 }
67
68 JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
69 return tesSUCCESS;
70}
71
72void
74{
75 // No transaction-specific invariants yet (future work).
76}
77
78bool
80{
81 // No transaction-specific invariants yet (future work).
82 return true;
83}
84
85} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
Stream trace() const
Severity stream access functions.
Definition Journal.h:338
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
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.
static NotTEC preflight(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
A view into a ledger.
Definition ReadView.h:41
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry const > const & const_ref
static constexpr SeqProxy rawSequence(std::uint32_t v)
Factory function to return a sequence-based SeqProxy.
Definition SeqProxy.h:62
beast::Journal const j_
Definition Transactor.h:155
ApplyView & view()
Definition Transactor.h:175
AccountID const accountID_
Definition Transactor.h:157
ApplyContext & ctx_
Definition Transactor.h:153
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Definition Indexes.cpp:276
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:198
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:213
@ tefINTERNAL
Definition TER.h:165
TER offerDelete(ApplyView &view, SLE::ref sle, beast::Journal j)
Delete an offer.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
@ temBAD_SEQUENCE
Definition TER.h:92
TERSubset< CanCvtToTER > TER
Definition TER.h:647
@ tesSUCCESS
Definition TER.h:245
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:83
ReadView const & view
Definition Transactor.h:86
beast::Journal const j
Definition Transactor.h:91
State information when preflighting a tx.
Definition Transactor.h:38
beast::Journal const j
Definition Transactor.h:45