rippled
Loading...
Searching...
No Matches
NFTokenBurn.cpp
1#include <xrpld/app/tx/detail/NFTokenBurn.h>
2#include <xrpld/app/tx/detail/NFTokenUtils.h>
3
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/Protocol.h>
6#include <xrpl/protocol/TxFlags.h>
7
8namespace xrpl {
9
12{
13 return tesSUCCESS;
14}
15
16TER
18{
19 auto const owner = [&ctx]() {
20 if (ctx.tx.isFieldPresent(sfOwner))
21 return ctx.tx.getAccountID(sfOwner);
22
23 return ctx.tx[sfAccount];
24 }();
25
26 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
27 return tecNO_ENTRY;
28
29 // The owner of a token can always burn it, but the issuer can only
30 // do so if the token is marked as burnable.
31 if (auto const account = ctx.tx[sfAccount]; owner != account)
32 {
33 if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagBurnable))
34 return tecNO_PERMISSION;
35
36 if (auto const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]); issuer != account)
37 {
38 if (auto const sle = ctx.view.read(keylet::account(issuer)); sle)
39 {
40 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
41 return tecNO_PERMISSION;
42 }
43 }
44 }
45
46 return tesSUCCESS;
47}
48
49TER
51{
52 // Remove the token, effectively burning it:
53 auto const ret = nft::removeToken(
54 view(),
55 ctx_.tx.isFieldPresent(sfOwner) ? ctx_.tx.getAccountID(sfOwner) : ctx_.tx.getAccountID(sfAccount),
56 ctx_.tx[sfNFTokenID]);
57
58 // Should never happen since preclaim() verified the token is present.
59 if (!isTesSuccess(ret))
60 return ret;
61
62 if (auto issuer = view().peek(keylet::account(nft::getIssuer(ctx_.tx[sfNFTokenID]))))
63 {
64 (*issuer)[~sfBurnedNFTokens] = (*issuer)[~sfBurnedNFTokens].value_or(0) + 1;
65 view().update(issuer);
66 }
67
68 // Delete up to 500 offers in total.
69 // Because the number of sell offers is likely to be less than
70 // the number of buy offers, we prioritize the deletion of sell
71 // offers in order to clean up sell offer directory
72 std::size_t const deletedSellOffers =
74
75 if (maxDeletableTokenOfferEntries > deletedSellOffers)
76 {
78 view(), keylet::nft_buys(ctx_.tx[sfNFTokenID]), maxDeletableTokenOfferEntries - deletedSellOffers);
79 }
80
81 return tesSUCCESS;
82}
83
84} // namespace xrpl
STTx const & tx
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to a peeked SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
TER doApply() override
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:439
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:618
ApplyView & view()
Definition Transactor.h:128
ApplyContext & ctx_
Definition Transactor.h:108
Keylet nft_buys(uint256 const &id) noexcept
The directory of buy offers for the specified NFT.
Definition Indexes.cpp:381
Keylet nft_sells(uint256 const &id) noexcept
The directory of sell offers for the specified NFT.
Definition Indexes.cpp:387
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
std::optional< STObject > findToken(ReadView const &view, AccountID const &owner, uint256 const &nftokenID)
Finds the specified token in the owner's token directory.
constexpr std::uint16_t const flagBurnable
Definition nft.h:33
TER removeToken(ApplyView &view, AccountID const &owner, uint256 const &nftokenID)
Remove the token from the owner's token directory.
AccountID getIssuer(uint256 const &id)
Definition nft.h:100
std::size_t removeTokenOffersWithLimit(ApplyView &view, Keylet const &directory, std::size_t maxDeletableOffers)
Delete up to a specified number of offers from the specified token offer directory.
std::uint16_t getFlags(uint256 const &id)
Definition nft.h:40
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
std::size_t constexpr maxDeletableTokenOfferEntries
The maximum number of offers in an offer directory for NFT to be burnable.
Definition Protocol.h:55
bool isTesSuccess(TER x) noexcept
Definition TER.h:649
@ tecNO_ENTRY
Definition TER.h:287
@ tecNO_PERMISSION
Definition TER.h:286
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:580
@ tesSUCCESS
Definition TER.h:225
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