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 ripple {
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]);
37 issuer != account)
38 {
39 if (auto const sle = ctx.view.read(keylet::account(issuer)); sle)
40 {
41 if (auto const minter = (*sle)[~sfNFTokenMinter];
42 minter != account)
43 return tecNO_PERMISSION;
44 }
45 }
46 }
47
48 return tesSUCCESS;
49}
50
51TER
53{
54 // Remove the token, effectively burning it:
55 auto const ret = nft::removeToken(
56 view(),
57 ctx_.tx.isFieldPresent(sfOwner) ? ctx_.tx.getAccountID(sfOwner)
58 : ctx_.tx.getAccountID(sfAccount),
59 ctx_.tx[sfNFTokenID]);
60
61 // Should never happen since preclaim() verified the token is present.
62 if (!isTesSuccess(ret))
63 return ret;
64
65 if (auto issuer =
67 {
68 (*issuer)[~sfBurnedNFTokens] =
69 (*issuer)[~sfBurnedNFTokens].value_or(0) + 1;
70 view().update(issuer);
71 }
72
73 // Delete up to 500 offers in total.
74 // Because the number of sell offers is likely to be less than
75 // the number of buy offers, we prioritize the deletion of sell
76 // offers in order to clean up sell offer directory
77 std::size_t const deletedSellOffers = nft::removeTokenOffersWithLimit(
78 view(),
79 keylet::nft_sells(ctx_.tx[sfNFTokenID]),
81
82 if (maxDeletableTokenOfferEntries > deletedSellOffers)
83 {
85 view(),
86 keylet::nft_buys(ctx_.tx[sfNFTokenID]),
87 maxDeletableTokenOfferEntries - deletedSellOffers);
88 }
89
90 return tesSUCCESS;
91}
92
93} // namespace ripple
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)
TER doApply() override
static NotTEC preflight(PreflightContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
ApplyView & view()
Definition Transactor.h:144
ApplyContext & ctx_
Definition Transactor.h:124
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet nft_buys(uint256 const &id) noexcept
The directory of buy offers for the specified NFT.
Definition Indexes.cpp:415
Keylet nft_sells(uint256 const &id) noexcept
The directory of sell offers for the specified NFT.
Definition Indexes.cpp:421
constexpr std::uint16_t const flagBurnable
Definition nft.h:34
std::uint16_t getFlags(uint256 const &id)
Definition nft.h:41
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:101
std::optional< STObject > findToken(ReadView const &view, AccountID const &owner, uint256 const &nftokenID)
Finds the specified token in the owner's token directory.
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::size_t constexpr maxDeletableTokenOfferEntries
The maximum number of offers in an offer directory for NFT to be burnable.
Definition Protocol.h:55
@ tecNO_ENTRY
Definition TER.h:288
@ tecNO_PERMISSION
Definition TER.h:287
@ tesSUCCESS
Definition TER.h:226
bool isTesSuccess(TER x) noexcept
Definition TER.h:659
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:590
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:16