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;
56 JLOG(ctx.
j.
trace()) <<
"featureCredentials is disabled.";
63 auto const& tx = ctx.
tx;
69 JLOG(ctx.
j.
debug()) <<
"CredentialCreate: invalid flags.";
75 JLOG(j.trace()) <<
"Malformed transaction: Invalid Subject";
79 auto const uri = tx[~sfURI];
82 JLOG(j.trace()) <<
"Malformed transaction: invalid size of URI.";
86 auto const credType = tx[sfCredentialType];
90 <<
"Malformed transaction: invalid size of CredentialType.";
100 auto const credType(ctx.
tx[sfCredentialType]);
101 auto const subject = ctx.
tx[sfSubject];
105 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
112 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
122 auto const subject =
ctx_.
tx[sfSubject];
123 auto const credType(
ctx_.
tx[sfCredentialType]);
124 Keylet const credentialKey =
131 auto const optExp =
ctx_.
tx[~sfExpiration];
137 if (closeTime > *optExp)
139 JLOG(
j_.
trace()) <<
"Malformed transaction: "
140 "Expiration time is in the past.";
153 sleIssuer->getFieldU32(sfOwnerCount) + 1)};
158 sleCred->setAccountID(sfSubject, subject);
159 sleCred->setAccountID(sfIssuer,
account_);
160 sleCred->setFieldVL(sfCredentialType, credType);
170 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
172 << (page ?
"success" :
"failure");
175 sleCred->setFieldU64(sfIssuerNode, *page);
190 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
192 << (page ?
"success" :
"failure");
195 sleCred->setFieldU64(sfSubjectNode, *page);
210 JLOG(ctx.
j.
trace()) <<
"featureCredentials is disabled.";
220 JLOG(ctx.
j.
debug()) <<
"CredentialDelete: invalid flags.";
224 auto const subject = ctx.
tx[~sfSubject];
225 auto const issuer = ctx.
tx[~sfIssuer];
227 if (!subject && !issuer)
230 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: "
231 "No Subject or Issuer fields.";
236 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
238 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Subject or Issuer "
243 auto const credType = ctx.
tx[sfCredentialType];
247 <<
"Malformed transaction: invalid size of CredentialType.";
258 auto const subject = ctx.
tx[~sfSubject].value_or(account);
259 auto const issuer = ctx.
tx[~sfIssuer].value_or(account);
260 auto const credType(ctx.
tx[sfCredentialType]);
274 auto const credType(
ctx_.
tx[sfCredentialType]);
283 JLOG(
j_.
trace()) <<
"Can't delete non-expired credential.";
297 JLOG(ctx.
j.
trace()) <<
"featureCredentials is disabled.";
307 JLOG(ctx.
j.
debug()) <<
"CredentialAccept: invalid flags.";
311 if (!ctx.
tx[sfIssuer])
313 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Issuer field zeroed.";
317 auto const credType = ctx.
tx[sfCredentialType];
321 <<
"Malformed transaction: invalid size of CredentialType.";
333 auto const credType(ctx.
tx[sfCredentialType]);
345 JLOG(ctx.
j.
warn()) <<
"No credential: " <<
to_string(subject) <<
", "
346 <<
to_string(issuer) <<
", " << credType;
352 JLOG(ctx.
j.
warn()) <<
"Credential already accepted: "
370 if (!sleSubject || !sleIssuer)
375 sleSubject->getFieldU32(sfOwnerCount) + 1)};
380 auto const credType(
ctx_.
tx[sfCredentialType]);
382 auto const sleCred =
view().
peek(credentialKey);
386 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.
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)
NotTEC preflight1(PreflightContext const &ctx)
Performs early sanity checks on the account and fee fields.
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
bool isTesSuccess(TER x) noexcept
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)