1#include <xrpl/basics/Log.h>
2#include <xrpl/ledger/View.h>
3#include <xrpl/ledger/helpers/AccountRootHelpers.h>
4#include <xrpl/ledger/helpers/CredentialHelpers.h>
5#include <xrpl/ledger/helpers/DirectoryHelpers.h>
6#include <xrpl/protocol/Feature.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/TxFlags.h>
9#include <xrpl/tx/transactors/payment/DepositPreauth.h>
19 bool const unauthArrPresent = ctx.
tx.
isFieldPresent(sfUnauthorizeCredentials);
20 bool const authCredPresent = authArrPresent || unauthArrPresent;
22 return !authCredPresent || ctx.
rules.
enabled(featureCredentials);
29 bool const unauthArrPresent = ctx.
tx.
isFieldPresent(sfUnauthorizeCredentials);
30 int const authCredPresent =
31 static_cast<int>(authArrPresent) +
static_cast<int>(unauthArrPresent);
33 auto const optAuth = ctx.
tx[~sfAuthorize];
34 auto const optUnauth = ctx.
tx[~sfUnauthorize];
35 int const authPresent =
36 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.";
68 authArrPresent ? sfAuthorizeCredentials : sfUnauthorizeCredentials),
106 for (
auto const& o : authCred)
108 auto const& issuer = o[sfIssuer];
111 auto [it, ins] = sorted.
emplace(issuer, o[sfCredentialType]);
159 slePreauth->setAccountID(sfAccount,
account_);
160 slePreauth->setAccountID(sfAuthorize, auth);
166 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory "
167 <<
to_string(preauthKeylet.
key) <<
": " << (page ?
"success" :
"failure");
172 slePreauth->setFieldU64(sfOwnerNode, *page);
203 auto const sortedTX =
205 STArray sortedLE(sfAuthorizeCredentials, sortedTX.size());
206 for (
auto const& p : sortedTX)
209 cred.setAccountID(sfIssuer, p.first);
210 cred.setFieldVL(sfCredentialType, p.second);
219 slePreauth->setAccountID(sfAccount,
account_);
220 slePreauth->peekFieldArray(sfAuthorizeCredentials) = std::move(sortedLE);
227 JLOG(
j_.
trace()) <<
"Adding DepositPreauth to owner directory " <<
to_string(preauthKey.
key)
228 <<
": " << (page ?
"success" :
"failure");
233 slePreauth->setFieldU64(sfOwnerNode, *page);
255 JLOG(j.
warn()) <<
"Selected DepositPreauth does not exist.";
259 AccountID const account{(*slePreauth)[sfAccount]};
264 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)
Returns a function that sets the owner on a directory SLE.
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.