rippled
ripple
app
tx
impl
AMMDelete.cpp
1
//------------------------------------------------------------------------------
2
/*
3
This file is part of rippled: https://github.com/ripple/rippled
4
Copyright (c) 2022 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/AMMDelete.h>
21
22
#include <ripple/app/misc/AMMUtils.h>
23
#include <ripple/ledger/Sandbox.h>
24
#include <ripple/protocol/AMMCore.h>
25
#include <ripple/protocol/Feature.h>
26
#include <ripple/protocol/STAccount.h>
27
#include <ripple/protocol/TER.h>
28
#include <ripple/protocol/TxFlags.h>
29
30
namespace
ripple
{
31
32
NotTEC
33
AMMDelete::preflight
(
PreflightContext
const
& ctx)
34
{
35
if
(!
ammEnabled
(ctx.
rules
))
36
return
temDISABLED
;
37
38
if
(
auto
const
ret =
preflight1
(ctx); !
isTesSuccess
(ret))
39
return
ret;
40
41
if
(ctx.
tx
.
getFlags
() &
tfUniversalMask
)
42
{
43
JLOG(ctx.
j
.
debug
()) <<
"AMM Delete: invalid flags."
;
44
return
temINVALID_FLAG
;
45
}
46
47
return
preflight2
(ctx);
48
}
49
50
TER
51
AMMDelete::preclaim
(
PreclaimContext
const
& ctx)
52
{
53
auto
const
ammSle =
54
ctx.
view
.
read
(
keylet::amm
(ctx.
tx
[
sfAsset
], ctx.
tx
[
sfAsset2
]));
55
if
(!ammSle)
56
{
57
JLOG(ctx.
j
.
debug
()) <<
"AMM Delete: Invalid asset pair."
;
58
return
terNO_AMM
;
59
}
60
61
auto
const
lpTokensBalance = (*ammSle)[
sfLPTokenBalance
];
62
if
(lpTokensBalance != beast::zero)
63
return
tecAMM_NOT_EMPTY
;
64
65
return
tesSUCCESS
;
66
}
67
68
TER
69
AMMDelete::doApply
()
70
{
71
// This is the ledger view that we work against. Transactions are applied
72
// as we go on processing transactions.
73
Sandbox
sb(&
ctx_
.
view
());
74
75
auto
const
ter =
76
deleteAMMAccount
(sb,
ctx_
.
tx
[
sfAsset
],
ctx_
.
tx
[
sfAsset2
],
j_
);
77
if
(ter ==
tesSUCCESS
|| ter ==
tecINCOMPLETE
)
78
sb.
apply
(
ctx_
.
rawView
());
79
80
return
ter;
81
}
82
83
}
// namespace ripple
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition:
Transactor.cpp:130
ripple::sfAsset
const SF_ISSUE sfAsset
ripple::PreclaimContext::view
ReadView const & view
Definition:
Transactor.h:56
ripple::PreclaimContext::j
const beast::Journal j
Definition:
Transactor.h:60
ripple::Transactor::j_
const beast::Journal j_
Definition:
Transactor.h:89
ripple::isTesSuccess
bool isTesSuccess(TER x)
Definition:
TER.h:608
ripple::Sandbox::apply
void apply(RawView &to)
Definition:
Sandbox.h:55
ripple::sfLPTokenBalance
const SF_AMOUNT sfLPTokenBalance
ripple::AMMDelete::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition:
AMMDelete.cpp:51
ripple::ammEnabled
bool ammEnabled(Rules const &)
Return true if required AMM amendments are enabled.
Definition:
AMMCore.cpp:126
ripple::keylet::amm
Keylet amm(Issue const &issue1, Issue const &issue2) noexcept
AMM entry.
Definition:
Indexes.cpp:375
ripple::ApplyContext::rawView
RawView & rawView()
Definition:
ApplyContext.h:67
ripple::PreflightContext::j
const beast::Journal j
Definition:
Transactor.h:38
ripple::tecINCOMPLETE
@ tecINCOMPLETE
Definition:
TER.h:305
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition:
Transactor.cpp:78
ripple::temINVALID_FLAG
@ temINVALID_FLAG
Definition:
TER.h:109
ripple::tecAMM_NOT_EMPTY
@ tecAMM_NOT_EMPTY
Definition:
TER.h:303
ripple::sfAsset2
const SF_ISSUE sfAsset2
ripple::TERSubset< CanCvtToTER >
ripple::Sandbox
Discardable, editable view to a ledger.
Definition:
Sandbox.h:34
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::ApplyContext::view
ApplyView & view()
Definition:
ApplyContext.h:54
ripple::AMMDelete::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition:
AMMDelete.cpp:33
ripple::PreclaimContext::tx
STTx const & tx
Definition:
Transactor.h:58
ripple::PreclaimContext
State information when determining if a tx is likely to claim a fee.
Definition:
Transactor.h:52
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition:
RCLCensorshipDetector.h:29
ripple::temDISABLED
@ temDISABLED
Definition:
TER.h:112
ripple::terNO_AMM
@ terNO_AMM
Definition:
TER.h:210
ripple::deleteAMMAccount
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition:
AMMUtils.cpp:234
ripple::AMMDelete::doApply
TER doApply() override
Definition:
AMMDelete.cpp:69
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition:
Transactor.h:88
beast::Journal::debug
Stream debug() const
Definition:
Journal.h:315
ripple::PreflightContext::tx
STTx const & tx
Definition:
Transactor.h:35
ripple::PreflightContext
State information when preflighting a tx.
Definition:
Transactor.h:31
ripple::PreflightContext::rules
const Rules rules
Definition:
Transactor.h:36
ripple::tfUniversalMask
constexpr std::uint32_t tfUniversalMask
Definition:
TxFlags.h:60
ripple::tesSUCCESS
@ tesSUCCESS
Definition:
TER.h:225
ripple::ApplyContext::tx
STTx const & tx
Definition:
ApplyContext.h:48
ripple::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition:
TER.h:539
Generated by
1.8.17