xrpld
Loading...
Searching...
No Matches
CredentialDelete.cpp
1#include <xrpl/tx/transactors/credentials/CredentialDelete.h>
2
3#include <xrpl/basics/Log.h>
4#include <xrpl/ledger/ApplyView.h>
5#include <xrpl/ledger/helpers/CredentialHelpers.h>
6#include <xrpl/protocol/AccountID.h>
7#include <xrpl/protocol/Feature.h>
8#include <xrpl/protocol/Indexes.h>
9#include <xrpl/protocol/Protocol.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/STLedgerEntry.h>
12#include <xrpl/protocol/STTx.h>
13#include <xrpl/protocol/TER.h>
14#include <xrpl/protocol/TxFlags.h>
15#include <xrpl/protocol/XRPAmount.h>
16#include <xrpl/tx/Transactor.h>
17
18#include <cstdint>
19namespace xrpl {
20
21using namespace credentials;
22
23std::uint32_t
25{
26 // 0 means "Allow any flags"
27 return ctx.rules.enabled(fixInvalidTxFlags) ? tfUniversalMask : 0;
28}
29
32{
33 auto const subject = ctx.tx[~sfSubject];
34 auto const issuer = ctx.tx[~sfIssuer];
35
36 if (!subject && !issuer)
37 {
38 // Neither field is present, the transaction is malformed.
39 JLOG(ctx.j.trace()) << "Malformed transaction: "
40 "No Subject or Issuer fields.";
41 return temMALFORMED;
42 }
43
44 // Make sure that the passed account is valid.
45 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
46 {
47 JLOG(ctx.j.trace()) << "Malformed transaction: Subject or Issuer "
48 "field zeroed.";
50 }
51
52 auto const credType = ctx.tx[sfCredentialType];
53 if (credType.empty() || (credType.size() > kMaxCredentialTypeLength))
54 {
55 JLOG(ctx.j.trace()) << "Malformed transaction: invalid size of CredentialType.";
56 return temMALFORMED;
57 }
58
59 return tesSUCCESS;
60}
61
62TER
64{
65 AccountID const account{ctx.tx[sfAccount]};
66 auto const subject = ctx.tx[~sfSubject].value_or(account);
67 auto const issuer = ctx.tx[~sfIssuer].value_or(account);
68 auto const credType(ctx.tx[sfCredentialType]);
69
70 if (!ctx.view.exists(keylet::credential(subject, issuer, credType)))
71 return tecNO_ENTRY;
72
73 return tesSUCCESS;
74}
75
76TER
78{
79 auto const subject = ctx_.tx[~sfSubject].value_or(accountID_);
80 auto const issuer = ctx_.tx[~sfIssuer].value_or(accountID_);
81
82 auto const credType(ctx_.tx[sfCredentialType]);
83 auto const sleCred = view().peek(keylet::credential(subject, issuer, credType));
84 if (!sleCred)
85 return tefINTERNAL; // LCOV_EXCL_LINE
86
87 if ((subject != accountID_) && (issuer != accountID_) &&
88 !checkExpired(*sleCred, ctx_.view().header().parentCloseTime))
89 {
90 JLOG(j_.trace()) << "Can't delete non-expired credential.";
91 return tecNO_PERMISSION;
92 }
93
94 return deleteSLE(view(), sleCred, j_);
95}
96
97void
99{
100 // No transaction-specific invariants yet (future work).
101}
102
103bool
105 STTx const&,
106 TER,
107 XRPAmount,
108 ReadView const&,
109 beast::Journal const&)
110{
111 // No transaction-specific invariants yet (future work).
112 return true;
113}
114} // namespace xrpl
A generic endpoint for log messages.
Definition Journal.h:38
Stream trace() const
Severity stream access functions.
Definition Journal.h:291
virtual SLE::pointer 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)
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.
A view into a ledger.
Definition ReadView.h:31
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.
Definition Rules.cpp:171
std::shared_ptr< STLedgerEntry const > const & const_ref
beast::Journal const j_
Definition Transactor.h:118
ApplyView & view()
Definition Transactor.h:136
AccountID const accountID_
Definition Transactor.h:120
ApplyContext & ctx_
Definition Transactor.h:116
TER deleteSLE(ApplyView &view, SLE::ref sleCredential, beast::Journal j)
bool checkExpired(SLE const &sleCredential, NetClock::time_point const &closed)
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:545
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
constexpr std::size_t kMaxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
Definition Protocol.h:225
@ tefINTERNAL
Definition TER.h:163
TERSubset< CanCvtToNotTEC > NotTEC
Definition TER.h:594
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28
@ temMALFORMED
Definition TER.h:73
@ temINVALID_ACCOUNT_ID
Definition TER.h:105
TERSubset< CanCvtToTER > TER
Definition TER.h:634
@ tecNO_ENTRY
Definition TER.h:304
@ tecNO_PERMISSION
Definition TER.h:303
constexpr FlagValue tfUniversalMask
Definition TxFlags.h:45
@ tesSUCCESS
Definition TER.h:240
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:61
ReadView const & view
Definition Transactor.h:64
State information when preflighting a tx.
Definition Transactor.h:18
beast::Journal const j
Definition Transactor.h:25