1#include <xrpl/tx/transactors/vault/VaultSet.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/Number.h>
5#include <xrpl/beast/utility/Zero.h>
6#include <xrpl/ledger/helpers/VaultHelpers.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/LedgerFormats.h>
10#include <xrpl/protocol/Protocol.h>
11#include <xrpl/protocol/SField.h>
12#include <xrpl/protocol/STAmount.h>
13#include <xrpl/protocol/STLedgerEntry.h>
14#include <xrpl/protocol/STNumber.h>
15#include <xrpl/protocol/STTakesAsset.h>
16#include <xrpl/protocol/STTx.h>
17#include <xrpl/protocol/TER.h>
18#include <xrpl/protocol/XRPAmount.h>
19#include <xrpl/tx/Transactor.h>
34 JLOG(ctx.
j.
debug()) <<
"VaultSet: zero/empty vault ID.";
38 if (
auto const data = ctx.
tx[~sfData])
42 JLOG(ctx.
j.
debug()) <<
"VaultSet: invalid data payload size.";
47 if (
auto const assetMax = ctx.
tx[~sfAssetsMaximum])
51 JLOG(ctx.
j.
debug()) <<
"VaultSet: invalid max assets.";
59 JLOG(ctx.
j.
debug()) <<
"VaultSet: nothing is being updated.";
74 if (ctx.
tx[sfAccount] != vault->at(sfOwner))
76 JLOG(ctx.
j.
debug()) <<
"VaultSet: account is not an owner.";
82 if (
auto const assetMax = ctx.
tx[~sfAssetsMaximum]; assetMax &&
86 JLOG(ctx.
j.
debug()) <<
"VaultSet: max assets out of range for the asset.";
90 auto const mptIssuanceID = (*vault)[sfShareMPTID];
95 JLOG(ctx.
j.
error()) <<
"VaultSet: missing issuance of vault shares.";
100 if (
auto const domain = ctx.
tx[~sfDomainID])
103 if (!vault->isFlag(lsfVaultPrivate))
105 JLOG(ctx.
j.
debug()) <<
"VaultSet: vault is not private";
117 if (!sleIssuance->isFlag(lsfMPTRequireAuth))
120 JLOG(ctx.
j.
error()) <<
"VaultSet: issuance of vault shares is not private.";
130 if (
auto const assetMax = ctx.
tx[~sfAssetsMaximum];
135 JLOG(ctx.
j.
debug()) <<
"VaultSet: AssetsMaximum " << *assetMax
136 <<
" is not representable at the Vault scale.";
151 auto const& tx =
ctx_.tx;
158 auto const vaultAsset = vault->at(sfAsset);
160 auto const mptIssuanceID = (*vault)[sfShareMPTID];
165 JLOG(
j_.error()) <<
"VaultSet: missing issuance of vault shares.";
171 if (tx.isFieldPresent(sfData))
172 vault->at(sfData) = tx[sfData];
173 if (tx.isFieldPresent(sfAssetsMaximum))
175 if (tx[sfAssetsMaximum] != 0 && tx[sfAssetsMaximum] <
getAssetsTotal(vault))
177 vault->at(sfAssetsMaximum) = tx[sfAssetsMaximum];
180 if (
auto const domainId = tx[~sfDomainID]; domainId)
189 sleIssuance->setFieldH256(sfDomainID, *domainId);
191 else if (sleIssuance->isFieldPresent(sfDomainID))
193 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 Rules const & rules() const =0
Returns the tx processing rules.
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 & ConstRef
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::ConstRef before, SLE::ConstRef after) override
Inspect a single ledger entry modified by this transaction.
static NotTEC preflight(PreflightContext const &ctx)
Keylet vault(AccountID const &owner, SeqProxy const &seq) noexcept
Keylet permissionedDomain(AccountID const &account, SeqProxy const &seq) noexcept
Keylet mptokenIssuance(MPTID const &issuanceID) noexcept
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
TER checkAssetsMaximum(SLE::ConstRef vault, Number const &amount)
Checks that a requested AssetsMaximum is exactly representable on the Vault's base grid,...
constexpr std::size_t kMaxDataPayloadLength
The maximum length of Data payload.
TERSubset< CanCvtToNotTEC > NotTEC
bool isRepresentable(Asset const &asset, Number const &value)
Check whether an arbitrary precision Number can be converted to an STAmount of a given Asset without ...
bool isTesSuccess(TER x) noexcept
TERSubset< CanCvtToTER > TER
Number getAssetsTotal(SLE::ConstRef vault)
Return the Vault's current assets total.
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.