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 auto const domain = ctx.tx.getFieldH256(sfDomainID);
31 if (domain == beast::zero)
32 return temMALFORMED;
33
34 return tesSUCCESS;
35}
36
37TER
39{
40 auto const domain = ctx.tx.getFieldH256(sfDomainID);
41 auto const sleDomain = ctx.view.read({ltPERMISSIONED_DOMAIN, domain});
42
43 if (!sleDomain)
44 return tecNO_ENTRY;
45
46 XRPL_ASSERT(
47 sleDomain->isFieldPresent(sfOwner) && ctx.tx.isFieldPresent(sfAccount),
48 "ripple::PermissionedDomainDelete::preclaim : required fields present");
49 if (sleDomain->getAccountID(sfOwner) != ctx.tx.getAccountID(sfAccount))
50 return tecNO_PERMISSION;
51
52 return tesSUCCESS;
53}
54
56TER
58{
59 XRPL_ASSERT(
60 ctx_.tx.isFieldPresent(sfDomainID),
61 "ripple::PermissionedDomainDelete::doApply : required field present");
62
63 auto const slePd =
64 view().peek({ltPERMISSIONED_DOMAIN, ctx_.tx.at(sfDomainID)});
65 auto const page = (*slePd)[sfOwnerNode];
66
67 if (!view().dirRemove(keylet::ownerDir(account_), page, slePd->key(), true))
68 {
69 JLOG(j_.fatal()) // LCOV_EXCL_LINE
70 << "Unable to delete permissioned domain directory entry."; // LCOV_EXCL_LINE
71 return tefBAD_LEDGER; // LCOV_EXCL_LINE
72 }
73
74 auto const ownerSle = view().peek(keylet::account(account_));
75 XRPL_ASSERT(
76 ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
77 "ripple::PermissionedDomainDelete::doApply : nonzero owner count");
78 adjustOwnerCount(view(), ownerSle, -1, ctx_.journal);
79 view().erase(slePd);
80
81 return tesSUCCESS;
82}
83
84} // namespace ripple
Stream fatal() const
Definition Journal.h:352
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.
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:657
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1042
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:484
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:645
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 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
@ tecNO_ENTRY
Definition TER.h:306
@ tecNO_PERMISSION
Definition TER.h:305
@ tesSUCCESS
Definition TER.h:244
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:605
@ temMALFORMED
Definition TER.h:87
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