20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/ledger/View.h>
22#include <xrpl/protocol/digest.h>
27namespace credentials {
34 std::uint32_t const exp = (*sleCredential)[~sfExpiration].value_or(
44 bool foundExpired =
false;
47 for (
auto const& h : arr)
51 auto const sleCred = view.
peek(k);
56 <<
"Credentials are expired. Cred: " << sleCred->getText();
76 [&view, &sleCredential, j](
81 JLOG(j.
fatal()) <<
"Internal error: can't retrieve Owner account.";
90 JLOG(j.
fatal()) <<
"Unable to delete Credential from owner.";
100 auto const issuer = sleCredential->getAccountID(sfIssuer);
101 auto const subject = sleCredential->getAccountID(sfSubject);
104 auto err = delSLE(issuer, sfIssuerNode, !
accepted || (subject == issuer));
108 if (subject != issuer)
110 err = delSLE(subject, sfSubjectNode,
accepted);
116 view.
erase(sleCredential);
131 <<
"Malformed transaction: Credentials array size is invalid: "
132 << credentials.size();
137 for (
auto const& cred : credentials)
139 auto [it, ins] = duplicates.
insert(cred);
143 <<
"Malformed transaction: duplicates in credentials.";
158 for (
auto const& h : credIDs)
163 JLOG(ctx.
j.
trace()) <<
"Credential doesn't exist. Cred: " << h;
167 if (sleCred->getAccountID(sfSubject) != src)
170 <<
"Credential doesn't belong to the source account. Cred: "
177 JLOG(ctx.
j.
trace()) <<
"Credential isn't accepted. Cred: " << h;
193 lifeExtender.
reserve(credIDs.size());
194 for (
auto const& h : credIDs)
201 sorted.
emplace((*sleCred)[sfIssuer], (*sleCred)[sfCredentialType]);
204 lifeExtender.
push_back(std::move(sleCred));
209 JLOG(ctx.
journal.
trace()) <<
"DepositPreauth doesn't exist";
220 for (
auto const& cred : credentials)
222 auto [it, ins] =
out.emplace(cred[sfIssuer], cred[sfCredentialType]);
232 if (credentials.
empty() || (credentials.
size() > maxSize))
234 JLOG(j.
trace()) <<
"Malformed transaction: "
235 "Invalid credentials size: "
236 << credentials.
size();
246 JLOG(j.
trace()) <<
"Malformed transaction: "
247 "Issuer account is invalid: "
255 JLOG(j.
trace()) <<
"Malformed transaction: "
256 "Invalid credentialType size: "
264 JLOG(j.
trace()) <<
"Malformed transaction: "
265 "duplicates in credenentials.";
290 if (credentialsPresent &&
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
State information when applying a tx.
beast::Journal const journal
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 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.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
virtual bool exists(Keylet const &k) const =0
Determine if a state item exists.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
const STVector256 & getFieldV256(SField const &field) const
bool isFieldPresent(SField const &field) const
NotTEC checkFields(PreflightContext const &ctx)
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
bool removeExpired(ApplyView &view, STTx const &tx, beast::Journal const j)
TER authorized(ApplyContext const &ctx, AccountID const &dst)
TER valid(PreclaimContext const &ctx, AccountID const &src)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
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.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
std::size_t constexpr maxCredentialsArraySize
The maximum number of credentials can be passed in array.
@ accepted
Manifest is valid.
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
TER verifyDepositPreauth(ApplyContext &ctx, AccountID const &src, AccountID const &dst, std::shared_ptr< SLE > const &sleDst)
std::string to_string(base_uint< Bits, Tag > const &a)
@ credential
Credentials signature.
TERSubset< CanCvtToTER > TER
sha512_half_hasher::result_type sha512Half(Args const &... args)
Returns the SHA512-Half of a series of objects.
State information when determining if a tx is likely to claim a fee.
State information when preflighting a tx.
T time_since_epoch(T... args)