1#include <xrpld/app/tx/detail/DepositPreauth.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/CredentialHelpers.h>
5#include <xrpl/ledger/View.h>
6#include <xrpl/protocol/Feature.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/TxFlags.h>
18 bool const unauthArrPresent =
20 bool const authCredPresent = authArrPresent || unauthArrPresent;
22 if (authCredPresent && !ctx.
rules.
enabled(featureCredentials))
32 bool const unauthArrPresent =
34 int const authCredPresent =
35 static_cast<int>(authArrPresent) +
static_cast<int>(unauthArrPresent);
37 auto const optAuth = ctx.
tx[~sfAuthorize];
38 auto const optUnauth = ctx.
tx[~sfUnauthorize];
39 int const authPresent =
static_cast<int>(optAuth.has_value()) +
40 static_cast<int>(optUnauth.has_value());
42 if (authPresent + authCredPresent != 1)
46 <<
"Malformed transaction: "
47 "Invalid Authorize and Unauthorize field combination.";
54 AccountID const& target(optAuth ? *optAuth : *optUnauth);
58 <<
"Malformed transaction: Authorized or Unauthorized "
64 if (optAuth && (target == ctx.
tx[sfAccount]))
67 <<
"Malformed transaction: Attempting to DepositPreauth self.";
75 authArrPresent ? sfAuthorizeCredentials
76 : sfUnauthorizeCredentials),
115 for (
auto const& o : authCred)
117 auto const& issuer = o[sfIssuer];
120 auto [it, ins] = sorted.
emplace(issuer, o[sfCredentialType]);
156 sleOwner->getFieldU32(sfOwnerCount) + 1)};
168 slePreauth->setAccountID(sfAccount,
account_);
169 slePreauth->setAccountID(sfAuthorize, auth);
177 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
179 << (page ?
"success" :
"failure");
184 slePreauth->setFieldU64(sfOwnerNode, *page);
207 sleOwner->getFieldU32(sfOwnerCount) + 1)};
218 STArray sortedLE(sfAuthorizeCredentials, sortedTX.size());
219 for (
auto const& p : sortedTX)
222 cred.setAccountID(sfIssuer, p.first);
223 cred.setFieldVL(sfCredentialType, p.second);
232 slePreauth->setAccountID(sfAccount,
account_);
233 slePreauth->peekFieldArray(sfAuthorizeCredentials) =
241 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
243 << (page ?
"success" :
"failure");
248 slePreauth->setFieldU64(sfOwnerNode, *page);
275 JLOG(j.
warn()) <<
"Selected DepositPreauth does not exist.";
279 AccountID const account{(*slePreauth)[sfAccount]};
284 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.