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>
37 bool const unauthArrPresent =
39 bool const authCredPresent = authArrPresent || unauthArrPresent;
41 if (authCredPresent && !ctx.
rules.
enabled(featureCredentials))
51 bool const unauthArrPresent =
53 int const authCredPresent =
54 static_cast<int>(authArrPresent) +
static_cast<int>(unauthArrPresent);
56 auto const optAuth = ctx.
tx[~sfAuthorize];
57 auto const optUnauth = ctx.
tx[~sfUnauthorize];
58 int const authPresent =
static_cast<int>(optAuth.has_value()) +
59 static_cast<int>(optUnauth.has_value());
61 if (authPresent + authCredPresent != 1)
65 <<
"Malformed transaction: "
66 "Invalid Authorize and Unauthorize field combination.";
73 AccountID const& target(optAuth ? *optAuth : *optUnauth);
77 <<
"Malformed transaction: Authorized or Unauthorized "
83 if (optAuth && (target == ctx.
tx[sfAccount]))
86 <<
"Malformed transaction: Attempting to DepositPreauth self.";
94 authArrPresent ? sfAuthorizeCredentials
95 : sfUnauthorizeCredentials),
134 for (
auto const& o : authCred)
136 auto const& issuer = o[sfIssuer];
139 auto [it, ins] = sorted.
emplace(issuer, o[sfCredentialType]);
175 sleOwner->getFieldU32(sfOwnerCount) + 1)};
187 slePreauth->setAccountID(sfAccount,
account_);
188 slePreauth->setAccountID(sfAuthorize, auth);
196 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
198 << (page ?
"success" :
"failure");
203 slePreauth->setFieldU64(sfOwnerNode, *page);
226 sleOwner->getFieldU32(sfOwnerCount) + 1)};
237 STArray sortedLE(sfAuthorizeCredentials, sortedTX.size());
238 for (
auto const& p : sortedTX)
241 cred.setAccountID(sfIssuer, p.first);
242 cred.setFieldVL(sfCredentialType, p.second);
251 slePreauth->setAccountID(sfAccount,
account_);
252 slePreauth->peekFieldArray(sfAuthorizeCredentials) =
260 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
262 << (page ?
"success" :
"failure");
267 slePreauth->setFieldU64(sfOwnerNode, *page);
294 JLOG(j.
warn()) <<
"Selected DepositPreauth does not exist.";
298 AccountID const account{(*slePreauth)[sfAccount]};
303 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 bool checkExtraFeatures(PreflightContext const &ctx)
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)
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
@ tecINSUFFICIENT_RESERVE
bool isTesSuccess(TER x) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)
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.