rippled
Loading...
Searching...
No Matches
xrpld
app
tx
detail
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 <xrpld/app/misc/AMMUtils.h>
21
#include <xrpld/app/tx/detail/AMMDelete.h>
22
23
#include <xrpl/ledger/Sandbox.h>
24
#include <xrpl/protocol/AMMCore.h>
25
#include <xrpl/protocol/TER.h>
26
#include <xrpl/protocol/TxFlags.h>
27
28
namespace
ripple
{
29
30
NotTEC
31
AMMDelete::preflight
(
PreflightContext
const
& ctx)
32
{
33
if
(!
ammEnabled
(ctx.
rules
))
34
return
temDISABLED
;
35
36
if
(
auto
const
ret =
preflight1
(ctx); !
isTesSuccess
(ret))
37
return
ret;
38
39
if
(ctx.
tx
.
getFlags
() &
tfUniversalMask
)
40
{
41
JLOG(ctx.
j
.
debug
()) <<
"AMM Delete: invalid flags."
;
42
return
temINVALID_FLAG
;
43
}
44
45
return
preflight2
(ctx);
46
}
47
48
TER
49
AMMDelete::preclaim
(
PreclaimContext
const
& ctx)
50
{
51
auto
const
ammSle =
52
ctx.
view
.
read
(
keylet::amm
(ctx.
tx
[sfAsset], ctx.
tx
[sfAsset2]));
53
if
(!ammSle)
54
{
55
JLOG(ctx.
j
.
debug
()) <<
"AMM Delete: Invalid asset pair."
;
56
return
terNO_AMM
;
57
}
58
59
auto
const
lpTokensBalance = (*ammSle)[sfLPTokenBalance];
60
if
(lpTokensBalance != beast::zero)
61
return
tecAMM_NOT_EMPTY
;
62
63
return
tesSUCCESS
;
64
}
65
66
TER
67
AMMDelete::doApply
()
68
{
69
// This is the ledger view that we work against. Transactions are applied
70
// as we go on processing transactions.
71
Sandbox
sb(&
ctx_
.
view
());
72
73
auto
const
ter =
deleteAMMAccount
(
74
sb,
ctx_
.
tx
[sfAsset].get<
Issue
>(),
ctx_
.
tx
[sfAsset2].get<
Issue
>(),
j_
);
75
if
(ter ==
tesSUCCESS
|| ter ==
tecINCOMPLETE
)
76
sb.
apply
(
ctx_
.
rawView
());
77
78
return
ter;
79
}
80
81
}
// namespace ripple
beast::Journal::debug
Stream debug() const
Definition
Journal.h:328
ripple::AMMDelete::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition
AMMDelete.cpp:31
ripple::AMMDelete::doApply
TER doApply() override
Definition
AMMDelete.cpp:67
ripple::AMMDelete::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition
AMMDelete.cpp:49
ripple::ApplyContext::rawView
RawView & rawView()
Definition
ApplyContext.h:91
ripple::ApplyContext::view
ApplyView & view()
Definition
ApplyContext.h:78
ripple::ApplyContext::tx
STTx const & tx
Definition
ApplyContext.h:72
ripple::Issue
A currency issued by an account.
Definition
Issue.h:33
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::Sandbox
Discardable, editable view to a ledger.
Definition
Sandbox.h:35
ripple::Sandbox::apply
void apply(RawView &to)
Definition
Sandbox.h:55
ripple::TERSubset< CanCvtToTER >
ripple::Transactor::j_
beast::Journal const j_
Definition
Transactor.h:143
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition
Transactor.h:141
ripple::keylet::amm
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition
Indexes.cpp:446
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition
algorithm.h:25
ripple::deleteAMMAccount
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition
AMMUtils.cpp:283
ripple::ammEnabled
bool ammEnabled(Rules const &)
Return true if required AMM amendments are enabled.
Definition
AMMCore.cpp:129
ripple::preflight1
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition
Transactor.cpp:91
ripple::preflight2
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition
Transactor.cpp:160
ripple::tecINCOMPLETE
@ tecINCOMPLETE
Definition
TER.h:335
ripple::tecAMM_NOT_EMPTY
@ tecAMM_NOT_EMPTY
Definition
TER.h:333
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_AMM
@ terNO_AMM
Definition
TER.h:227
ripple::NotTEC
TERSubset< CanCvtToNotTEC > NotTEC
Definition
TER.h:605
ripple::temINVALID_FLAG
@ temINVALID_FLAG
Definition
TER.h:111
ripple::temDISABLED
@ temDISABLED
Definition
TER.h:114
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::rules
Rules const rules
Definition
Transactor.h:39
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