rippled
Loading...
Searching...
No Matches
PermissionedDomainDelete.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/PermissionedDomainDelete.h>
21
22#include <xrpl/ledger/View.h>
23#include <xrpl/protocol/TxFlags.h>
24
25namespace ripple {
26
29{
30 if (!ctx.rules.enabled(featurePermissionedDomains))
31 return temDISABLED;
32
33 if (auto const ret = preflight1(ctx); !isTesSuccess(ret))
34 return ret;
35
36 if (ctx.tx.getFlags() & tfUniversalMask)
37 {
38 JLOG(ctx.j.debug()) << "PermissionedDomainDelete: invalid flags.";
39 return temINVALID_FLAG;
40 }
41
42 auto const domain = ctx.tx.getFieldH256(sfDomainID);
43 if (domain == beast::zero)
44 return temMALFORMED;
45
46 return preflight2(ctx);
47}
48
49TER
51{
52 auto const domain = ctx.tx.getFieldH256(sfDomainID);
53 auto const sleDomain = ctx.view.read({ltPERMISSIONED_DOMAIN, domain});
54
55 if (!sleDomain)
56 return tecNO_ENTRY;
57
58 XRPL_ASSERT(
59 sleDomain->isFieldPresent(sfOwner) && ctx.tx.isFieldPresent(sfAccount),
60 "ripple::PermissionedDomainDelete::preclaim : required fields present");
61 if (sleDomain->getAccountID(sfOwner) != ctx.tx.getAccountID(sfAccount))
62 return tecNO_PERMISSION;
63
64 return tesSUCCESS;
65}
66
68TER
70{
71 XRPL_ASSERT(
72 ctx_.tx.isFieldPresent(sfDomainID),
73 "ripple::PermissionedDomainDelete::doApply : required field present");
74
75 auto const slePd =
76 view().peek({ltPERMISSIONED_DOMAIN, ctx_.tx.at(sfDomainID)});
77 auto const page = (*slePd)[sfOwnerNode];
78
79 if (!view().dirRemove(keylet::ownerDir(account_), page, slePd->key(), true))
80 {
81 JLOG(j_.fatal()) // LCOV_EXCL_LINE
82 << "Unable to delete permissioned domain directory entry."; // LCOV_EXCL_LINE
83 return tefBAD_LEDGER; // LCOV_EXCL_LINE
84 }
85
86 auto const ownerSle = view().peek(keylet::account(account_));
87 XRPL_ASSERT(
88 ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
89 "ripple::PermissionedDomainDelete::doApply : nonzero owner count");
90 adjustOwnerCount(view(), ownerSle, -1, ctx_.journal);
91 view().erase(slePd);
92
93 return tesSUCCESS;
94}
95
96} // namespace ripple
Stream fatal() const
Definition Journal.h:352
Stream debug() const
Definition Journal.h:328
beast::Journal const journal
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.
TER doApply() override
Attempt to delete the Permissioned Domain.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext 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
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:651
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1038
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:484
std::uint32_t getFlags() const
Definition STObject.cpp:537
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:645
AccountID const account_
Definition Transactor.h:145
ApplyView & view()
Definition Transactor.h:161
beast::Journal const j_
Definition Transactor.h:143
ApplyContext & ctx_
Definition Transactor.h:141
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
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
@ tefBAD_LEDGER
Definition TER.h:170
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
@ tecNO_ENTRY
Definition TER.h:306
@ tecNO_PERMISSION
Definition TER.h:305
@ tesSUCCESS
Definition TER.h:244
bool isTesSuccess(TER x) noexcept
Definition TER.h:674
constexpr std::uint32_t tfUniversalMask
Definition TxFlags.h:63
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:605
@ temMALFORMED
Definition TER.h:87
@ 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:80
ReadView const & view
Definition Transactor.h:83
State information when preflighting a tx.
Definition Transactor.h:35
beast::Journal const j
Definition Transactor.h:42