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/TER.h>
10#include <xrpl/protocol/XRPAmount.h>
11#include <xrpl/tx/Transactor.h>
12
13namespace xrpl {
14
17{
18 if (ctx.tx[sfOfferSequence] == 0u)
19 {
20 JLOG(ctx.j.trace()) << "OfferCancel::preflight: missing sequence";
21 return temBAD_SEQUENCE;
22 }
23
24 return tesSUCCESS;
25}
26
27//------------------------------------------------------------------------------
28
29TER
31{
32 auto const id = ctx.tx[sfAccount];
33 auto const offerSequence = ctx.tx[sfOfferSequence];
34
35 auto const sle = ctx.view.read(keylet::account(id));
36 if (!sle)
37 return terNO_ACCOUNT;
38
39 if ((*sle)[sfSequence] <= offerSequence)
40 {
41 JLOG(ctx.j.trace()) << "Malformed transaction: "
42 << "Sequence " << offerSequence << " is invalid.";
43 return temBAD_SEQUENCE;
44 }
45
46 return tesSUCCESS;
47}
48
49//------------------------------------------------------------------------------
50
51TER
53{
54 auto const offerSequence = ctx_.tx[sfOfferSequence];
55
56 auto const sle = view().read(keylet::account(accountID_));
57 if (!sle)
58 return tefINTERNAL; // LCOV_EXCL_LINE
59
60 if (auto sleOffer = view().peek(keylet::offer(accountID_, offerSequence)))
61 {
62 JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
63 return offerDelete(view(), sleOffer, ctx_.registry.get().getJournal("View"));
64 }
65
66 JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
67 return tesSUCCESS;
68}
69
70void
72{
73 // No transaction-specific invariants yet (future work).
74}
75
76bool
78{
79 // No transaction-specific invariants yet (future work).
80 return true;
81}
82
83} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Stream trace() const
Severity stream access functions.
Definition Journal.h:291
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:31
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
beast::Journal const j_
Definition Transactor.h:118
ApplyView & view()
Definition Transactor.h:136
AccountID const accountID_
Definition Transactor.h:120
ApplyContext & ctx_
Definition Transactor.h:116
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:264
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ terNO_ACCOUNT
Definition TER.h:209
@ tefINTERNAL
Definition TER.h:163
TER offerDelete(ApplyView &view, SLE::ref sle, beast::Journal j)
Delete an offer.
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
@ temBAD_SEQUENCE
Definition TER.h:90
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tesSUCCESS
Definition TER.h:240
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:18
beast::Journal const j
Definition Transactor.h:25