xrpld
Loading...
Searching...
No Matches
NFTokenModify.cpp
1#include <xrpl/tx/transactors/nft/NFTokenModify.h>
2
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/Journal.h>
5#include <xrpl/ledger/helpers/NFTokenHelpers.h>
6#include <xrpl/protocol/AccountID.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/STLedgerEntry.h>
11#include <xrpl/protocol/STTx.h>
12#include <xrpl/protocol/TER.h>
13#include <xrpl/protocol/XRPAmount.h>
14#include <xrpl/protocol/nft.h>
15#include <xrpl/tx/Transactor.h>
16
17namespace xrpl {
18
21{
22 if (auto owner = ctx.tx[~sfOwner]; owner == ctx.tx[sfAccount])
23 return temMALFORMED;
24
25 if (auto uri = ctx.tx[~sfURI])
26 {
27 if (uri->empty() || uri->length() > kMaxTokenUriLength)
28 return temMALFORMED;
29 }
30
31 return tesSUCCESS;
32}
33
34TER
36{
37 AccountID const account = ctx.tx[sfAccount];
38 AccountID const owner = ctx.tx[ctx.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
39
40 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
41 return tecNO_ENTRY;
42
43 // Check if the NFT is mutable
44 if ((nft::getFlags(ctx.tx[sfNFTokenID]) & nft::kFlagMutable) == 0)
45 return tecNO_PERMISSION;
46
47 // Verify permissions for the issuer
48 if (AccountID const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]); issuer != account)
49 {
50 auto const sle = ctx.view.read(keylet::account(issuer));
51 if (!sle)
52 return tecINTERNAL; // LCOV_EXCL_LINE
53 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
54 return tecNO_PERMISSION;
55 }
56
57 return tesSUCCESS;
58}
59
60TER
62{
63 uint256 const nftokenID = ctx_.tx[sfNFTokenID];
64 AccountID const owner = ctx_.tx[ctx_.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
65
66 return nft::changeTokenURI(view(), owner, nftokenID, ctx_.tx[~sfURI]);
67}
68
69void
71{
72 // No transaction-specific invariants yet (future work).
73}
74
75bool
77 STTx const&,
78 TER,
80 ReadView const&,
81 beast::Journal const&)
82{
83 // No transaction-specific invariants yet (future work).
84 return true;
85}
86
87} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
static TER preclaim(PreclaimContext const &ctx)
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
static NotTEC preflight(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
TER doApply() override
A view into a ledger.
Definition ReadView.h:31
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
std::shared_ptr< STLedgerEntry const > const & const_ref
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:454
ApplyView & view()
Definition Transactor.h:136
ApplyContext & ctx_
Definition Transactor.h:116
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:186
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.
constexpr std::uint16_t const kFlagMutable
Definition nft.h:36
AccountID getIssuer(uint256 const &id)
Definition nft.h:99
std::uint16_t getFlags(uint256 const &id)
Definition nft.h:39
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr std::size_t kMaxTokenUriLength
The maximum length of a URI inside an NFT.
Definition Protocol.h:207
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
@ temMALFORMED
Definition TER.h:73
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tecNO_ENTRY
Definition TER.h:304
@ tecINTERNAL
Definition TER.h:308
@ tecNO_PERMISSION
Definition TER.h:303
BaseUInt< 256 > uint256
Definition base_uint.h:562
@ tesSUCCESS
Definition TER.h:240
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:18