1#include <xrpld/app/tx/detail/Credentials.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/CredentialHelpers.h>
6#include <xrpl/ledger/View.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/TxFlags.h>
28using namespace credentials;
42 auto const& tx = ctx.
tx;
47 JLOG(j.trace()) <<
"Malformed transaction: Invalid Subject";
51 auto const uri = tx[~sfURI];
54 JLOG(j.trace()) <<
"Malformed transaction: invalid size of URI.";
58 auto const credType = tx[sfCredentialType];
62 <<
"Malformed transaction: invalid size of CredentialType.";
72 auto const credType(ctx.
tx[sfCredentialType]);
73 auto const subject = ctx.
tx[sfSubject];
77 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
84 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
94 auto const subject =
ctx_.
tx[sfSubject];
95 auto const credType(
ctx_.
tx[sfCredentialType]);
96 Keylet const credentialKey =
103 auto const optExp =
ctx_.
tx[~sfExpiration];
109 if (closeTime > *optExp)
111 JLOG(
j_.
trace()) <<
"Malformed transaction: "
112 "Expiration time is in the past.";
125 sleIssuer->getFieldU32(sfOwnerCount) + 1)};
130 sleCred->setAccountID(sfSubject, subject);
131 sleCred->setAccountID(sfIssuer,
account_);
132 sleCred->setFieldVL(sfCredentialType, credType);
142 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
144 << (page ?
"success" :
"failure");
147 sleCred->setFieldU64(sfIssuerNode, *page);
162 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory "
164 << (page ?
"success" :
"failure");
167 sleCred->setFieldU64(sfSubjectNode, *page);
188 auto const subject = ctx.
tx[~sfSubject];
189 auto const issuer = ctx.
tx[~sfIssuer];
191 if (!subject && !issuer)
194 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: "
195 "No Subject or Issuer fields.";
200 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
202 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Subject or Issuer "
207 auto const credType = ctx.
tx[sfCredentialType];
211 <<
"Malformed transaction: invalid size of CredentialType.";
222 auto const subject = ctx.
tx[~sfSubject].value_or(account);
223 auto const issuer = ctx.
tx[~sfIssuer].value_or(account);
224 auto const credType(ctx.
tx[sfCredentialType]);
238 auto const credType(
ctx_.
tx[sfCredentialType]);
247 JLOG(
j_.
trace()) <<
"Can't delete non-expired credential.";
266 if (!ctx.
tx[sfIssuer])
268 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Issuer field zeroed.";
272 auto const credType = ctx.
tx[sfCredentialType];
276 <<
"Malformed transaction: invalid size of CredentialType.";
288 auto const credType(ctx.
tx[sfCredentialType]);
300 JLOG(ctx.
j.
warn()) <<
"No credential: " <<
to_string(subject) <<
", "
301 <<
to_string(issuer) <<
", " << credType;
307 JLOG(ctx.
j.
warn()) <<
"Credential already accepted: "
325 if (!sleSubject || !sleIssuer)
330 sleSubject->getFieldU32(sfOwnerCount) + 1)};
335 auto const credType(
ctx_.
tx[sfCredentialType]);
337 auto const sleCred =
view().
peek(credentialKey);
341 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)