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
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
48TER
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
66TER
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
Stream debug() const
Definition Journal.h:328
static NotTEC preflight(PreflightContext const &ctx)
Definition AMMDelete.cpp:31
TER doApply() override
Definition AMMDelete.cpp:67
static TER preclaim(PreclaimContext const &ctx)
Definition AMMDelete.cpp:49
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.
std::uint32_t getFlags() const
Definition STObject.cpp:537
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:143
ApplyContext & ctx_
Definition Transactor.h:141
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
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
@ tecINCOMPLETE
Definition TER.h:335
@ tecAMM_NOT_EMPTY
Definition TER.h:333
@ tesSUCCESS
Definition TER.h:244
bool isTesSuccess(TER x) noexcept
Definition TER.h:674
constexpr std::uint32_t tfUniversalMask
Definition TxFlags.h:63
@ terNO_AMM
Definition TER.h:227
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:605
@ temINVALID_FLAG
Definition TER.h:111
@ temDISABLED
Definition TER.h:114
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
beast::Journal const j
Definition Transactor.h:42