xrpld
Loading...
Searching...
No Matches
PermissionedDomainDelete.cpp
1#include <xrpl/tx/transactors/permissioned_domain/PermissionedDomainDelete.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/beast/utility/instrumentation.h>
6#include <xrpl/ledger/helpers/AccountRootHelpers.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/SField.h>
9#include <xrpl/protocol/STLedgerEntry.h>
10#include <xrpl/protocol/STTx.h>
11#include <xrpl/protocol/TER.h>
12#include <xrpl/protocol/XRPAmount.h>
13#include <xrpl/tx/Transactor.h>
14
15namespace xrpl {
16
19{
20 auto const domain = ctx.tx.getFieldH256(sfDomainID);
21 if (domain == beast::kZero)
22 return temMALFORMED;
23
24 return tesSUCCESS;
25}
26
27TER
29{
30 auto const domain = ctx.tx.getFieldH256(sfDomainID);
31 auto const sleDomain = ctx.view.read(keylet::permissionedDomain(domain));
32
33 if (!sleDomain)
34 return tecNO_ENTRY;
35
36 XRPL_ASSERT(
37 sleDomain->isFieldPresent(sfOwner) && ctx.tx.isFieldPresent(sfAccount),
38 "xrpl::PermissionedDomainDelete::preclaim : required fields present");
39 if (sleDomain->getAccountID(sfOwner) != ctx.tx.getAccountID(sfAccount))
40 return tecNO_PERMISSION;
41
42 return tesSUCCESS;
43}
44
46TER
48{
49 XRPL_ASSERT(
50 ctx_.tx.isFieldPresent(sfDomainID),
51 "xrpl::PermissionedDomainDelete::doApply : required field present");
52
53 auto const slePd = view().peek(keylet::permissionedDomain(ctx_.tx.at(sfDomainID)));
54 auto const page = (*slePd)[sfOwnerNode];
55
56 if (!view().dirRemove(keylet::ownerDir(accountID_), page, slePd->key(), true))
57 {
58 // LCOV_EXCL_START
59 JLOG(j_.fatal()) << "Unable to delete permissioned domain directory entry.";
60 return tefBAD_LEDGER;
61 // LCOV_EXCL_STOP
62 }
63
64 auto const ownerSle = view().peek(keylet::account(accountID_));
65 XRPL_ASSERT(
66 ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
67 "xrpl::PermissionedDomainDelete::doApply : nonzero owner count");
68 adjustOwnerCount(view(), ownerSle, -1, ctx_.journal);
69 view().erase(slePd);
70
71 return tesSUCCESS;
72}
73
74void
76{
77 // No transaction-specific invariants yet (future work).
78}
79
80bool
82 STTx const&,
83 TER,
85 ReadView const&,
86 beast::Journal const&)
87{
88 // No transaction-specific invariants yet (future work).
89 return true;
90}
91
92} // 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.
TER doApply() override
Attempt to delete the Permissioned Domain.
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:454
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:621
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:633
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 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
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Definition Indexes.cpp:569
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.
@ temMALFORMED
Definition TER.h:73
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tecNO_ENTRY
Definition TER.h:304
@ tecNO_PERMISSION
Definition TER.h:303
@ tesSUCCESS
Definition TER.h:240
uint256 key
Definition Keylet.h:20
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