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#include <xrpld/ledger/View.h>
22
23#include <xrpl/basics/Log.h>
24#include <xrpl/protocol/st.h>
25
26namespace ripple {
27
30{
31 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
32 return ret;
33
34 auto const uTxFlags = ctx.tx.getFlags();
35
36 if (uTxFlags & tfUniversalMask)
37 {
38 JLOG(ctx.j.trace())
39 << "Malformed transaction: " << "Invalid flags set.";
40 return temINVALID_FLAG;
41 }
42
43 if (!ctx.tx[sfOfferSequence])
44 {
45 JLOG(ctx.j.trace()) << "CancelOffer::preflight: missing sequence";
46 return temBAD_SEQUENCE;
47 }
48
49 return preflight2(ctx);
50}
51
52//------------------------------------------------------------------------------
53
54TER
56{
57 auto const id = ctx.tx[sfAccount];
58 auto const offerSequence = ctx.tx[sfOfferSequence];
59
60 auto const sle = ctx.view.read(keylet::account(id));
61 if (!sle)
62 return terNO_ACCOUNT;
63
64 if ((*sle)[sfSequence] <= offerSequence)
65 {
66 JLOG(ctx.j.trace()) << "Malformed transaction: " << "Sequence "
67 << offerSequence << " is invalid.";
68 return temBAD_SEQUENCE;
69 }
70
71 return tesSUCCESS;
72}
73
74//------------------------------------------------------------------------------
75
76TER
78{
79 auto const offerSequence = ctx_.tx[sfOfferSequence];
80
81 auto const sle = view().read(keylet::account(account_));
82 if (!sle)
83 return tefINTERNAL;
84
85 if (auto sleOffer = view().peek(keylet::offer(account_, offerSequence)))
86 {
87 JLOG(j_.debug()) << "Trying to cancel offer #" << offerSequence;
88 return offerDelete(view(), sleOffer, ctx_.app.journal("View"));
89 }
90
91 JLOG(j_.debug()) << "Offer #" << offerSequence << " can't be found.";
92 return tesSUCCESS;
93}
94
95} // 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
Definition: ApplyContext.h:48
static TER preclaim(PreclaimContext const &ctx)
Definition: CancelOffer.cpp:55
static NotTEC preflight(PreflightContext const &ctx)
Definition: CancelOffer.cpp:29
TER doApply() override
Definition: CancelOffer.cpp:77
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
std::uint32_t getFlags() const
Definition: STObject.cpp:537
AccountID const account_
Definition: Transactor.h:93
ApplyView & view()
Definition: Transactor.h:109
beast::Journal const j_
Definition: Transactor.h:91
ApplyContext & ctx_
Definition: Transactor.h:90
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:176
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:266
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isTesSuccess(TER x)
Definition: TER.h:656
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:83
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition: View.cpp:1092
@ tefINTERNAL
Definition: TER.h:173
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:144
@ tesSUCCESS
Definition: TER.h:242
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:62
@ terNO_ACCOUNT
Definition: TER.h:217
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:587
@ temBAD_SEQUENCE
Definition: TER.h:104
@ temINVALID_FLAG
Definition: TER.h:111
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:55
ReadView const & view
Definition: Transactor.h:58
beast::Journal const j
Definition: Transactor.h:62
State information when preflighting a tx.
Definition: Transactor.h:34
beast::Journal const j
Definition: Transactor.h:40