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
48TER
50{
51 XRPL_ASSERT(
52 ctx_.tx.isFieldPresent(sfDomainID),
53 "xrpl::PermissionedDomainDelete::doApply : required field present");
54
55 auto const slePd = view().peek(keylet::permissionedDomain(ctx_.tx.at(sfDomainID)));
56 auto const page = (*slePd)[sfOwnerNode];
57
58 if (!view().dirRemove(keylet::ownerDir(accountID_), page, slePd->key(), true))
59 {
60 // LCOV_EXCL_START
61 JLOG(j_.fatal()) << "Unable to delete permissioned domain directory entry.";
62 return tefBAD_LEDGER;
63 // LCOV_EXCL_STOP
64 }
65
66 auto const ownerSle = view().peek(keylet::account(accountID_));
67 XRPL_ASSERT(
68 ownerSle && ownerSle->getFieldU32(sfOwnerCount) > 0,
69 "xrpl::PermissionedDomainDelete::doApply : nonzero owner count");
70 decreaseOwnerCountForObject(view(), ownerSle, slePd, 1, ctx_.journal);
71 view().erase(slePd);
72
73 return tesSUCCESS;
74}
75
76void
78{
79 // No transaction-specific invariants yet (future work).
80}
81
82bool
84 STTx const&,
85 TER,
87 ReadView const&,
88 beast::Journal const&)
89{
90 // No transaction-specific invariants yet (future work).
91 return true;
92}
93
94} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:44
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:41
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:464
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:631
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:643
beast::Journal const j_
Definition Transactor.h:155
ApplyView & view()
Definition Transactor.h:175
AccountID const accountID_
Definition Transactor.h:157
ApplyContext & ctx_
Definition Transactor.h:153
constexpr Zero kZero
Definition Zero.h:30
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:373
Keylet permissionedDomain(AccountID const &account, SeqProxy const &seq) noexcept
Definition Indexes.cpp:579
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:198
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
void decreaseOwnerCountForObject(ApplyView &view, SLE::ref accountSle, SLE::ref objectSle, std::uint32_t count, beast::Journal j)
Decrease owner-count fields for an existing ledger object.
@ tefBAD_LEDGER
Definition TER.h:162
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:607
@ temMALFORMED
Definition TER.h:75
TERSubset< CanCvtToTER > TER
Definition TER.h:647
@ tecNO_ENTRY
Definition TER.h:309
@ tecNO_PERMISSION
Definition TER.h:308
@ tesSUCCESS
Definition TER.h:245
uint256 key
Definition Keylet.h:21
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:83
ReadView const & view
Definition Transactor.h:86
State information when preflighting a tx.
Definition Transactor.h:38