1#include <xrpl/tx/transactors/nft/NFTokenMint.h>
3#include <xrpl/basics/base_uint.h>
4#include <xrpl/beast/utility/instrumentation.h>
5#include <xrpl/ledger/View.h>
6#include <xrpl/ledger/helpers/NFTokenHelpers.h>
7#include <xrpl/protocol/AccountID.h>
8#include <xrpl/protocol/Feature.h>
9#include <xrpl/protocol/Indexes.h>
10#include <xrpl/protocol/InnerObjectFormats.h>
11#include <xrpl/protocol/Protocol.h>
12#include <xrpl/protocol/SField.h>
13#include <xrpl/protocol/SOTemplate.h>
14#include <xrpl/protocol/STLedgerEntry.h>
15#include <xrpl/protocol/STObject.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/TER.h>
18#include <xrpl/protocol/TxFlags.h>
19#include <xrpl/protocol/XRPAmount.h>
20#include <xrpl/protocol/nft.h>
21#include <xrpl/tx/Transactor.h>
23#include <boost/endian/conversion.hpp>
73 return ctx.
rules.
enabled(featureDynamicNFT) ? tfNFTokenMintMask
80 return nfTokenMintMask;
86 if (
auto const f = ctx.
tx[~sfTransferFee])
93 if (f > 0u && !ctx.
tx.
isFlag(tfTransferable))
98 if (
auto iss = ctx.
tx[~sfIssuer]; iss == ctx.
tx[sfAccount])
101 if (
auto uri = ctx.
tx[~sfURI])
120 ctx.
tx[~sfDestination],
121 ctx.
tx[~sfExpiration],
149 flags = boost::endian::native_to_big(flags);
150 fee = boost::endian::native_to_big(fee);
152 tokenSeq = boost::endian::native_to_big(tokenSeq);
156 auto ptr = buf.
data();
161 ptr +=
sizeof(flags);
167 ptr += issuer.
size();
170 ptr +=
sizeof(taxon);
173 ptr +=
sizeof(tokenSeq);
176 "xrpl::NFTokenMint::createNFTokenID : data size matches the buffer");
186 if (
auto issuer = ctx.
tx[~sfIssuer])
193 if (
auto const minter = (*sle)[~sfNFTokenMinter]; minter != ctx.
tx[sfAccount])
209 ctx.
tx[~sfIssuer].value_or(ctx.
tx[sfAccount]),
211 ctx.
tx[~sfDestination],
213 ctx.
tx[~sfTransferFee].value_or(0),
226 auto const tokenSeq = [
this, &issuer]() -> std::expected<std::uint32_t, TER> {
249 if (!
root->isFieldPresent(sfFirstNFTokenSequence))
253 root->at(sfFirstNFTokenSequence) =
254 ctx_.tx.isFieldPresent(sfIssuer) ||
ctx_.tx.getSeqProxy().isTicket() ? acctSeq
258 std::uint32_t const mintedNftCnt = (*root)[~sfMintedNFTokens].valueOr(0u);
260 (*root)[sfMintedNFTokens] = mintedNftCnt + 1u;
261 if ((*
root)[sfMintedNFTokens] == 0u)
266 std::uint32_t const offset = (*root)[sfFirstNFTokenSequence];
270 if (tokenSeq + 1u == 0u || tokenSeq < offset)
277 if (!tokenSeq.has_value())
278 return (tokenSeq.error());
287 if (nfTokenTemplate ==
nullptr)
295 ctx_.tx[~sfTransferFee].value_or(0),
300 STObject newToken(*nfTokenTemplate, sfNFToken, [
this, &nftokenID](
STObject&
object) {
301 object.setFieldH256(sfNFTokenID, nftokenID);
303 if (
auto const uri =
ctx_.tx[~sfURI])
304 object.setFieldVL(sfURI, *uri);
311 if (
ctx_.tx.isFieldPresent(sfAmount))
320 ctx_.tx[~sfDestination],
321 ctx_.tx[~sfExpiration],
322 ctx_.tx.getSeqProxy(),
334 if (
auto const ownerCountAfter =
336 ownerCountAfter > ownerCountBefore)
338 if (
auto const reserve =
view().fees().accountReserve(ownerCountAfter);
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static BaseUInt fromVoid(void const *data)
static constexpr std::size_t size()
static uint256 createNFTokenID(std::uint16_t flags, std::uint16_t fee, AccountID const &issuer, nft::Taxon taxon, std::uint32_t tokenSeq)
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.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
virtual SLE::const_pointer 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.
Defines the fields and their attributes within a STObject.
std::shared_ptr< STLedgerEntry const > const & const_ref
bool isFlag(std::uint32_t) const
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
AccountID const accountID_
Keylet account(AccountID const &id) noexcept
AccountID root.
std::uint32_t toUInt32(Taxon t)
TER tokenOfferCreatePreclaim(ReadView const &view, AccountID const &acctID, AccountID const &nftIssuer, STAmount const &amount, std::optional< AccountID > const &dest, std::uint16_t nftFlags, std::uint16_t xferFee, beast::Journal j, std::optional< AccountID > const &owner=std::nullopt, std::uint32_t txFlags=tfSellNFToken)
Preclaim checks shared by NFTokenCreateOffer and NFTokenMint.
TER insertToken(ApplyView &view, AccountID owner, STObject &&nft)
Insert the token in the owner's token directory.
Taxon toTaxon(std::uint32_t i)
Taxon cipheredTaxon(std::uint32_t tokenSeq, Taxon taxon)
TER tokenOfferCreateApply(ApplyView &view, AccountID const &acctID, STAmount const &amount, std::optional< AccountID > const &dest, std::optional< std::uint32_t > const &expiration, SeqProxy seqProxy, uint256 const &nftokenID, XRPAmount const &priorBalance, beast::Journal j, std::uint32_t txFlags=tfSellNFToken)
doApply implementation shared by NFTokenCreateOffer and NFTokenMint
NotTEC tokenOfferCreatePreflight(AccountID const &acctID, STAmount const &amount, std::optional< AccountID > const &dest, std::optional< std::uint32_t > const &expiration, std::uint16_t nftFlags, Rules const &rules, std::optional< AccountID > const &owner=std::nullopt, std::uint32_t txFlags=tfSellNFToken)
Preflight checks shared by NFTokenCreateOffer and NFTokenMint.
TaggedInteger< std::uint32_t, TaxonTag > Taxon
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool hasExpired(ReadView const &view, std::optional< std::uint32_t > const &exp)
Determines whether the given expiration time has passed.
constexpr std::size_t kMaxTokenUriLength
The maximum length of a URI inside an NFT.
constexpr FlagValue tfNFTokenMintMaskWithoutMutable
constexpr FlagValue tfNFTokenMintOldMaskWithMutable
static bool hasOfferFields(PreflightContext const &ctx)
Number root(Number f, unsigned d)
TERSubset< CanCvtToNotTEC > NotTEC
constexpr FlagValue tfNFTokenMintOldMask
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
constexpr std::uint16_t kMaxTransferFee
The maximum token transfer fee allowed.
@ temBAD_NFTOKEN_TRANSFER_FEE
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
@ tecMAX_SEQUENCE_REACHED
static std::uint16_t extractNFTokenFlagsFromTxFlags(std::uint32_t txFlags)
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.