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 ripple {
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 =
29 ctx.tx[ctx.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
30
31 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
32 return tecNO_ENTRY;
33
34 // Check if the NFT is mutable
35 if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagMutable))
36 return tecNO_PERMISSION;
37
38 // Verify permissions for the issuer
39 if (AccountID const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]);
40 issuer != account)
41 {
42 auto const sle = ctx.view.read(keylet::account(issuer));
43 if (!sle)
44 return tecINTERNAL; // LCOV_EXCL_LINE
45 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
46 return tecNO_PERMISSION;
47 }
48
49 return tesSUCCESS;
50}
51
52TER
54{
55 uint256 const nftokenID = ctx_.tx[sfNFTokenID];
56 AccountID const owner =
57 ctx_.tx[ctx_.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
58
59 return nft::changeTokenURI(view(), owner, nftokenID, ctx_.tx[~sfURI]);
60}
61
62} // namespace ripple
static TER preclaim(PreclaimContext const &ctx)
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.
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
std::uint16_t getFlags(uint256 const &id)
Definition nft.h:41
constexpr std::uint16_t const flagMutable
Definition nft.h:38
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.
TER changeTokenURI(ApplyView &view, AccountID const &owner, uint256 const &nftokenID, std::optional< ripple::Slice > const &uri)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::size_t constexpr maxTokenURILength
The maximum length of a URI inside an NFT.
Definition Protocol.h:69
@ tecNO_ENTRY
Definition TER.h:288
@ tecINTERNAL
Definition TER.h:292
@ tecNO_PERMISSION
Definition TER.h:287
@ tesSUCCESS
Definition TER.h:226
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:590
@ temMALFORMED
Definition TER.h:68
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