1#include <xrpl/tx/transactors/vault/VaultSet.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/beast/utility/Zero.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/Indexes.h>
7#include <xrpl/protocol/LedgerFormats.h>
8#include <xrpl/protocol/Protocol.h>
9#include <xrpl/protocol/SField.h>
10#include <xrpl/protocol/STLedgerEntry.h>
11#include <xrpl/protocol/STNumber.h>
12#include <xrpl/protocol/STTakesAsset.h>
13#include <xrpl/protocol/STTx.h>
14#include <xrpl/protocol/TER.h>
15#include <xrpl/protocol/XRPAmount.h>
16#include <xrpl/tx/Transactor.h>
29 if (ctx.
tx[sfVaultID] == beast::kZero)
31 JLOG(ctx.
j.
debug()) <<
"VaultSet: zero/empty vault ID.";
35 if (
auto const data = ctx.
tx[~sfData])
39 JLOG(ctx.
j.
debug()) <<
"VaultSet: invalid data payload size.";
44 if (
auto const assetMax = ctx.
tx[~sfAssetsMaximum])
46 if (*assetMax < beast::kZero)
48 JLOG(ctx.
j.
debug()) <<
"VaultSet: invalid max assets.";
56 JLOG(ctx.
j.
debug()) <<
"VaultSet: nothing is being updated.";
71 if (ctx.
tx[sfAccount] != vault->at(sfOwner))
73 JLOG(ctx.
j.
debug()) <<
"VaultSet: account is not an owner.";
77 auto const mptIssuanceID = (*vault)[sfShareMPTID];
82 JLOG(ctx.
j.
error()) <<
"VaultSet: missing issuance of vault shares.";
87 if (
auto const domain = ctx.
tx[~sfDomainID])
90 if (!vault->isFlag(lsfVaultPrivate))
92 JLOG(ctx.
j.
debug()) <<
"VaultSet: vault is not private";
96 if (*domain != beast::kZero)
104 if (!sleIssuance->isFlag(lsfMPTRequireAuth))
107 JLOG(ctx.
j.
error()) <<
"VaultSet: issuance of vault shares is not private.";
123 auto const& tx =
ctx_.tx;
130 auto const vaultAsset = vault->at(sfAsset);
132 auto const mptIssuanceID = (*vault)[sfShareMPTID];
137 JLOG(
j_.error()) <<
"VaultSet: missing issuance of vault shares.";
143 if (tx.isFieldPresent(sfData))
144 vault->at(sfData) = tx[sfData];
145 if (tx.isFieldPresent(sfAssetsMaximum))
147 if (tx[sfAssetsMaximum] != 0 && tx[sfAssetsMaximum] < *vault->at(sfAssetsTotal))
149 vault->at(sfAssetsMaximum) = tx[sfAssetsMaximum];
152 if (
auto const domainId = tx[~sfDomainID]; domainId)
154 if (*domainId != beast::kZero)
161 sleIssuance->setFieldH256(sfDomainID, *domainId);
163 else if (sleIssuance->isFieldPresent(sfDomainID))
165 sleIssuance->makeFieldAbsent(sfDomainID);
A generic endpoint for log messages.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void update(SLE::ref sle)=0
Indicate changes to a peeked SLE.
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 isFieldPresent(SField const &field) const
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 bool checkExtraFeatures(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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 NotTEC preflight(PreflightContext const &ctx)
Keylet mptokenIssuance(std::uint32_t seq, AccountID const &issuer) noexcept
Keylet vault(AccountID const &owner, std::uint32_t seq) noexcept
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
constexpr std::size_t kMaxDataPayloadLength
The maximum length of Data payload.
TERSubset< CanCvtToNotTEC > NotTEC
TERSubset< CanCvtToTER > TER
void associateAsset(STLedgerEntry &sle, Asset const &asset)
Associate an Asset with all sMD_NeedsAsset fields in a ledger entry.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.