rippled
Loading...
Searching...
No Matches
CredentialDelete.cpp
1#include <xrpl/basics/Log.h>
2#include <xrpl/ledger/ApplyView.h>
3#include <xrpl/ledger/View.h>
4#include <xrpl/ledger/helpers/CredentialHelpers.h>
5#include <xrpl/protocol/Feature.h>
6#include <xrpl/protocol/Indexes.h>
7#include <xrpl/protocol/TxFlags.h>
8#include <xrpl/tx/transactors/credentials/CredentialDelete.h>
9
10#include <chrono>
11
12namespace xrpl {
13
14using namespace credentials;
15
18{
19 // 0 means "Allow any flags"
20 return ctx.rules.enabled(fixInvalidTxFlags) ? tfUniversalMask : 0;
21}
22
25{
26 auto const subject = ctx.tx[~sfSubject];
27 auto const issuer = ctx.tx[~sfIssuer];
28
29 if (!subject && !issuer)
30 {
31 // Neither field is present, the transaction is malformed.
32 JLOG(ctx.j.trace()) << "Malformed transaction: "
33 "No Subject or Issuer fields.";
34 return temMALFORMED;
35 }
36
37 // Make sure that the passed account is valid.
38 if ((subject && subject->isZero()) || (issuer && issuer->isZero()))
39 {
40 JLOG(ctx.j.trace()) << "Malformed transaction: Subject or Issuer "
41 "field zeroed.";
43 }
44
45 auto const credType = ctx.tx[sfCredentialType];
46 if (credType.empty() || (credType.size() > maxCredentialTypeLength))
47 {
48 JLOG(ctx.j.trace()) << "Malformed transaction: invalid size of CredentialType.";
49 return temMALFORMED;
50 }
51
52 return tesSUCCESS;
53}
54
55TER
57{
58 AccountID const account{ctx.tx[sfAccount]};
59 auto const subject = ctx.tx[~sfSubject].value_or(account);
60 auto const issuer = ctx.tx[~sfIssuer].value_or(account);
61 auto const credType(ctx.tx[sfCredentialType]);
62
63 if (!ctx.view.exists(keylet::credential(subject, issuer, credType)))
64 return tecNO_ENTRY;
65
66 return tesSUCCESS;
67}
68
69TER
71{
72 auto const subject = ctx_.tx[~sfSubject].value_or(account_);
73 auto const issuer = ctx_.tx[~sfIssuer].value_or(account_);
74
75 auto const credType(ctx_.tx[sfCredentialType]);
76 auto const sleCred = view().peek(keylet::credential(subject, issuer, credType));
77 if (!sleCred)
78 return tefINTERNAL; // LCOV_EXCL_LINE
79
80 if ((subject != account_) && (issuer != account_) &&
82 {
83 JLOG(j_.trace()) << "Can't delete non-expired credential.";
84 return tecNO_PERMISSION;
85 }
86
87 return deleteSLE(view(), sleCred, j_);
88}
89
90} // namespace xrpl
Stream trace() const
Severity stream access functions.
Definition Journal.h:295
STTx const & tx
ApplyView & view()
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)
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.
Definition Rules.cpp:120
AccountID const account_
Definition Transactor.h:116
beast::Journal const j_
Definition Transactor.h:114
ApplyView & view()
Definition Transactor.h:132
ApplyContext & ctx_
Definition Transactor.h:112
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 credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition Indexes.cpp:498
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefINTERNAL
Definition TER.h:153
@ temMALFORMED
Definition TER.h:67
@ temINVALID_ACCOUNT_ID
Definition TER.h:99
@ tecNO_ENTRY
Definition TER.h:287
@ tecNO_PERMISSION
Definition TER.h:286
constexpr FlagValue tfUniversalMask
Definition TxFlags.h:43
@ tesSUCCESS
Definition TER.h:225
std::size_t constexpr maxCredentialTypeLength
The maximum length of a CredentialType inside a Credential.
Definition Protocol.h:221
NetClock::time_point parentCloseTime
State information when determining if a tx is likely to claim a fee.
Definition Transactor.h:57
ReadView const & view
Definition Transactor.h:60
State information when preflighting a tx.
Definition Transactor.h:14
beast::Journal const j
Definition Transactor.h:21