rippled
Loading...
Searching...
No Matches
MPTokenIssuanceDestroy.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 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/tx/detail/MPTokenIssuanceDestroy.h>
21
22#include <xrpl/ledger/View.h>
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/TxFlags.h>
25
26namespace ripple {
27
33
39
40TER
42{
43 // ensure that issuance exists
44 auto const sleMPT =
45 ctx.view.read(keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID]));
46 if (!sleMPT)
48
49 // ensure it is issued by the tx submitter
50 if ((*sleMPT)[sfIssuer] != ctx.tx[sfAccount])
51 return tecNO_PERMISSION;
52
53 // ensure it has no outstanding balances
54 if ((*sleMPT)[sfOutstandingAmount] != 0)
55 return tecHAS_OBLIGATIONS;
56
57 if ((*sleMPT)[~sfLockedAmount].value_or(0) != 0)
58 return tecHAS_OBLIGATIONS; // LCOV_EXCL_LINE
59
60 return tesSUCCESS;
61}
62
63TER
65{
66 auto const mpt =
67 view().peek(keylet::mptIssuance(ctx_.tx[sfMPTokenIssuanceID]));
68 if (account_ != mpt->getAccountID(sfIssuer))
69 return tecINTERNAL;
70
71 if (!view().dirRemove(
72 keylet::ownerDir(account_), (*mpt)[sfOwnerNode], mpt->key(), false))
73 return tefBAD_LEDGER;
74
75 view().erase(mpt);
76
78
79 return tesSUCCESS;
80}
81
82} // namespace ripple
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
AccountID const account_
Definition Transactor.h:147
ApplyView & view()
Definition Transactor.h:163
beast::Journal const j_
Definition Transactor.h:145
ApplyContext & ctx_
Definition Transactor.h:143
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Definition Indexes.cpp:526
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:184
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:374
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:1029
@ tefBAD_LEDGER
Definition TER.h:170
@ tecOBJECT_NOT_FOUND
Definition TER.h:326
@ tecINTERNAL
Definition TER.h:310
@ tecNO_PERMISSION
Definition TER.h:305
@ tecHAS_OBLIGATIONS
Definition TER.h:317
@ tesSUCCESS
Definition TER.h:244
constexpr std::uint32_t const tfMPTokenIssuanceDestroyMask
Definition TxFlags.h:201
uint256 key
Definition Keylet.h:40
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:80
ReadView const & view
Definition Transactor.h:83
State information when preflighting a tx.
Definition Transactor.h:35