1#include <xrpl/basics/Log.h>
2#include <xrpl/beast/utility/instrumentation.h>
3#include <xrpl/ledger/View.h>
4#include <xrpl/ledger/helpers/CredentialHelpers.h>
5#include <xrpl/ledger/helpers/DirectoryHelpers.h>
6#include <xrpl/ledger/helpers/OfferHelpers.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Protocol.h>
10#include <xrpl/protocol/TxFlags.h>
11#include <xrpl/protocol/Units.h>
12#include <xrpl/tx/transactors/account/AccountDelete.h>
13#include <xrpl/tx/transactors/account/SignerListSet.h>
14#include <xrpl/tx/transactors/delegate/DelegateSet.h>
15#include <xrpl/tx/transactors/did/DIDDelete.h>
16#include <xrpl/tx/transactors/nft/NFTokenUtils.h>
17#include <xrpl/tx/transactors/oracle/OracleDelete.h>
18#include <xrpl/tx/transactors/payment/DepositPreauth.h>
31 if (ctx.
tx[sfAccount] == ctx.
tx[sfDestination])
52using DeleterFuncPtr =
TER (*)(
75 ServiceRegistry& registry,
86removeTicketFromLedger(
98removeDepositPreauthFromLedger(
110removeNFTokenOfferFromLedger(
137removeOracleFromLedger(
149removeCredentialFromLedger(
161removeDelegateFromLedger(
185 return removeTicketFromLedger;
186 case ltDEPOSIT_PREAUTH:
187 return removeDepositPreauthFromLedger;
188 case ltNFTOKEN_OFFER:
189 return removeNFTokenOfferFromLedger;
191 return removeDIDFromLedger;
193 return removeOracleFromLedger;
195 return removeCredentialFromLedger;
197 return removeDelegateFromLedger;
216 if ((((*sleDst)[sfFlags] & lsfRequireDestTag) != 0u) && !ctx.
tx[~sfDestinationTag])
228 if ((sleDst->getFlags() & lsfDepositAuth) != 0u)
236 XRPL_ASSERT(sleAccount,
"xrpl::AccountDelete::preclaim : non-null account");
242 if ((*sleAccount)[~sfMintedNFTokens] != (*sleAccount)[~sfBurnedNFTokens])
261 if ((*sleAccount)[sfSequence] + seqDelta > ctx.
view.
seq())
275 if ((*sleAccount)[~sfFirstNFTokenSequence].value_or(0) +
276 (*sleAccount)[~sfMintedNFTokens].value_or(0) + seqDelta >
287 unsigned int uDirEntry{0};
292 if (!
cdirFirst(ctx.
view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry))
305 JLOG(ctx.
j.
fatal()) <<
"AccountDelete: directory node in ledger " << ctx.
view.
seq()
306 <<
" has index to object that is missing: " <<
to_string(dirEntry);
311 LedgerEntryType const nodeType{safe_cast<LedgerEntryType>((*sleItem)[sfLedgerEntryType])};
313 if (nonObligationDeleter(nodeType) ==
nullptr)
321 }
while (
cdirNext(ctx.
view, ownerDirKeylet.key, sleDirNode, uDirEntry, dirEntry));
330 XRPL_ASSERT(src,
"xrpl::AccountDelete::doApply : non-null source account");
332 auto const dstID =
ctx_.
tx[sfDestination];
334 XRPL_ASSERT(dst,
"xrpl::AccountDelete::doApply : non-null destination account");
354 if (
auto deleter = nonObligationDeleter(nodeType))
363 "xrpl::AccountDelete::doApply : undeletable item not found "
365 JLOG(
j_.
error()) <<
"AccountDelete undeletable item not "
366 "found in preclaim.";
375 auto const remainingBalance = src->getFieldAmount(sfBalance).xrp();
376 (*dst)[sfBalance] = (*dst)[sfBalance] + remainingBalance;
377 (*src)[sfBalance] = (*src)[sfBalance] - remainingBalance;
381 (*src)[sfBalance] ==
XRPAmount(0),
"xrpl::AccountDelete::doApply : source balance is zero");
385 if (
view().exists(ownerDirKeylet) && !
view().emptyDirDelete(ownerDirKeylet))
392 if (remainingBalance >
XRPAmount(0) && dst->isFlag(lsfPasswordSpent))
393 dst->clearFlag(lsfPasswordSpent);
A generic endpoint for log messages.
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)
std::reference_wrapper< ServiceRegistry > registry
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 TER removeFromLedger(ApplyView &view, uint256 const &delIndex, beast::Journal j)
static TER deleteOracle(ApplyView &view, std::shared_ptr< SLE > const &sle, AccountID const &account, 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
Service registry for dependency injection.
static TER removeFromLedger(ServiceRegistry ®istry, 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)
TER verifyDepositPreauth(STTx const &tx, ApplyView &view, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE const > const &sleDst, beast::Journal j)
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.
TERSubset< CanCvtToTER > TER
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.
static TER removeSignersFromLedger(ServiceRegistry ®istry, ApplyView &view, Keylet const &accountKeylet, Keylet const &ownerDirKeylet, Keylet const &signerListKeylet, beast::Journal j)
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.