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