1#include <xrpl/basics/Log.h>
2#include <xrpl/ledger/ApplyView.h>
3#include <xrpl/ledger/helpers/AccountRootHelpers.h>
4#include <xrpl/ledger/helpers/CredentialHelpers.h>
5#include <xrpl/ledger/helpers/DirectoryHelpers.h>
6#include <xrpl/protocol/Feature.h>
7#include <xrpl/protocol/Indexes.h>
8#include <xrpl/protocol/TxFlags.h>
9#include <xrpl/tx/transactors/credentials/CredentialCreate.h>
28using namespace credentials;
40 auto const& tx = ctx.
tx;
45 JLOG(j.trace()) <<
"Malformed transaction: Invalid Subject";
49 auto const uri = tx[~sfURI];
52 JLOG(j.trace()) <<
"Malformed transaction: invalid size of URI.";
56 auto const credType = tx[sfCredentialType];
59 JLOG(j.trace()) <<
"Malformed transaction: invalid size of CredentialType.";
69 auto const credType(ctx.
tx[sfCredentialType]);
70 auto const subject = ctx.
tx[sfSubject];
74 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
80 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
90 auto const subject =
ctx_.
tx[sfSubject];
91 auto const credType(
ctx_.
tx[sfCredentialType]);
98 auto const optExp =
ctx_.
tx[~sfExpiration];
104 if (closeTime > *optExp)
106 JLOG(
j_.
trace()) <<
"Malformed transaction: "
107 "Expiration time is in the past.";
111 sleCred->setFieldU32(sfExpiration, *optExp);
125 sleCred->setAccountID(sfSubject, subject);
126 sleCred->setAccountID(sfIssuer,
account_);
127 sleCred->setFieldVL(sfCredentialType, credType);
135 JLOG(
j_.
trace()) <<
"Adding Credential to owner directory " <<
to_string(credentialKey.
key)
136 <<
": " << (page ?
"success" :
"failure");
139 sleCred->setFieldU64(sfIssuerNode, *page);
146 sleCred->setFieldU32(sfFlags, lsfAccepted);
154 JLOG(
j_.
trace()) <<
"Adding Credential to subject directory "
155 <<
to_string(credentialKey.
key) <<
": " << (page ?
"success" :
"failure");
158 sleCred->setFieldU64(sfSubjectNode, *page);
Stream trace() const
Severity stream access functions.
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 std::uint32_t getFlagsMask(PreflightContext const &ctx)
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
Blob getFieldVL(SField const &field) const
bool isFieldPresent(SField const &field) const
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)
Returns a function that sets the owner on a directory SLE.
@ tecINSUFFICIENT_RESERVE
constexpr FlagValue 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)