xrpld
Loading...
Searching...
No Matches
MPTokenIssuanceDestroy.cpp
1#include <xrpl/tx/transactors/token/MPTokenIssuanceDestroy.h>
2
3#include <xrpl/ledger/helpers/AccountRootHelpers.h>
4#include <xrpl/protocol/Indexes.h>
5#include <xrpl/protocol/SField.h>
6#include <xrpl/protocol/STLedgerEntry.h>
7#include <xrpl/protocol/STTx.h>
8#include <xrpl/protocol/TER.h>
9#include <xrpl/protocol/XRPAmount.h>
10#include <xrpl/tx/Transactor.h>
11
12namespace xrpl {
13
19
20TER
22{
23 // ensure that issuance exists
24 auto const sleMPT = ctx.view.read(keylet::mptokenIssuance(ctx.tx[sfMPTokenIssuanceID]));
25 if (!sleMPT)
27
28 // ensure it is issued by the tx submitter
29 if ((*sleMPT)[sfIssuer] != ctx.tx[sfAccount])
30 return tecNO_PERMISSION;
31
32 // ensure it has no outstanding balances
33 if ((*sleMPT)[sfOutstandingAmount] != 0)
34 return tecHAS_OBLIGATIONS;
35
36 if ((*sleMPT)[~sfLockedAmount].value_or(0) != 0)
37 return tecHAS_OBLIGATIONS; // LCOV_EXCL_LINE
38
39 return tesSUCCESS;
40}
41
42TER
44{
45 auto const mpt = view().peek(keylet::mptokenIssuance(ctx_.tx[sfMPTokenIssuanceID]));
46 if (accountID_ != mpt->getAccountID(sfIssuer))
47 return tecINTERNAL; // LCOV_EXCL_LINE
48
49 if (!view().dirRemove(keylet::ownerDir(accountID_), (*mpt)[sfOwnerNode], mpt->key(), false))
50 return tefBAD_LEDGER; // LCOV_EXCL_LINE
51
52 view().erase(mpt);
53
55
56 return tesSUCCESS;
57}
58
59void
61{
62 // No transaction-specific invariants yet (future work).
63}
64
65bool
67 STTx const&,
68 TER,
70 ReadView const&,
71 beast::Journal const&)
72{
73 // No transaction-specific invariants yet (future work).
74 return true;
75}
76
77} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(SLE::ref sle)=0
Remove a peeked SLE.
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
A view into a ledger.
Definition ReadView.h:31
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry const > const & const_ref
beast::Journal const j_
Definition Transactor.h:118
ApplyView & view()
Definition Transactor.h:136
AccountID const accountID_
Definition Transactor.h:120
ApplyContext & ctx_
Definition Transactor.h:116
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Definition Indexes.cpp:521
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:357
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefBAD_LEDGER
Definition TER.h:160
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tecOBJECT_NOT_FOUND
Definition TER.h:324
@ tecINTERNAL
Definition TER.h:308
@ tecNO_PERMISSION
Definition TER.h:303
@ tecHAS_OBLIGATIONS
Definition TER.h:315
@ tesSUCCESS
Definition TER.h:240
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
ReadView const & view
Definition Transactor.h:64
State information when preflighting a tx.
Definition Transactor.h:18