rippled
Loading...
Searching...
No Matches
NFTokenModify.cpp
1#include <xrpl/protocol/Feature.h>
2#include <xrpl/protocol/TxFlags.h>
3#include <xrpl/tx/transactors/NFT/NFTokenModify.h>
4#include <xrpl/tx/transactors/NFT/NFTokenUtils.h>
5
6namespace xrpl {
7
10{
11 if (auto owner = ctx.tx[~sfOwner]; owner == ctx.tx[sfAccount])
12 return temMALFORMED;
13
14 if (auto uri = ctx.tx[~sfURI])
15 {
16 if (uri->length() == 0 || uri->length() > maxTokenURILength)
17 return temMALFORMED;
18 }
19
20 return tesSUCCESS;
21}
22
23TER
25{
26 AccountID const account = ctx.tx[sfAccount];
27 AccountID const owner = ctx.tx[ctx.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
28
29 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
30 return tecNO_ENTRY;
31
32 // Check if the NFT is mutable
33 if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagMutable))
34 return tecNO_PERMISSION;
35
36 // Verify permissions for the issuer
37 if (AccountID const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]); issuer != account)
38 {
39 auto const sle = ctx.view.read(keylet::account(issuer));
40 if (!sle)
41 return tecINTERNAL; // LCOV_EXCL_LINE
42 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
43 return tecNO_PERMISSION;
44 }
45
46 return tesSUCCESS;
47}
48
49TER
51{
52 uint256 const nftokenID = ctx_.tx[sfNFTokenID];
53 AccountID const owner = ctx_.tx[ctx_.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
54
55 return nft::changeTokenURI(view(), owner, nftokenID, ctx_.tx[~sfURI]);
56}
57
58} // namespace xrpl
STTx const & tx
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:447
ApplyView & view()
Definition Transactor.h:132
ApplyContext & ctx_
Definition Transactor.h:112
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
TER changeTokenURI(ApplyView &view, AccountID const &owner, uint256 const &nftokenID, std::optional< xrpl::Slice > const &uri)
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
constexpr std::uint16_t const flagMutable
Definition nft.h:37
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 maxTokenURILength
The maximum length of a URI inside an NFT.
Definition Protocol.h:203
@ temMALFORMED
Definition TER.h:67
@ tecNO_ENTRY
Definition TER.h:287
@ tecINTERNAL
Definition TER.h:291
@ 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