rippled
Loading...
Searching...
No Matches
PermissionedDomainDelete.cpp
1#include <xrpld/app/tx/detail/PermissionedDomainDelete.h>
2
3#include <xrpl/ledger/View.h>
4#include <xrpl/protocol/TxFlags.h>
5
6namespace xrpl {
7
10{
11 auto const domain = ctx.tx.getFieldH256(sfDomainID);
12 if (domain == beast::zero)
13 return temMALFORMED;
14
15 return tesSUCCESS;
16}
17
18TER
20{
21 auto const domain = ctx.tx.getFieldH256(sfDomainID);
22 auto const sleDomain = ctx.view.read({ltPERMISSIONED_DOMAIN, domain});
23
24 if (!sleDomain)
25 return tecNO_ENTRY;
26
27 XRPL_ASSERT(
28 sleDomain->isFieldPresent(sfOwner) && ctx.tx.isFieldPresent(sfAccount),
29 "xrpl::PermissionedDomainDelete::preclaim : required fields present");
30 if (sleDomain->getAccountID(sfOwner) != ctx.tx.getAccountID(sfAccount))
31 return tecNO_PERMISSION;
32
33 return tesSUCCESS;
34}
35
37TER
39{
40 XRPL_ASSERT(ctx_.tx.isFieldPresent(sfDomainID), "xrpl::PermissionedDomainDelete::doApply : required field present");
41
42 auto const slePd = view().peek({ltPERMISSIONED_DOMAIN, ctx_.tx.at(sfDomainID)});
43 auto const page = (*slePd)[sfOwnerNode];
44
45 if (!view().dirRemove(keylet::ownerDir(account_), page, slePd->key(), true))
46 {
47 // LCOV_EXCL_START
48 JLOG(j_.fatal()) << "Unable to delete permissioned domain directory entry.";
49 return tefBAD_LEDGER;
50 // LCOV_EXCL_STOP
51 }
52
53 auto const ownerSle = view().peek(keylet::account(account_));
54 XRPL_ASSERT(
55 ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
56 "xrpl::PermissionedDomainDelete::doApply : nonzero owner count");
57 adjustOwnerCount(view(), ownerSle, -1, ctx_.journal);
58 view().erase(slePd);
59
60 return tesSUCCESS;
61}
62
63} // namespace xrpl
Stream fatal() const
Definition Journal.h:324
STTx const & tx
beast::Journal const journal
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
TER doApply() override
Attempt to delete the Permissioned Domain.
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.
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1041
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:439
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:606
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:618
AccountID const account_
Definition Transactor.h:112
beast::Journal const j_
Definition Transactor.h:110
ApplyView & view()
Definition Transactor.h:128
ApplyContext & ctx_
Definition Transactor.h:108
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:325
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefBAD_LEDGER
Definition TER.h:150
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:941
@ temMALFORMED
Definition TER.h:67
@ tecNO_ENTRY
Definition TER.h:287
@ tecNO_PERMISSION
Definition TER.h:286
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:580
@ tesSUCCESS
Definition TER.h:225
uint256 key
Definition Keylet.h:20
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:15