rippled
Loading...
Searching...
No Matches
AMMDelete.cpp
1#include <xrpld/app/misc/AMMUtils.h>
2#include <xrpld/app/tx/detail/AMMDelete.h>
3
4#include <xrpl/ledger/Sandbox.h>
5#include <xrpl/protocol/AMMCore.h>
6#include <xrpl/protocol/TER.h>
7#include <xrpl/protocol/TxFlags.h>
8
9namespace xrpl {
10
11bool
16
19{
20 return tesSUCCESS;
21}
22
23TER
25{
26 auto const ammSle = ctx.view.read(keylet::amm(ctx.tx[sfAsset], ctx.tx[sfAsset2]));
27 if (!ammSle)
28 {
29 JLOG(ctx.j.debug()) << "AMM Delete: Invalid asset pair.";
30 return terNO_AMM;
31 }
32
33 auto const lpTokensBalance = (*ammSle)[sfLPTokenBalance];
34 if (lpTokensBalance != beast::zero)
35 return tecAMM_NOT_EMPTY;
36
37 return tesSUCCESS;
38}
39
40TER
42{
43 // This is the ledger view that we work against. Transactions are applied
44 // as we go on processing transactions.
45 Sandbox sb(&ctx_.view());
46
47 auto const ter = deleteAMMAccount(sb, ctx_.tx[sfAsset].get<Issue>(), ctx_.tx[sfAsset2].get<Issue>(), j_);
48 if (ter == tesSUCCESS || ter == tecINCOMPLETE)
49 sb.apply(ctx_.rawView());
50
51 return ter;
52}
53
54} // namespace xrpl
Stream debug() const
Definition Journal.h:301
static TER preclaim(PreclaimContext const &ctx)
Definition AMMDelete.cpp:24
TER doApply() override
Definition AMMDelete.cpp:41
static bool checkExtraFeatures(PreflightContext const &ctx)
Definition AMMDelete.cpp:12
static NotTEC preflight(PreflightContext const &ctx)
Definition AMMDelete.cpp:18
STTx const & tx
RawView & rawView()
ApplyView & view()
A currency issued by an account.
Definition Issue.h:14
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:16
void apply(RawView &to)
Definition Sandbox.h:36
beast::Journal const j_
Definition Transactor.h:111
ApplyContext & ctx_
Definition Transactor.h:109
Keylet amm(Asset const &issue1, Asset const &issue2) noexcept
AMM entry.
Definition Indexes.cpp:393
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ terNO_AMM
Definition TER.h:208
TER deleteAMMAccount(Sandbox &view, Issue const &asset, Issue const &asset2, beast::Journal j)
Delete trustlines to AMM.
Definition AMMUtils.cpp:222
bool ammEnabled(Rules const &)
Return true if required AMM amendments are enabled.
Definition AMMCore.cpp:95
@ tecAMM_NOT_EMPTY
Definition TER.h:315
@ tecINCOMPLETE
Definition TER.h:317
@ tesSUCCESS
Definition TER.h:226
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:54
ReadView const & view
Definition Transactor.h:57
beast::Journal const j
Definition Transactor.h:62
State information when preflighting a tx.
Definition Transactor.h:16