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#include <xrpld/ledger/View.h>
22
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/TxFlags.h>
25
26namespace ripple {
27
30{
31 if (!ctx.rules.enabled(featureMPTokensV1))
32 return temDISABLED;
33
34 // check flags
35 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
36 return ret;
37
39 return temINVALID_FLAG;
40
41 return preflight2(ctx);
42}
43
44TER
46{
47 // ensure that issuance exists
48 auto const sleMPT =
49 ctx.view.read(keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID]));
50 if (!sleMPT)
52
53 // ensure it is issued by the tx submitter
54 if ((*sleMPT)[sfIssuer] != ctx.tx[sfAccount])
55 return tecNO_PERMISSION;
56
57 // ensure it has no outstanding balances
58 if ((*sleMPT)[sfOutstandingAmount] != 0)
59 return tecHAS_OBLIGATIONS;
60
61 return tesSUCCESS;
62}
63
64TER
66{
67 auto const mpt =
68 view().peek(keylet::mptIssuance(ctx_.tx[sfMPTokenIssuanceID]));
69 if (account_ != mpt->getAccountID(sfIssuer))
70 return tecINTERNAL;
71
72 if (!view().dirRemove(
73 keylet::ownerDir(account_), (*mpt)[sfOwnerNode], mpt->key(), false))
74 return tefBAD_LEDGER;
75
76 view().erase(mpt);
77
79
80 return tesSUCCESS;
81}
82
83} // 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 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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
std::uint32_t getFlags() const
Definition: STObject.cpp:537
AccountID const account_
Definition: Transactor.h:93
ApplyView & view()
Definition: Transactor.h:109
beast::Journal const j_
Definition: Transactor.h:91
ApplyContext & ctx_
Definition: Transactor.h:90
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Definition: Indexes.cpp:519
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:177
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:367
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
bool isTesSuccess(TER x)
Definition: TER.h:672
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:83
@ tefBAD_LEDGER
Definition: TER.h:170
static bool adjustOwnerCount(ApplyContext &ctx, int count)
Definition: SetOracle.cpp:186
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:144
@ 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
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:603
constexpr std::uint32_t const tfMPTokenIssuanceDestroyMask
Definition: TxFlags.h:169
@ temINVALID_FLAG
Definition: TER.h:111
@ temDISABLED
Definition: TER.h:114
uint256 key
Definition: Keylet.h:40
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:55
ReadView const & view
Definition: Transactor.h:58
State information when preflighting a tx.
Definition: Transactor.h:34