20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/app/tx/detail/Credentials.h>
22#include <xrpld/ledger/ApplyView.h>
23#include <xrpld/ledger/View.h>
24#include <xrpl/basics/Log.h>
25#include <xrpl/protocol/Feature.h>
26#include <xrpl/protocol/Indexes.h>
27#include <xrpl/protocol/TxFlags.h>
46using namespace credentials;
55 JLOG(ctx.
j.
trace()) <<
"featureCredentials is disabled.";
62 auto const& tx = ctx.
tx;
68 JLOG(ctx.
j.
debug()) <<
"CredentialCreate: invalid flags.";
74 JLOG(j.trace()) <<
"Malformed transaction: Invalid Subject";
78 auto const uri = tx[~sfURI];
81 JLOG(j.trace()) <<
"Malformed transaction: invalid size of URI.";
85 auto const credType = tx[sfCredentialType];
89 <<
"Malformed transaction: invalid size of CredentialType.";
99 auto const credType(ctx.
tx[sfCredentialType]);
100 auto const subject = ctx.
tx[sfSubject];
104 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
111 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
121 auto const subject =
ctx_.
tx[sfSubject];
122 auto const credType(
ctx_.
tx[sfCredentialType]);
123 Keylet const credentialKey =
126 auto const sleCred = std::make_shared<SLE>(credentialKey);
130 auto const optExp =
ctx_.
tx[~sfExpiration];
136 if (closeTime > *optExp)
138 JLOG(
j_.
trace()) <<
"Malformed transaction: "
139 "Expiration time is in the past.";
152 sleIssuer->getFieldU32(sfOwnerCount) + 1)};
157 sleCred->setAccountID(sfSubject, subject);
158 sleCred->setAccountID(sfIssuer,
account_);
159 sleCred->setFieldVL(sfCredentialType, credType);
169 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
171 << (page ?
"success" :
"failure");
174 sleCred->setFieldU64(sfIssuerNode, *page);
189 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
191 << (page ?
"success" :
"failure");
194 sleCred->setFieldU64(sfSubjectNode, *page);
209 JLOG(ctx.
j.
trace()) <<
"featureCredentials is disabled.";
219 JLOG(ctx.
j.
debug()) <<
"CredentialDelete: invalid flags.";
223 auto const subject = ctx.
tx[~sfSubject];
224 auto const issuer = ctx.
tx[~sfIssuer];
226 if (!subject && !issuer)
229 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: "
230 "No Subject or Issuer fields.";
235 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
237 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Subject or Issuer "
242 auto const credType = ctx.
tx[sfCredentialType];
246 <<
"Malformed transaction: invalid size of CredentialType.";
257 auto const subject = ctx.
tx[~sfSubject].value_or(account);
258 auto const issuer = ctx.
tx[~sfIssuer].value_or(account);
259 auto const credType(ctx.
tx[sfCredentialType]);
273 auto const credType(
ctx_.
tx[sfCredentialType]);
282 JLOG(
j_.
trace()) <<
"Can't delete non-expired credential.";
296 JLOG(ctx.
j.
trace()) <<
"featureCredentials is disabled.";
306 JLOG(ctx.
j.
debug()) <<
"CredentialAccept: invalid flags.";
310 if (!ctx.
tx[sfIssuer])
312 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Issuer field zeroed.";
316 auto const credType = ctx.
tx[sfCredentialType];
320 <<
"Malformed transaction: invalid size of CredentialType.";
332 auto const credType(ctx.
tx[sfCredentialType]);
344 JLOG(ctx.
j.
warn()) <<
"No credential: " <<
to_string(subject) <<
", "
345 <<
to_string(issuer) <<
", " << credType;
351 JLOG(ctx.
j.
warn()) <<
"Credential already accepted: "
369 if (!sleSubject || !sleIssuer)
374 sleSubject->getFieldU32(sfOwnerCount) + 1)};
379 auto const credType(
ctx_.
tx[sfCredentialType]);
381 auto const sleCred =
view().
peek(credentialKey);
385 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 TER preclaim(PreclaimContext const &ctx)
static NotTEC preflight(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
std::uint32_t getFlags() 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.
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
static bool adjustOwnerCount(ApplyContext &ctx, int count)
NotTEC preflight2(PreflightContext const &ctx)
Checks whether the signature appears valid.
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
@ tecINSUFFICIENT_RESERVE
std::string to_string(base_uint< Bits, Tag > const &a)
constexpr std::uint32_t tfUniversalMask
TERSubset< CanCvtToNotTEC > NotTEC
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)