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];
61 JLOG(j.trace()) <<
"Malformed transaction: invalid size of CredentialType.";
71 auto const credType(ctx.
tx[sfCredentialType]);
72 auto const subject = ctx.
tx[sfSubject];
76 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
82 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
92 auto const subject =
ctx_.
tx[sfSubject];
93 auto const credType(
ctx_.
tx[sfCredentialType]);
100 auto const optExp =
ctx_.
tx[~sfExpiration];
105 if (closeTime > *optExp)
107 JLOG(
j_.
trace()) <<
"Malformed transaction: "
108 "Expiration time is in the past.";
125 sleCred->setAccountID(sfSubject, subject);
126 sleCred->setAccountID(sfIssuer,
account_);
127 sleCred->setFieldVL(sfCredentialType, credType);
134 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory " <<
to_string(credentialKey.
key) <<
": "
135 << (page ?
"success" :
"failure");
138 sleCred->setFieldU64(sfIssuerNode, *page);
150 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory " <<
to_string(credentialKey.
key) <<
": "
151 << (page ?
"success" :
"failure");
154 sleCred->setFieldU64(sfSubjectNode, *page);
175 auto const subject = ctx.
tx[~sfSubject];
176 auto const issuer = ctx.
tx[~sfIssuer];
178 if (!subject && !issuer)
181 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: "
182 "No Subject or Issuer fields.";
187 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
189 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Subject or Issuer "
194 auto const credType = ctx.
tx[sfCredentialType];
197 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: invalid size of CredentialType.";
208 auto const subject = ctx.
tx[~sfSubject].value_or(account);
209 auto const issuer = ctx.
tx[~sfIssuer].value_or(account);
210 auto const credType(ctx.
tx[sfCredentialType]);
224 auto const credType(
ctx_.
tx[sfCredentialType]);
231 JLOG(
j_.
trace()) <<
"Can't delete non-expired credential.";
250 if (!ctx.
tx[sfIssuer])
252 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: Issuer field zeroed.";
256 auto const credType = ctx.
tx[sfCredentialType];
259 JLOG(ctx.
j.
trace()) <<
"Malformed transaction: invalid size of CredentialType.";
271 auto const credType(ctx.
tx[sfCredentialType]);
282 JLOG(ctx.
j.
warn()) <<
"No credential: " <<
to_string(subject) <<
", " <<
to_string(issuer) <<
", " << credType;
288 JLOG(ctx.
j.
warn()) <<
"Credential already accepted: " <<
to_string(subject) <<
", " <<
to_string(issuer) <<
", "
305 if (!sleSubject || !sleIssuer)
314 auto const credType(
ctx_.
tx[sfCredentialType]);
316 auto const sleCred =
view().
peek(credentialKey);
320 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 TER preclaim(PreclaimContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext 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)
static TER preclaim(PreclaimContext const &ctx)
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
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 LedgerHeader const & header() const =0
Returns information about the ledger.
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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
bool checkExpired(std::shared_ptr< SLE const > const &sleCredential, NetClock::time_point const &closed)
TER deleteSLE(ApplyView &view, std::shared_ptr< SLE > const &sleCredential, beast::Journal j)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Keylet account(AccountID const &id) noexcept
AccountID root.
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
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::string to_string(base_uint< Bits, Tag > const &a)
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)
bool isTesSuccess(TER x) noexcept
@ tecINSUFFICIENT_RESERVE
constexpr std::uint32_t tfUniversalMask
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
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)