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
bool
31
AMMDelete::checkExtraFeatures
(
PreflightContext
const
& ctx)
32
{
33
return
ammEnabled
(ctx.
rules
);
34
}
35
36
NotTEC
37
AMMDelete::preflight
(
PreflightContext
const
& ctx)
38
{
39
return
tesSUCCESS
;
40
}
41
42
TER
43
AMMDelete::preclaim
(
PreclaimContext
const
& ctx)
44
{
45
auto
const
ammSle =
46
ctx.
view
.
read
(
keylet::amm
(ctx.
tx
[sfAsset], ctx.
tx
[sfAsset2]));
47
if
(!ammSle)
48
{
49
JLOG(ctx.
j
.
debug
()) <<
"AMM Delete: Invalid asset pair."
;
50
return
terNO_AMM
;
51
}
52
53
auto
const
lpTokensBalance = (*ammSle)[sfLPTokenBalance];
54
if
(lpTokensBalance != beast::zero)
55
return
tecAMM_NOT_EMPTY
;
56
57
return
tesSUCCESS
;
58
}
59
60
TER
61
AMMDelete::doApply
()
62
{
63
// This is the ledger view that we work against. Transactions are applied
64
// as we go on processing transactions.
65
Sandbox
sb(&
ctx_
.
view
());
66
67
auto
const
ter =
deleteAMMAccount
(
68
sb,
ctx_
.
tx
[sfAsset].get<
Issue
>(),
ctx_
.
tx
[sfAsset2].get<
Issue
>(),
j_
);
69
if
(ter ==
tesSUCCESS
|| ter ==
tecINCOMPLETE
)
70
sb.
apply
(
ctx_
.
rawView
());
71
72
return
ter;
73
}
74
75
}
// namespace ripple
beast::Journal::debug
Stream debug() const
Definition
Journal.h:328
ripple::AMMDelete::preflight
static NotTEC preflight(PreflightContext const &ctx)
Definition
AMMDelete.cpp:37
ripple::AMMDelete::doApply
TER doApply() override
Definition
AMMDelete.cpp:61
ripple::AMMDelete::preclaim
static TER preclaim(PreclaimContext const &ctx)
Definition
AMMDelete.cpp:43
ripple::AMMDelete::checkExtraFeatures
static bool checkExtraFeatures(PreflightContext const &ctx)
Definition
AMMDelete.cpp:31
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::Sandbox
Discardable, editable view to a ledger.
Definition
Sandbox.h:35
ripple::Sandbox::apply
void apply(RawView &to)
Definition
Sandbox.h:55
ripple::TERSubset
Definition
TER.h:411
ripple::Transactor::j_
beast::Journal const j_
Definition
Transactor.h:145
ripple::Transactor::ctx_
ApplyContext & ctx_
Definition
Transactor.h:143
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::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::terNO_AMM
@ terNO_AMM
Definition
TER.h:227
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
Generated by
1.9.8