1#include <xrpld/app/tx/detail/DID.h>
2#include <xrpld/app/tx/detail/DelegateSet.h>
3#include <xrpld/app/tx/detail/DeleteAccount.h>
4#include <xrpld/app/tx/detail/DeleteOracle.h>
5#include <xrpld/app/tx/detail/DepositPreauth.h>
6#include <xrpld/app/tx/detail/NFTokenUtils.h>
7#include <xrpld/app/tx/detail/SetSignerList.h>
9#include <xrpl/basics/Log.h>
10#include <xrpl/basics/mulDiv.h>
11#include <xrpl/beast/utility/instrumentation.h>
12#include <xrpl/ledger/CredentialHelpers.h>
13#include <xrpl/ledger/View.h>
14#include <xrpl/protocol/Feature.h>
15#include <xrpl/protocol/Indexes.h>
16#include <xrpl/protocol/Protocol.h>
17#include <xrpl/protocol/TxFlags.h>
18#include <xrpl/protocol/Units.h>
34 if (ctx.
tx[sfAccount] == ctx.
tx[sfDestination])
53using DeleterFuncPtr =
TER (*)(
87removeTicketFromLedger(
99removeDepositPreauthFromLedger(
111removeNFTokenOfferFromLedger(
138removeOracleFromLedger(
150removeCredentialFromLedger(
162removeDelegateFromLedger(
186 return removeTicketFromLedger;
187 case ltDEPOSIT_PREAUTH:
188 return removeDepositPreauthFromLedger;
189 case ltNFTOKEN_OFFER:
190 return removeNFTokenOfferFromLedger;
192 return removeDIDFromLedger;
194 return removeOracleFromLedger;
196 return removeCredentialFromLedger;
198 return removeDelegateFromLedger;
237 XRPL_ASSERT(sleAccount,
"xrpl::DeleteAccount::preclaim : non-null account");
243 if ((*sleAccount)[~sfMintedNFTokens] != (*sleAccount)[~sfBurnedNFTokens])
261 if ((*sleAccount)[sfSequence] + seqDelta > ctx.
view.
seq())
275 if ((*sleAccount)[~sfFirstNFTokenSequence].value_or(0) + (*sleAccount)[~sfMintedNFTokens].value_or(0) + seqDelta >
286 unsigned int uDirEntry{0};
291 if (!
cdirFirst(ctx.
view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry))
304 JLOG(ctx.
j.
fatal()) <<
"DeleteAccount: directory node in ledger " << ctx.
view.
seq()
305 <<
" has index to object that is missing: " <<
to_string(dirEntry);
310 LedgerEntryType const nodeType{safe_cast<LedgerEntryType>((*sleItem)[sfLedgerEntryType])};
312 if (!nonObligationDeleter(nodeType))
320 }
while (
cdirNext(ctx.
view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry));
329 XRPL_ASSERT(src,
"xrpl::DeleteAccount::doApply : non-null source account");
331 auto const dstID =
ctx_.
tx[sfDestination];
333 XRPL_ASSERT(dst,
"xrpl::DeleteAccount::doApply : non-null destination account");
352 if (
auto deleter = nonObligationDeleter(nodeType))
361 "xrpl::DeleteAccount::doApply : undeletable item not found "
363 JLOG(
j_.
error()) <<
"DeleteAccount undeletable item not "
364 "found in preclaim.";
377 XRPL_ASSERT((*src)[sfBalance] ==
XRPAmount(0),
"xrpl::DeleteAccount::doApply : source balance is zero");
381 if (
view().exists(ownerDirKeylet) && !
view().emptyDirDelete(ownerDirKeylet))
A generic endpoint for log messages.
void deliver(STAmount const &amount)
Sets the DeliveredAmount field in the metadata.
beast::Journal const journal
Writeable view to a ledger, for applying a transaction.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
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.
static TER deleteSLE(ApplyContext &ctx, Keylet sleKeylet, AccountID const owner)
static TER deleteDelegate(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, beast::Journal j)
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
static NotTEC preflight(PreflightContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static TER deleteOracle(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, beast::Journal j)
static TER removeFromLedger(ApplyView &view, uint256 const &delIndex, beast::Journal j)
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
LedgerIndex seq() const
Returns the sequence number of the base ledger.
virtual std::optional< key_type > succ(key_type const &key, std::optional< key_type > const &last=std::nullopt) const =0
Return the key of the next state item.
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.
bool isFieldPresent(SField const &field) const
static TER removeFromLedger(Application &app, ApplyView &view, AccountID const &account, beast::Journal j)
static XRPAmount calculateOwnerReserveFee(ReadView const &view, STTx const &tx)
static TER ticketDelete(ApplyView &view, AccountID const &account, uint256 const &ticketIndex, beast::Journal j)
NotTEC checkFields(STTx const &tx, beast::Journal j)
TER valid(STTx const &tx, ReadView const &view, AccountID const &src, beast::Journal j)
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
Keylet nftpage_max(AccountID const &owner)
A keylet for the owner's last possible NFT page.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet child(uint256 const &key) noexcept
Any item that can be in an owner dir.
Keylet nftpage_min(AccountID const &owner)
NFT page keylets.
Keylet account(AccountID const &id) noexcept
AccountID root.
bool deleteTokenOffer(ApplyView &view, std::shared_ptr< SLE > const &offer)
Deletes the given token offer.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool dirIsEmpty(ReadView const &view, Keylet const &k)
Returns true if the directory is empty.
std::size_t constexpr maxDeletableDirEntries
The maximum number of owner directory entries for account to be deletable.
std::string to_string(base_uint< Bits, Tag > const &a)
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
bool cdirNext(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the next entry in the directory, advancing the index.
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
bool cdirFirst(ReadView const &view, uint256 const &root, std::shared_ptr< SLE const > &page, unsigned int &index, uint256 &entry)
Returns the first entry in the directory, advancing the index.
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst, beast::Journal j)
TERSubset< CanCvtToTER > TER
static TER removeSignersFromLedger(Application &app, ApplyView &view, Keylet const &accountKeylet, Keylet const &ownerDirKeylet, Keylet const &signerListKeylet, beast::Journal j)
TER offerDelete(ApplyView &view, std::shared_ptr< SLE > const &sle, beast::Journal j)
Delete an offer.
bool isTesSuccess(TER x) noexcept
LedgerEntryType
Identifiers for on-ledger objects.
TER cleanupOnAccountDelete(ApplyView &view, Keylet const &ownerDirKeylet, EntryDeleter const &deleter, beast::Journal j, std::optional< std::uint16_t > maxNodesToDelete=std::nullopt)
Cleanup owner directory entries on account delete.
A pair of SHAMap key and LedgerEntryType.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.