20#include <xrpld/app/tx/detail/MPTokenAuthorize.h>
21#include <xrpld/app/tx/detail/MPTokenIssuanceCreate.h>
22#include <xrpld/app/tx/detail/VaultCreate.h>
23#include <xrpld/ledger/View.h>
25#include <xrpl/protocol/Asset.h>
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/MPTIssue.h>
29#include <xrpl/protocol/Protocol.h>
30#include <xrpl/protocol/STNumber.h>
31#include <xrpl/protocol/TER.h>
32#include <xrpl/protocol/TxFlags.h>
53 if (
auto const data = ctx.
tx[~sfData])
59 if (
auto const withdrawalPolicy = ctx.
tx[~sfWithdrawalPolicy])
66 if (
auto const domain = ctx.
tx[~sfDomainID])
68 if (*domain == beast::zero)
74 if (
auto const assetMax = ctx.
tx[~sfAssetsMaximum])
76 if (*assetMax < beast::zero)
80 if (
auto const metadata = ctx.
tx[~sfMPTokenMetadata])
82 if (metadata->length() == 0 ||
100 auto vaultAsset = ctx.
tx[sfAsset];
101 auto account = ctx.
tx[sfAccount];
103 if (vaultAsset.native())
105 else if (vaultAsset.holds<
MPTIssue>())
107 auto mptID = vaultAsset.get<
MPTIssue>().getMptID();
116 <<
"VaultCreate: vault assets are non-transferable.";
120 else if (vaultAsset.holds<
Issue>())
133 if (!vaultAsset.native())
143 if (
auto const domain = ctx.
tx[~sfDomainID])
145 auto const sleDomain =
154 accountId == beast::zero)
170 if (owner ==
nullptr)
178 auto ownerCount = owner->at(sfOwnerCount);
184 return maybePseudo.error();
185 auto& pseudo = *maybePseudo;
186 auto pseudoId = pseudo->at(sfAccount);
187 auto asset = tx[sfAsset];
193 auto txFlags = tx.getFlags();
208 .priorBalance = std::nullopt,
209 .account = pseudoId->value(),
212 .metadata = tx[~sfMPTokenMetadata],
213 .domainId = tx[~sfDomainID],
216 return maybeShare.error();
217 auto& share = *maybeShare;
219 vault->setFieldIssue(sfAsset,
STIssue{sfAsset, asset});
221 vault->at(sfSequence) = sequence;
223 vault->at(sfAccount) = pseudoId;
224 vault->at(sfAssetsTotal) =
Number(0);
225 vault->at(sfAssetsAvailable) =
Number(0);
226 vault->at(sfLossUnrealized) =
Number(0);
228 if (
auto value = tx[~sfAssetsMaximum])
229 vault->at(sfAssetsMaximum) = *value;
230 vault->at(sfShareMPTID) = share;
231 if (
auto value = tx[~sfData])
232 vault->at(sfData) = *value;
234 if (
auto value = tx[~sfWithdrawalPolicy])
235 vault->at(sfWithdrawalPolicy) = *value;
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
A currency issued by an account.
static Expected< MPTID, TER > create(ApplyView &view, beast::Journal journal, MPTCreateArgs const &args)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
bool isFieldPresent(SField const &field) const
std::uint32_t getFlags() const
std::uint32_t getSeqValue() const
Returns the first non-zero value of (Sequence, TicketSequence).
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static XRPAmount calculateBaseFee(ReadView const &view, STTx const &tx)
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Keylet mptIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Expected< std::shared_ptr< SLE >, TER > createPseudoAccount(ApplyView &view, uint256 const &pseudoOwnerKey, SField const &ownerField)
Create pseudo-account, storing pseudoOwnerKey into ownerField.
constexpr std::uint32_t const tfVaultPrivate
std::size_t constexpr maxDataPayloadLength
The maximum length of Data payload.
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
bool isFrozen(ReadView const &view, AccountID const &account, Currency const ¤cy, AccountID const &issuer)
std::size_t constexpr maxMPTokenMetadataLength
The maximum length of MPTokenMetadata.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
@ tecINSUFFICIENT_RESERVE
TER addEmptyHolding(ApplyView &view, AccountID const &accountID, XRPAmount priorBalance, Issue const &issue, beast::Journal journal)
constexpr std::uint32_t const tfVaultShareNonTransferable
AccountID pseudoAccountAddress(ReadView const &view, uint256 const &pseudoOwnerKey)
bool isTesSuccess(TER x) noexcept
std::uint8_t constexpr vaultStrategyFirstComeFirstServe
Vault withdrawal policies.
constexpr std::uint32_t const tfVaultCreateMask
bool isPseudoAccount(std::shared_ptr< SLE const > sleAcct)
TERSubset< CanCvtToNotTEC > NotTEC
TER dirLink(ApplyView &view, AccountID const &owner, std::shared_ptr< SLE > &object)
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.