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/protocol/Feature.h>
11#include <xrpl/protocol/Indexes.h>
12#include <xrpl/protocol/LedgerFormats.h>
13#include <xrpl/protocol/Protocol.h>
14#include <xrpl/protocol/SField.h>
15#include <xrpl/protocol/STLedgerEntry.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/TER.h>
18#include <xrpl/protocol/TxFlags.h>
19#include <xrpl/protocol/UintTypes.h>
20#include <xrpl/protocol/XRPAmount.h>
21#include <xrpl/tx/Transactor.h>
40 if (ctx.
tx.
isFlag(tfMPTCanHoldConfidentialBalance) &&
45 auto const mutableFlags = ctx.
tx[~sfMutableFlags];
46 return !mutableFlags ||
55 return tfMPTokenIssuanceCreateMask;
68 if (
auto const mutableFlags = ctx.
tx[~sfMutableFlags]; mutableFlags &&
72 if (
auto const fee = ctx.
tx[~sfTransferFee])
79 if (fee > 0u && !ctx.
tx.
isFlag(tfMPTCanTransfer))
83 if (fee > 0u && ctx.
tx.
isFlag(tfMPTCanHoldConfidentialBalance))
87 if (
auto const domain = ctx.
tx[~sfDomainID])
89 if (*domain == beast::kZero)
93 if (!ctx.
tx.
isFlag(tfMPTRequireAuth))
97 if (
auto const metadata = ctx.
tx[~sfMPTokenMetadata])
104 if (
auto const maxAmt = ctx.
tx[~sfMaximumAmount])
115std::expected<MPTID, TER>
123 *(args.
priorBalance) <
view.fees().accountReserve((*acct)[sfOwnerCount] + 1))
131 auto const ownerNode =
view.dirInsert(
139 (*mptIssuance)[sfIssuer] = args.
account;
140 (*mptIssuance)[sfOutstandingAmount] = 0;
141 (*mptIssuance)[sfOwnerNode] = *ownerNode;
142 (*mptIssuance)[sfSequence] = args.
sequence;
145 (*mptIssuance)[sfMaximumAmount] = *args.
maxAmount;
148 (*mptIssuance)[sfAssetScale] = *args.
assetScale;
154 (*mptIssuance)[sfMPTokenMetadata] = *args.
metadata;
157 (*mptIssuance)[sfDomainID] = *args.
domainId;
172 auto const type = sleHolding->getType();
173 if (type != ltMPTOKEN && type != ltRIPPLE_STATE)
178 view.insert(mptIssuance);
190 auto const& tx =
ctx_.tx;
191 auto const result =
create(
197 .sequence = tx.getSeqValue(),
198 .flags = tx.getFlags(),
199 .maxAmount = tx[~sfMaximumAmount],
200 .assetScale = tx[~sfAssetScale],
201 .transferFee = tx[~sfTransferFee],
202 .metadata = tx[~sfMPTokenMetadata],
203 .domainId = tx[~sfDomainID],
204 .mutableFlags = tx[~sfMutableFlags],
A generic endpoint for log messages.
Writeable view to a ledger, for applying a transaction.
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(ApplyView &view, beast::Journal journal, MPTCreateArgs const &args)
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
AccountID const accountID_
Keylet unchecked(uint256 const &key) noexcept
Any ledger entry.
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr FlagValue tmfMPTCannotEnableCanHoldConfidentialBalance
constexpr FlagValue tmfMPTokenIssuanceCreateMutableMask
constexpr FlagValue tfUniversal
TERSubset< CanCvtToNotTEC > NotTEC
constexpr std::size_t kMaxMpTokenMetadataLength
The maximum length of MPTokenMetadata.
void adjustOwnerCount(ApplyView &view, SLE::ref sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Returns a function that sets the owner on a directory SLE.
constexpr std::uint16_t kMaxTransferFee
The maximum token transfer fee allowed.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
constexpr std::uint64_t kMaxMpTokenAmount
The maximum amount of MPTokenIssuance.
MPTID makeMptID(std::uint32_t sequence, AccountID const &account)
std::optional< std::uint32_t > mutableFlags
AccountID const & account
std::optional< std::uint64_t > maxAmount
std::optional< std::uint16_t > transferFee
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.