rippled
Loading...
Searching...
No Matches
NFTokenModify.cpp
1#include <xrpld/app/tx/detail/NFTokenModify.h>
2#include <xrpld/app/tx/detail/NFTokenUtils.h>
3
4#include <xrpl/protocol/Feature.h>
5#include <xrpl/protocol/TxFlags.h>
6
7namespace xrpl {
8
11{
12 if (auto owner = ctx.tx[~sfOwner]; owner == ctx.tx[sfAccount])
13 return temMALFORMED;
14
15 if (auto uri = ctx.tx[~sfURI])
16 {
17 if (uri->length() == 0 || uri->length() > maxTokenURILength)
18 return temMALFORMED;
19 }
20
21 return tesSUCCESS;
22}
23
24TER
26{
27 AccountID const account = ctx.tx[sfAccount];
28 AccountID const owner = ctx.tx[ctx.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
29
30 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
31 return tecNO_ENTRY;
32
33 // Check if the NFT is mutable
34 if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagMutable))
35 return tecNO_PERMISSION;
36
37 // Verify permissions for the issuer
38 if (AccountID const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]); issuer != account)
39 {
40 auto const sle = ctx.view.read(keylet::account(issuer));
41 if (!sle)
42 return tecINTERNAL; // LCOV_EXCL_LINE
43 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
44 return tecNO_PERMISSION;
45 }
46
47 return tesSUCCESS;
48}
49
50TER
52{
53 uint256 const nftokenID = ctx_.tx[sfNFTokenID];
54 AccountID const owner = ctx_.tx[ctx_.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
55
56 return nft::changeTokenURI(view(), owner, nftokenID, ctx_.tx[~sfURI]);
57}
58
59} // 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:439
ApplyView & view()
Definition Transactor.h:128
ApplyContext & ctx_
Definition Transactor.h:108
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:160
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:202
@ 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: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