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/AccountRootHelpers.h>
7#include <xrpl/ledger/helpers/NFTokenHelpers.h>
8#include <xrpl/protocol/AccountID.h>
9#include <xrpl/protocol/Feature.h>
10#include <xrpl/protocol/Indexes.h>
11#include <xrpl/protocol/InnerObjectFormats.h>
12#include <xrpl/protocol/Protocol.h>
13#include <xrpl/protocol/SField.h>
14#include <xrpl/protocol/SOTemplate.h>
15#include <xrpl/protocol/STLedgerEntry.h>
16#include <xrpl/protocol/STObject.h>
17#include <xrpl/protocol/STTx.h>
18#include <xrpl/protocol/TER.h>
19#include <xrpl/protocol/TxFlags.h>
20#include <xrpl/protocol/XRPAmount.h>
21#include <xrpl/protocol/nft.h>
22#include <xrpl/tx/Transactor.h>
24#include <boost/endian/conversion.hpp>
74 return ctx.
rules.
enabled(featureDynamicNFT) ? tfNFTokenMintMask
81 return nfTokenMintMask;
87 if (
auto const f = ctx.
tx[~sfTransferFee])
94 if (f > 0u && !ctx.
tx.
isFlag(tfTransferable))
99 if (
auto iss = ctx.
tx[~sfIssuer]; iss == ctx.
tx[sfAccount])
102 if (
auto uri = ctx.
tx[~sfURI])
121 ctx.
tx[~sfDestination],
122 ctx.
tx[~sfExpiration],
150 flags = boost::endian::native_to_big(flags);
151 fee = boost::endian::native_to_big(fee);
153 tokenSeq = boost::endian::native_to_big(tokenSeq);
157 auto ptr = buf.
data();
162 ptr +=
sizeof(flags);
168 ptr += issuer.
size();
171 ptr +=
sizeof(taxon);
174 ptr +=
sizeof(tokenSeq);
177 "xrpl::NFTokenMint::createNFTokenID : data size matches the buffer");
187 if (
auto issuer = ctx.
tx[~sfIssuer])
194 if (
auto const minter = (*sle)[~sfNFTokenMinter]; minter != ctx.
tx[sfAccount])
210 ctx.
tx[~sfIssuer].value_or(ctx.
tx[sfAccount]),
212 ctx.
tx[~sfDestination],
214 ctx.
tx[~sfTransferFee].value_or(0),
227 auto const tokenSeq = [
this, &issuer]() -> std::expected<std::uint32_t, TER> {
250 if (!
root->isFieldPresent(sfFirstNFTokenSequence))
254 root->at(sfFirstNFTokenSequence) =
255 ctx_.tx.isFieldPresent(sfIssuer) ||
ctx_.tx.getSeqProxy().isTicket() ? acctSeq
259 std::uint32_t const mintedNftCnt = (*root)[~sfMintedNFTokens].valueOr(0u);
261 (*root)[sfMintedNFTokens] = mintedNftCnt + 1u;
262 if ((*
root)[sfMintedNFTokens] == 0u)
267 std::uint32_t const offset = (*root)[sfFirstNFTokenSequence];
271 if (tokenSeq + 1u == 0u || tokenSeq < offset)
278 if (!tokenSeq.has_value())
279 return (tokenSeq.error());
288 if (nfTokenTemplate ==
nullptr)
296 ctx_.tx[~sfTransferFee].value_or(0),
301 STObject newToken(*nfTokenTemplate, sfNFToken, [
this, &nftokenID](
STObject&
object) {
302 object.setFieldH256(sfNFTokenID, nftokenID);
304 if (
auto const uri =
ctx_.tx[~sfURI])
305 object.setFieldVL(sfURI, *uri);
312 if (
ctx_.tx.isFieldPresent(sfAmount))
321 ctx_.tx[~sfDestination],
322 ctx_.tx[~sfExpiration],
323 ctx_.tx.getSeqProxy(),
339 if (
auto const ownerCountAfter = sleAccount->getFieldU32(sfOwnerCount);
340 ownerCountAfter > ownerCountBefore)
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, ExpiryComparison comparison=ExpiryComparison::Inclusive)
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)
XRPAmount accountReserve(ReadView const &view, SLE::const_ref sle, beast::Journal j, Adjustment adj={})
Returns the account reserve, in drops.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.