rippled
Loading...
Searching...
No Matches
NFTokenBurn.cpp
1#include <xrpl/protocol/Feature.h>
2#include <xrpl/protocol/Protocol.h>
3#include <xrpl/protocol/TxFlags.h>
4#include <xrpl/tx/transactors/nft/NFTokenBurn.h>
5#include <xrpl/tx/transactors/nft/NFTokenUtils.h>
6
7namespace xrpl {
8
11{
12 return tesSUCCESS;
13}
14
15TER
17{
18 auto const owner = [&ctx]() {
19 if (ctx.tx.isFieldPresent(sfOwner))
20 return ctx.tx.getAccountID(sfOwner);
21
22 return ctx.tx[sfAccount];
23 }();
24
25 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
26 return tecNO_ENTRY;
27
28 // The owner of a token can always burn it, but the issuer can only
29 // do so if the token is marked as burnable.
30 if (auto const account = ctx.tx[sfAccount]; owner != account)
31 {
32 if ((nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagBurnable) == 0)
33 return tecNO_PERMISSION;
34
35 if (auto const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]); issuer != account)
36 {
37 if (auto const sle = ctx.view.read(keylet::account(issuer)); sle)
38 {
39 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
40 return tecNO_PERMISSION;
41 }
42 }
43 }
44
45 return tesSUCCESS;
46}
47
48TER
50{
51 // Remove the token, effectively burning it:
52 auto const ret = nft::removeToken(
53 view(),
54 ctx_.tx.isFieldPresent(sfOwner) ? ctx_.tx.getAccountID(sfOwner)
55 : 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 = nft::removeTokenOffersWithLimit(
74
75 if (maxDeletableTokenOfferEntries > deletedSellOffers)
76 {
78 view(),
79 keylet::nft_buys(ctx_.tx[sfNFTokenID]),
80 maxDeletableTokenOfferEntries - deletedSellOffers);
81 }
82
83 return tesSUCCESS;
84}
85
86} // 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:456
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:635
ApplyView & view()
Definition Transactor.h:132
ApplyContext & ctx_
Definition Transactor.h:112
Keylet nft_buys(uint256 const &id) noexcept
The directory of buy offers for the specified NFT.
Definition Indexes.cpp:392
Keylet nft_sells(uint256 const &id) noexcept
The directory of sell offers for the specified NFT.
Definition Indexes.cpp:398
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
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.
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::optional< STObject > findToken(ReadView const &view, AccountID const &owner, uint256 const &nftokenID)
Finds the specified token in the owner's token directory.
AccountID getIssuer(uint256 const &id)
Definition nft.h:100
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:651
@ tecNO_ENTRY
Definition TER.h:287
@ tecNO_PERMISSION
Definition TER.h:286
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:582
@ tesSUCCESS
Definition TER.h:225
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:57
ReadView const & view
Definition Transactor.h:60
State information when preflighting a tx.
Definition Transactor.h:14