rippled
Loading...
Searching...
No Matches
NFTokenModify.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2024 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/tx/detail/NFTokenModify.h>
21#include <xrpld/app/tx/detail/NFTokenUtils.h>
22
23#include <xrpl/protocol/Feature.h>
24#include <xrpl/protocol/TxFlags.h>
25
26namespace ripple {
27
30{
31 if (!ctx.rules.enabled(featureNonFungibleTokensV1_1) ||
32 !ctx.rules.enabled(featureDynamicNFT))
33 return temDISABLED;
34
35 if (NotTEC const ret = preflight1(ctx); !isTesSuccess(ret))
36 return ret;
37
38 if (ctx.tx.getFlags() & tfUniversalMask)
39 return temINVALID_FLAG;
40
41 if (auto owner = ctx.tx[~sfOwner]; owner == ctx.tx[sfAccount])
42 return temMALFORMED;
43
44 if (auto uri = ctx.tx[~sfURI])
45 {
46 if (uri->length() == 0 || uri->length() > maxTokenURILength)
47 return temMALFORMED;
48 }
49
50 return preflight2(ctx);
51}
52
53TER
55{
56 AccountID const account = ctx.tx[sfAccount];
57 AccountID const owner =
58 ctx.tx[ctx.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
59
60 if (!nft::findToken(ctx.view, owner, ctx.tx[sfNFTokenID]))
61 return tecNO_ENTRY;
62
63 // Check if the NFT is mutable
64 if (!(nft::getFlags(ctx.tx[sfNFTokenID]) & nft::flagMutable))
65 return tecNO_PERMISSION;
66
67 // Verify permissions for the issuer
68 if (AccountID const issuer = nft::getIssuer(ctx.tx[sfNFTokenID]);
69 issuer != account)
70 {
71 auto const sle = ctx.view.read(keylet::account(issuer));
72 if (!sle)
73 return tecINTERNAL; // LCOV_EXCL_LINE
74 if (auto const minter = (*sle)[~sfNFTokenMinter]; minter != account)
75 return tecNO_PERMISSION;
76 }
77
78 return tesSUCCESS;
79}
80
81TER
83{
84 uint256 const nftokenID = ctx_.tx[sfNFTokenID];
85 AccountID const owner =
86 ctx_.tx[ctx_.tx.isFieldPresent(sfOwner) ? sfOwner : sfAccount];
87
88 return nft::changeTokenURI(view(), owner, nftokenID, ctx_.tx[~sfURI]);
89}
90
91} // namespace ripple
TER doApply() override
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 enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Definition: Rules.cpp:130
bool isFieldPresent(SField const &field) const
Definition: STObject.cpp:484
std::uint32_t getFlags() const
Definition: STObject.cpp:537
ApplyView & view()
Definition: Transactor.h:159
ApplyContext & ctx_
Definition: Transactor.h:140
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition: Indexes.cpp:177
std::uint16_t getFlags(uint256 const &id)
Definition: nft.h:60
constexpr std::uint16_t const flagMutable
Definition: nft.h:57
AccountID getIssuer(uint256 const &id)
Definition: nft.h:120
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:26
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
Definition: Transactor.cpp:91
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
Definition: Transactor.cpp:160
std::size_t constexpr maxTokenURILength
The maximum length of a URI inside an NFT.
Definition: Protocol.h:86
@ tecNO_ENTRY
Definition: TER.h:306
@ tecINTERNAL
Definition: TER.h:310
@ tecNO_PERMISSION
Definition: TER.h:305
@ tesSUCCESS
Definition: TER.h:244
bool isTesSuccess(TER x) noexcept
Definition: TER.h:672
constexpr std::uint32_t tfUniversalMask
Definition: TxFlags.h:63
TERSubset< CanCvtToNotTEC > NotTEC
Definition: TER.h:603
@ temMALFORMED
Definition: TER.h:87
@ temINVALID_FLAG
Definition: TER.h:111
@ temDISABLED
Definition: TER.h:114
State information when determining if a tx is likely to claim a fee.
Definition: Transactor.h:79
ReadView const & view
Definition: Transactor.h:82
State information when preflighting a tx.
Definition: Transactor.h:34