1#include <xrpl/tx/transactors/credentials/CredentialCreate.h>
3#include <xrpl/basics/Log.h>
4#include <xrpl/basics/base_uint.h>
5#include <xrpl/core/ServiceRegistry.h>
6#include <xrpl/ledger/ApplyView.h>
7#include <xrpl/ledger/helpers/AccountRootHelpers.h>
8#include <xrpl/ledger/helpers/CredentialHelpers.h>
9#include <xrpl/ledger/helpers/DirectoryHelpers.h>
10#include <xrpl/protocol/Feature.h>
11#include <xrpl/protocol/Indexes.h>
12#include <xrpl/protocol/Keylet.h>
13#include <xrpl/protocol/LedgerFormats.h>
14#include <xrpl/protocol/Protocol.h>
15#include <xrpl/protocol/SField.h>
16#include <xrpl/protocol/STAmount.h>
17#include <xrpl/protocol/STLedgerEntry.h>
18#include <xrpl/protocol/STTx.h>
19#include <xrpl/protocol/TER.h>
20#include <xrpl/protocol/TxFlags.h>
21#include <xrpl/protocol/XRPAmount.h>
22#include <xrpl/tx/Transactor.h>
55 auto const& tx = ctx.
tx;
60 JLOG(j.trace()) <<
"Malformed transaction: Invalid Subject";
64 auto const uri = tx[~sfURI];
67 JLOG(j.trace()) <<
"Malformed transaction: invalid size of URI.";
71 auto const credType = tx[sfCredentialType];
74 JLOG(j.trace()) <<
"Malformed transaction: invalid size of CredentialType.";
84 auto const credType(ctx.
tx[sfCredentialType]);
85 auto const subject = ctx.
tx[sfSubject];
89 JLOG(ctx.
j.
trace()) <<
"Subject doesn't exist.";
95 JLOG(ctx.
j.
trace()) <<
"Credential already exists.";
105 auto const subject =
ctx_.tx[sfSubject];
106 auto const credType(
ctx_.tx[sfCredentialType]);
113 auto const optExp =
ctx_.tx[~sfExpiration];
117 ctx_.view().header().parentCloseTime.time_since_epoch().count();
119 if (closeTime > *optExp)
121 JLOG(
j_.trace()) <<
"Malformed transaction: "
122 "Expiration time is in the past.";
126 sleCred->setFieldU32(sfExpiration, *optExp);
140 sleCred->setAccountID(sfSubject, subject);
142 sleCred->setFieldVL(sfCredentialType, credType);
144 if (
ctx_.tx.isFieldPresent(sfURI))
145 sleCred->setFieldVL(sfURI,
ctx_.tx.getFieldVL(sfURI));
150 JLOG(
j_.trace()) <<
"Adding Credential to owner directory " <<
to_string(credentialKey.
key)
151 <<
": " << (page ?
"success" :
"failure");
154 sleCred->setFieldU64(sfIssuerNode, *page);
161 sleCred->setFieldU32(sfFlags, lsfAccepted);
169 JLOG(
j_.trace()) <<
"Adding Credential to subject directory "
170 <<
to_string(credentialKey.
key) <<
": " << (page ?
"success" :
"failure");
173 sleCred->setFieldU64(sfSubjectNode, *page);
A generic endpoint for log messages.
Stream trace() const
Severity stream access functions.
virtual SLE::pointer peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
virtual void insert(SLE::ref sle)=0
Insert a new state SLE.
std::optional< std::uint64_t > dirInsert(Keylet const &directory, uint256 const &key, std::function< void(SLE::ref)> const &describe)
Insert an entry to a directory.
static std::uint32_t getFlagsMask(PreflightContext const &ctx)
void visitInvariantEntry(bool isDelete, SLE::const_ref before, SLE::const_ref after) override
Inspect a single ledger entry modified by this transaction.
bool finalizeInvariants(STTx const &tx, TER result, XRPAmount fee, ReadView const &view, beast::Journal const &j) override
Check transaction-specific post-conditions after all entries have been visited.
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.
bool enabled(uint256 const &feature) const
Returns true if a feature is enabled.
std::shared_ptr< STLedgerEntry const > const & const_ref
AccountID const accountID_
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.
constexpr std::size_t kMaxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
std::string to_string(BaseUInt< Bits, Tag > const &a)
TERSubset< CanCvtToNotTEC > NotTEC
void adjustOwnerCount(ApplyView &view, SLE::ref 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.
constexpr std::size_t kMaxCredentialUriLength
The maximum length of a URI inside a Credential.
TERSubset< CanCvtToTER > TER
@ tecINSUFFICIENT_RESERVE
constexpr FlagValue 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.