rippled
Loading...
Searching...
No Matches
CancelOffer.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/tx/detail/CancelOffer.h>
21
22#include <xrpl/basics/Log.h>
23#include <xrpl/ledger/View.h>
24#include <xrpl/protocol/st.h>
25
26namespace ripple {
27
30{
31 if (!ctx.tx[sfOfferSequence])
32 {
33 JLOG(ctx.j.trace()) << "CancelOffer::preflight: missing sequence";
34 return temBAD_SEQUENCE;
35 }
36
37 return tesSUCCESS;
38}
39
40//------------------------------------------------------------------------------
41
42TER
44{
45 auto const id = ctx.tx[sfAccount];
46 auto const offerSequence = ctx.tx[sfOfferSequence];
47
48 auto const sle = ctx.view.read(keylet::account(id));
49 if (!sle)
50 return terNO_ACCOUNT;
51
52 if ((*sle)[sfSequence] <= offerSequence)
53 {
54 JLOG(ctx.j.trace()) << "Malformed transaction: "
55 << "Sequence " << offerSequence << " is invalid.";
56 return temBAD_SEQUENCE;
57 }
58
59 return tesSUCCESS;
60}
61
62//------------------------------------------------------------------------------
63
64TER
66{
67 auto const offerSequence = ctx_.tx[sfOfferSequence];
68
69 auto const sle = view().read(keylet::account(account_));
70 if (!sle)
71 return tefINTERNAL; // LCOV_EXCL_LINE
72
73 if (auto sleOffer = view().peek(keylet::offer(account_, offerSequence)))
74 {
75 JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
76 return offerDelete(view(), sleOffer, ctx_.app.journal("View"));
77 }
78
79 JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
80 return tesSUCCESS;
81}
82
83} // namespace ripple
Stream debug() const
Definition Journal.h:328
Stream trace() const
Severity stream access functions.
Definition Journal.h:322
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:147
ApplyView & view()
Definition Transactor.h:163
beast::Journal const j_
Definition Transactor.h:145
ApplyContext & ctx_
Definition Transactor.h:143
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:184
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:274
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
@ tefINTERNAL
Definition TER.h:173
@ tesSUCCESS
Definition TER.h:245
@ terNO_ACCOUNT
Definition TER.h:217
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition View.cpp:1647
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:609
@ temBAD_SEQUENCE
Definition TER.h:104
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
ReadView const & view
Definition Transactor.h:83
beast::Journal const j
Definition Transactor.h:88
State information when preflighting a tx.
Definition Transactor.h:35
beast::Journal const j
Definition Transactor.h:42