rippled
Loading...
Searching...
No Matches
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
28namespace ripple {
29
30bool
35
38{
39 return tesSUCCESS;
40}
41
42TER
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
60TER
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
Stream debug() const
Definition Journal.h:328
static NotTEC preflight(PreflightContext const &ctx)
Definition AMMDelete.cpp:37
TER doApply() override
Definition AMMDelete.cpp:61
static TER preclaim(PreclaimContext const &ctx)
Definition AMMDelete.cpp:43
static bool checkExtraFeatures(PreflightContext const &ctx)
Definition AMMDelete.cpp:31
ApplyView & view()
A currency issued by an account.
Definition Issue.h:33
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Discardable, editable view to a ledger.
Definition Sandbox.h:35
void apply(RawView &to)
Definition Sandbox.h:55
beast::Journal const j_
Definition Transactor.h:145
ApplyContext & ctx_
Definition Transactor.h:143
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:446
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition AMMUtils.cpp:283
bool ammEnabled(Rules const &)
Return true if required AMM amendments are enabled.
Definition AMMCore.cpp:129
@ tecINCOMPLETE
Definition TER.h:335
@ tecAMM_NOT_EMPTY
Definition TER.h:333
@ tesSUCCESS
Definition TER.h:244
@ terNO_AMM
Definition TER.h:227
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
ReadView const & view
Definition Transactor.h:83
beast::Journal const j
Definition Transactor.h:88
State information when preflighting a tx.
Definition Transactor.h:35