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 = ctx.
tx.
isFieldPresent(sfUnauthorizeCredentials);
19 bool const authCredPresent = authArrPresent || unauthArrPresent;
21 if (authCredPresent && !ctx.
rules.
enabled(featureCredentials))
31 bool const unauthArrPresent = ctx.
tx.
isFieldPresent(sfUnauthorizeCredentials);
32 int const authCredPresent =
static_cast<int>(authArrPresent) +
static_cast<int>(unauthArrPresent);
34 auto const optAuth = ctx.
tx[~sfAuthorize];
35 auto const optUnauth = ctx.
tx[~sfUnauthorize];
36 int const authPresent =
static_cast<int>(optAuth.has_value()) +
static_cast<int>(optUnauth.has_value());
38 if (authPresent + authCredPresent != 1)
41 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: "
42 "Invalid Authorize and Unauthorize field combination.";
49 AccountID const& target(optAuth ? *optAuth : *optUnauth);
52 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Authorized or Unauthorized "
58 if (optAuth && (target == ctx.
tx[sfAccount]))
60 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Attempting to DepositPreauth self.";
67 ctx.
tx.
getFieldArray(authArrPresent ? sfAuthorizeCredentials : sfUnauthorizeCredentials),
105 for (
auto const& o : authCred)
107 auto const& issuer = o[sfIssuer];
110 auto [it, ins] = sorted.
emplace(issuer, o[sfCredentialType]);
155 slePreauth->setAccountID(sfAccount,
account_);
156 slePreauth->setAccountID(sfAuthorize, auth);
161 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory " <<
to_string(preauthKeylet.
key) <<
": "
162 << (page ?
"success" :
"failure");
167 slePreauth->setFieldU64(sfOwnerNode, *page);
198 STArray sortedLE(sfAuthorizeCredentials, sortedTX.size());
199 for (
auto const& p : sortedTX)
202 cred.setAccountID(sfIssuer, p.first);
203 cred.setFieldVL(sfCredentialType, p.second);
212 slePreauth->setAccountID(sfAccount,
account_);
213 slePreauth->peekFieldArray(sfAuthorizeCredentials) = std::move(sortedLE);
219 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory " <<
to_string(preauthKey.
key) <<
": "
220 << (page ?
"success" :
"failure");
225 slePreauth->setFieldU64(sfOwnerNode, *page);
232 auto const preauthKey =
247 JLOG(j.
warn()) <<
"Selected DepositPreauth does not exist.";
251 AccountID const account{(*slePreauth)[sfAccount]};
256 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 erase(std::shared_ptr< SLE > const &sle)=0
Remove a peeked SLE.
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.
static TER removeFromLedger(ApplyView &view, uint256 const &delIndex, beast::Journal j)
static NotTEC preflight(PreflightContext const &ctx)
static bool checkExtraFeatures(PreflightContext const &ctx)
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)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
Keylet depositPreauth(AccountID const &owner, AccountID const &preauthorized) noexcept
A DepositPreauth.
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::string to_string(base_uint< Bits, Tag > const &a)
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::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
bool isTesSuccess(TER x) noexcept
@ tecINSUFFICIENT_RESERVE
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.