1#include <xrpl/tx/transactors/token/MPTokenIssuanceCreate.h>
3#include <xrpl/beast/utility/Journal.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/ReadView.h>
8#include <xrpl/ledger/helpers/AccountRootHelpers.h>
9#include <xrpl/ledger/helpers/DirectoryHelpers.h>
10#include <xrpl/ledger/helpers/SponsorHelpers.h>
11#include <xrpl/protocol/Feature.h>
12#include <xrpl/protocol/Indexes.h>
13#include <xrpl/protocol/LedgerFormats.h>
14#include <xrpl/protocol/Protocol.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STLedgerEntry.h>
17#include <xrpl/protocol/STTx.h>
18#include <xrpl/protocol/TER.h>
19#include <xrpl/protocol/TxFlags.h>
20#include <xrpl/protocol/UintTypes.h>
21#include <xrpl/protocol/XRPAmount.h>
22#include <xrpl/tx/Transactor.h>
41 if (ctx.
tx.
isFlag(tfMPTCanHoldConfidentialBalance) &&
46 auto const immutableFlags = ctx.
tx[~sfImmutableFlags];
62 return tfMPTokenIssuanceCreateMask;
75 if (
auto const immutableFlags = ctx.
tx[~sfImmutableFlags]; immutableFlags &&
79 if (
auto const fee = ctx.
tx[~sfTransferFee])
86 if (fee > 0u && !ctx.
tx.
isFlag(tfMPTCanTransfer))
90 if (fee > 0u && ctx.
tx.
isFlag(tfMPTCanHoldConfidentialBalance))
94 if (
auto const domain = ctx.
tx[~sfDomainID])
100 if (!ctx.
tx.
isFlag(tfMPTRequireAuth))
104 if (
auto const metadata = ctx.
tx[~sfMPTokenMetadata])
111 if (
auto const maxAmt = ctx.
tx[~sfMaximumAmount])
122std::expected<MPTID, TER>
136 auto const sponsorSle = *sponsorExp;
141 ctx, acct, *(args.
priorBalance), sponsorSle, {.ownerCountDelta = 1}, journal);
159 (*mptIssuance)[sfIssuer] = args.
account;
160 (*mptIssuance)[sfOutstandingAmount] = 0;
161 (*mptIssuance)[sfOwnerNode] = *ownerNode;
162 (*mptIssuance)[sfSequence] = args.
sequence;
165 (*mptIssuance)[sfMaximumAmount] = *args.
maxAmount;
168 (*mptIssuance)[sfAssetScale] = *args.
assetScale;
174 (*mptIssuance)[sfMPTokenMetadata] = *args.
metadata;
177 (*mptIssuance)[sfDomainID] = *args.
domainId;
192 auto const type = sleHolding->getType();
193 if (type != ltMPTOKEN && type != ltRIPPLE_STATE)
212 auto const& tx =
ctx_.tx;
213 auto const result =
create(
214 ctx_.getApplyViewContext(),
217 .priorBalance = preFeeBalance_,
218 .account = accountID_,
219 .sequence = tx.getSeqProxy().value(),
220 .flags = tx.getFlags(),
221 .maxAmount = tx[~sfMaximumAmount],
222 .assetScale = tx[~sfAssetScale],
223 .transferFee = tx[~sfTransferFee],
224 .metadata = tx[~sfMPTokenMetadata],
225 .domainId = tx[~sfDomainID],
226 .immutableFlags = tx[~sfImmutableFlags],
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void insert(SLE::ref sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(SLE::ref)> const &describe)
Insert an entry to a directory.
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.
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
static bool checkExtraFeatures(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static std::expected< MPTID, TER > create(ApplyViewContext ctx, beast::Journal journal, MPTCreateArgs const &args)
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.
std::shared_ptr< STLedgerEntry const > const & const_ref
bool isFlag(std::uint32_t) const
bool isFieldPresent(SField const &field) const
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void increaseOwnerCount(ApplyView &view, SLE::ref accountSle, SLE::ref sponsorSle, std::uint32_t count, beast::Journal j)
Increase owner-count fields when the caller supplies the sponsor.
constexpr FlagValue tfUniversal
std::expected< SLE::pointer, TER > getEffectiveTxReserveSponsor(ApplyViewContext ctx, SLE::const_ref accountSle)
The transaction's reserve sponsor for the given account, if applicable.
void addSponsorToLedgerEntry(SLE::ref sle, SLE::const_ref sponsorSle, SF_ACCOUNT const &field=sfSponsor)
Stamp a reserve sponsor onto a ledger entry using an explicit sponsor SLE.
TERSubset< CanCvtToNotTEC > NotTEC
constexpr std::size_t kMaxMpTokenMetadataLength
The maximum length of MPTokenMetadata.
constexpr FlagValue tifMPTokenIssuanceImmutableMask
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
MPTID makeMptID(std::uint32_t const sequence, AccountID const &account)
constexpr std::uint16_t kMaxTransferFee
The maximum token transfer fee allowed.
TER checkReserve(ApplyViewContext ctx, SLE::const_ref accSle, XRPAmount accBalance, SLE::const_ref sponsorSle, Adjustment adj, beast::Journal j, TER insufReserveCode=tecINSUFFICIENT_RESERVE)
Check if an account has sufficient reserve.
constexpr FlagValue tifMPTCanHoldConfidentialBalance
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
Bundles the mutable ledger view and the transaction being applied.
AccountID const & account
std::optional< std::uint64_t > maxAmount
std::optional< std::uint16_t > transferFee
std::optional< std::uint32_t > immutableFlags
std::optional< uint256 > domainId
std::optional< uint256 > referenceHolding
std::optional< XRPAmount > priorBalance
std::optional< Slice > const & metadata
std::optional< std::uint8_t > assetScale
State information when preflighting a tx.