rippled
Loading...
Searching...
No Matches
xrpld
app
tx
detail
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
26
namespace
ripple
{
27
28
NotTEC
29
CancelOffer::preflight
(
PreflightContext
const
& ctx)
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
()) <<
"Malformed transaction: "
39
<<
"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
54
TER
55
CancelOffer::preclaim
(
PreclaimContext
const
& ctx)
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: "
67
<<
"Sequence "
<< offerSequence <<
" is invalid."
;
68
return
temBAD_SEQUENCE
;
69
}
70
71
return
tesSUCCESS
;
72
}
73
74
//------------------------------------------------------------------------------
75
76
TER
77
CancelOffer::doApply
()
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
beast::Journal::debug
Stream debug() const
Definition
Journal.h:328
beast::Journal::trace
Stream trace() const
Severity stream access functions.
Definition
Journal.h:322
ripple::Application::journal
virtual beast::Journal journal(std::string const &name)=0
ripple::ApplyContext::app
Application & app
Definition
ApplyContext.h:71
ripple::ApplyContext::tx
STTx const & tx
Definition
ApplyContext.h:72
ripple::CancelOffer::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition
CancelOffer.cpp:55
ripple::CancelOffer::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition
CancelOffer.cpp:29
ripple::CancelOffer::doApply
TER doApply() override
Definition
CancelOffer.cpp:77
ripple::ReadView::read
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
ripple::STObject::getFlags
std::uint32_t getFlags() const
Definition
STObject.cpp:537
ripple::TERSubset< CanCvtToTER >
ripple::Transactor::account_
AccountID const account_
Definition
Transactor.h:145
ripple::Transactor::view
ApplyView & view()
Definition
Transactor.h:161
ripple::Transactor::j_
beast::Journal const j_
Definition
Transactor.h:143
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition
Transactor.h:141
ripple::keylet::account
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition
Indexes.cpp:184
ripple::keylet::offer
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition
Indexes.cpp:274
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:25
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition
Transactor.cpp:91
ripple::tefINTERNAL
@ tefINTERNAL
Definition
TER.h:173
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition
Transactor.cpp:160
ripple::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:244
ripple::isTesSuccess
bool isTesSuccess(TER x) noexcept
Definition
TER.h:674
ripple::tfUniversalMask
constexpr std::uint32_t tfUniversalMask
Definition
TxFlags.h:63
ripple::terNO_ACCOUNT
@ terNO_ACCOUNT
Definition
TER.h:217
ripple::offerDelete
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
Definition
View.cpp:1634
ripple::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition
TER.h:605
ripple::temBAD_SEQUENCE
@ temBAD_SEQUENCE
Definition
TER.h:104
ripple::temINVALID_FLAG
@ temINVALID_FLAG
Definition
TER.h:111
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition
Transactor.h:80
ripple::PreclaimContext::view
ReadView const & view
Definition
Transactor.h:83
ripple::PreclaimContext::tx
STTx const & tx
Definition
Transactor.h:86
ripple::PreclaimContext::j
beast::Journal const j
Definition
Transactor.h:88
ripple::PreflightContext
State information when preflighting a tx.
Definition
Transactor.h:35
ripple::PreflightContext::j
beast::Journal const j
Definition
Transactor.h:42
ripple::PreflightContext::tx
STTx const & tx
Definition
Transactor.h:38
Generated by
1.9.8