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 <xrpld/ledger/View.h>
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/TxFlags.h>
25#include <xrpl/protocol/st.h>
26
27namespace ripple {
28
31{
32 if (!ctx.rules.enabled(featureMPTokensV1))
33 return temDISABLED;
34
35 // check flags
36 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
37 return ret;
38
40 return temINVALID_FLAG;
41
42 return preflight2(ctx);
43}
44
45TER
47{
48 // ensure that issuance exists
49 auto const sleMPT =
50 ctx.view.read(keylet::mptIssuance(ctx.tx[sfMPTokenIssuanceID]));
51 if (!sleMPT)
53
54 // ensure it is issued by the tx submitter
55 if ((*sleMPT)[sfIssuer] != ctx.tx[sfAccount])
56 return tecNO_PERMISSION;
57
58 // ensure it has no outstanding balances
59 if ((*sleMPT)[~sfOutstandingAmount] != 0)
60 return tecHAS_OBLIGATIONS;
61
62 return tesSUCCESS;
63}
64
65TER
67{
68 auto const mpt =
69 view().peek(keylet::mptIssuance(ctx_.tx[sfMPTokenIssuanceID]));
70 if (account_ != mpt->getAccountID(sfIssuer))
71 return tecINTERNAL;
72
73 if (!view().dirRemove(
74 keylet::ownerDir(account_), (*mpt)[sfOwnerNode], mpt->key(), false))
75 return tefBAD_LEDGER;
76
77 view().erase(mpt);
78
80
81 return tesSUCCESS;
82}
83
84} // 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:122
std::uint32_t getFlags() const
Definition: STObject.cpp:507
AccountID const account_
Definition: Transactor.h:91
ApplyView & view()
Definition: Transactor.h:107
beast::Journal const j_
Definition: Transactor.h:89
ApplyContext & ctx_
Definition: Transactor.h:88
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Definition: Indexes.cpp:494
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:160
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition: Indexes.cpp:350
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:656
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:82
@ 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:134
@ tecOBJECT_NOT_FOUND
Definition: TER.h:313
@ tecINTERNAL
Definition: TER.h:297
@ tecNO_PERMISSION
Definition: TER.h:292
@ tecHAS_OBLIGATIONS
Definition: TER.h:304
@ tesSUCCESS
Definition: TER.h:242
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:587
constexpr std::uint32_t const tfMPTokenIssuanceDestroyMask
Definition: TxFlags.h:160
@ 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:53
ReadView const & view
Definition: Transactor.h:56
State information when preflighting a tx.
Definition: Transactor.h:32