20#include <xrpld/app/tx/detail/Credentials.h>
22#include <xrpl/basics/Log.h>
23#include <xrpl/ledger/ApplyView.h>
24#include <xrpl/ledger/CredentialHelpers.h>
25#include <xrpl/ledger/View.h>
26#include <xrpl/protocol/Feature.h>
27#include <xrpl/protocol/Indexes.h>
28#include <xrpl/protocol/TxFlags.h>
47using namespace credentials;
61 auto const& tx = ctx.
tx;
66 JLOG(j.trace()) <<
"Malformed transaction: Invalid Subject";
70 auto const uri = tx[~sfURI];
73 JLOG(j.trace()) <<
"Malformed transaction: invalid size of URI.";
77 auto const credType = tx[sfCredentialType];
81 <<
"Malformed transaction: invalid size of CredentialType.";
91 auto const credType(ctx.
tx[sfCredentialType]);
92 auto const subject = ctx.
tx[sfSubject];
96 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
103 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
113 auto const subject =
ctx_.
tx[sfSubject];
114 auto const credType(
ctx_.
tx[sfCredentialType]);
115 Keylet const credentialKey =
122 auto const optExp =
ctx_.
tx[~sfExpiration];
128 if (closeTime > *optExp)
130 JLOG(
j_.
trace()) <<
"Malformed transaction: "
131 "Expiration time is in the past.";
144 sleIssuer->getFieldU32(sfOwnerCount) + 1)};
149 sleCred->setAccountID(sfSubject, subject);
150 sleCred->setAccountID(sfIssuer,
account_);
151 sleCred->setFieldVL(sfCredentialType, credType);
161 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
163 << (page ?
"success" :
"failure");
166 sleCred->setFieldU64(sfIssuerNode, *page);
181 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
183 << (page ?
"success" :
"failure");
186 sleCred->setFieldU64(sfSubjectNode, *page);
207 auto const subject = ctx.
tx[~sfSubject];
208 auto const issuer = ctx.
tx[~sfIssuer];
210 if (!subject && !issuer)
213 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: "
214 "No Subject or Issuer fields.";
219 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
221 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Subject or Issuer "
226 auto const credType = ctx.
tx[sfCredentialType];
230 <<
"Malformed transaction: invalid size of CredentialType.";
241 auto const subject = ctx.
tx[~sfSubject].value_or(account);
242 auto const issuer = ctx.
tx[~sfIssuer].value_or(account);
243 auto const credType(ctx.
tx[sfCredentialType]);
257 auto const credType(
ctx_.
tx[sfCredentialType]);
266 JLOG(
j_.
trace()) <<
"Can't delete non-expired credential.";
285 if (!ctx.
tx[sfIssuer])
287 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Issuer field zeroed.";
291 auto const credType = ctx.
tx[sfCredentialType];
295 <<
"Malformed transaction: invalid size of CredentialType.";
307 auto const credType(ctx.
tx[sfCredentialType]);
319 JLOG(ctx.
j.
warn()) <<
"No credential: " <<
to_string(subject) <<
", "
320 <<
to_string(issuer) <<
", " << credType;
326 JLOG(ctx.
j.
warn()) <<
"Credential already accepted: "
344 if (!sleSubject || !sleIssuer)
349 sleSubject->getFieldU32(sfOwnerCount) + 1)};
354 auto const credType(
ctx_.
tx[sfCredentialType]);
356 auto const sleCred =
view().
peek(credentialKey);
360 JLOG(
j_.
trace()) <<
"Credential is expired: " << sleCred->getText();
Stream trace() const
Severity stream access functions.
virtual void update(std::shared_ptr< SLE > const &sle)=0
Indicate changes to 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 NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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.
virtual LedgerInfo const & info() const =0
Returns information about the ledger.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Blob getFieldVL(SField const &field) const
std::uint32_t getFieldU32(SField const &field) const
bool isFieldPresent(SField const &field) const
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
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.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
std::size_t constexpr maxCredentialURILength
The maximum length of a URI inside a Credential.
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 maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
@ tecINSUFFICIENT_RESERVE
bool isTesSuccess(TER x) noexcept
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfUniversalMask
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.
T time_since_epoch(T... args)