20#include <xrpld/app/tx/detail/DepositPreauth.h>
22#include <xrpl/basics/Log.h>
23#include <xrpl/ledger/CredentialHelpers.h>
24#include <xrpl/ledger/View.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/TxFlags.h>
40 bool const unauthArrPresent =
42 int const authCredPresent =
43 static_cast<int>(authArrPresent) +
static_cast<int>(unauthArrPresent);
45 if (authCredPresent && !ctx.
rules.
enabled(featureCredentials))
55 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Invalid flags set.";
59 auto const optAuth = ctx.
tx[~sfAuthorize];
60 auto const optUnauth = ctx.
tx[~sfUnauthorize];
61 int const authPresent =
static_cast<int>(optAuth.has_value()) +
62 static_cast<int>(optUnauth.has_value());
64 if (authPresent + authCredPresent != 1)
68 <<
"Malformed transaction: "
69 "Invalid Authorize and Unauthorize field combination.";
76 AccountID const& target(optAuth ? *optAuth : *optUnauth);
80 <<
"Malformed transaction: Authorized or Unauthorized "
86 if (optAuth && (target == ctx.
tx[sfAccount]))
89 <<
"Malformed transaction: Attempting to DepositPreauth self.";
97 authArrPresent ? sfAuthorizeCredentials
98 : sfUnauthorizeCredentials),
137 for (
auto const& o : authCred)
139 auto const& issuer = o[sfIssuer];
142 auto [it, ins] = sorted.
emplace(issuer, o[sfCredentialType]);
178 sleOwner->getFieldU32(sfOwnerCount) + 1)};
190 slePreauth->setAccountID(sfAccount,
account_);
191 slePreauth->setAccountID(sfAuthorize, auth);
199 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
201 << (page ?
"success" :
"failure");
206 slePreauth->setFieldU64(sfOwnerNode, *page);
229 sleOwner->getFieldU32(sfOwnerCount) + 1)};
240 STArray sortedLE(sfAuthorizeCredentials, sortedTX.size());
241 for (
auto const& p : sortedTX)
244 cred.setAccountID(sfIssuer, p.first);
245 cred.setFieldVL(sfCredentialType, p.second);
254 slePreauth->setAccountID(sfAccount,
account_);
255 slePreauth->peekFieldArray(sfAuthorizeCredentials) =
263 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
265 << (page ?
"success" :
"failure");
270 slePreauth->setFieldU64(sfOwnerNode, *page);
297 JLOG(j.
warn()) <<
"Selected DepositPreauth does not exist.";
301 AccountID const account{(*slePreauth)[sfAccount]};
305 JLOG(j.
fatal()) <<
"Unable to delete DepositPreauth from owner.";
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
Writeable view to a ledger, for applying a transaction.
bool dirRemove(Keylet const &directory, std::uint64_t page, uint256 const &key, bool keepRoot)
Remove an entry from a directory.
virtual void insert(std::shared_ptr< SLE > const &sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(std::shared_ptr< SLE > const &)> const &describe)
Insert an entry to a directory.
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
static NotTEC preflight(PreflightContext const &ctx)
static TER removeFromLedger(ApplyView &view, uint256 const &delIndex, beast::Journal j)
static TER preclaim(PreclaimContext const &ctx)
virtual Fees const & fees() const =0
Returns the fees for the base ledger.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
void push_back(STObject const &object)
STArray const & getFieldArray(SField const &field) const
bool isFieldPresent(SField const &field) const
static STObject makeInnerObject(SField const &name)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
@ tecINSUFFICIENT_RESERVE
bool isTesSuccess(TER x) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfUniversalMask
TERSubset< CanCvtToNotTEC > NotTEC
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.