rippled
Loading...
Searching...
No Matches
PermissionedDomainSet.cpp
1#include <xrpl/tx/transactors/permissioned_domain/PermissionedDomainSet.h>
2//
3#include <xrpl/ledger/View.h>
4#include <xrpl/ledger/helpers/AccountRootHelpers.h>
5#include <xrpl/ledger/helpers/CredentialHelpers.h>
6#include <xrpl/ledger/helpers/DirectoryHelpers.h>
7#include <xrpl/protocol/STObject.h>
8#include <xrpl/protocol/TxFlags.h>
9
10namespace xrpl {
11
12bool
14{
15 return ctx.rules.enabled(featureCredentials);
16}
17
20{
21 if (auto err = credentials::checkArray(
22 ctx.tx.getFieldArray(sfAcceptedCredentials),
24 ctx.j);
25 !isTesSuccess(err))
26 return err;
27
28 auto const domain = ctx.tx.at(~sfDomainID);
29 if (domain && *domain == beast::zero)
30 return temMALFORMED;
31
32 return tesSUCCESS;
33}
34
35TER
37{
38 auto const account = ctx.tx.getAccountID(sfAccount);
39
40 if (!ctx.view.exists(keylet::account(account)))
41 return tefINTERNAL; // LCOV_EXCL_LINE
42
43 auto const& credentials = ctx.tx.getFieldArray(sfAcceptedCredentials);
44 for (auto const& credential : credentials)
45 {
46 if (!ctx.view.exists(keylet::account(credential.getAccountID(sfIssuer))))
47 return tecNO_ISSUER;
48 }
49
50 if (ctx.tx.isFieldPresent(sfDomainID))
51 {
52 auto const sleDomain =
54 if (!sleDomain)
55 return tecNO_ENTRY;
56 if (sleDomain->getAccountID(sfOwner) != account)
57 return tecNO_PERMISSION;
58 }
59
60 return tesSUCCESS;
61}
62
64TER
66{
67 auto const ownerSle = view().peek(keylet::account(account_));
68 if (!ownerSle)
69 return tefINTERNAL; // LCOV_EXCL_LINE
70
71 auto const sortedTxCredentials =
72 credentials::makeSorted(ctx_.tx.getFieldArray(sfAcceptedCredentials));
73 STArray sortedLE(sfAcceptedCredentials, sortedTxCredentials.size());
74 for (auto const& p : sortedTxCredentials)
75 {
76 auto cred = STObject::makeInnerObject(sfCredential);
77 cred.setAccountID(sfIssuer, p.first);
78 cred.setFieldVL(sfCredentialType, p.second);
79 sortedLE.push_back(std::move(cred));
80 }
81
82 if (ctx_.tx.isFieldPresent(sfDomainID))
83 {
84 // Modify existing permissioned domain.
85 auto slePd = view().peek(keylet::permissionedDomain(ctx_.tx.getFieldH256(sfDomainID)));
86 if (!slePd)
87 return tefINTERNAL; // LCOV_EXCL_LINE
88 slePd->peekFieldArray(sfAcceptedCredentials) = std::move(sortedLE);
89 view().update(slePd);
90 }
91 else
92 {
93 // Create new permissioned domain.
94 // Check reserve availability for new object creation
95 auto const balance = STAmount((*ownerSle)[sfBalance]).xrp();
96 auto const reserve = ctx_.view().fees().accountReserve((*ownerSle)[sfOwnerCount] + 1);
97 if (balance < reserve)
99
100 Keylet const pdKeylet =
102 auto slePd = std::make_shared<SLE>(pdKeylet);
103
104 slePd->setAccountID(sfOwner, account_);
105 slePd->setFieldU32(sfSequence, ctx_.tx.getFieldU32(sfSequence));
106 slePd->peekFieldArray(sfAcceptedCredentials) = std::move(sortedLE);
107 auto const page =
109 if (!page)
110 return tecDIR_FULL; // LCOV_EXCL_LINE
111
112 slePd->setFieldU64(sfOwnerNode, *page);
113 // If we succeeded, the new entry counts against the creator's reserve.
114 adjustOwnerCount(view(), ownerSle, 1, ctx_.journal);
115 view().insert(slePd);
116 }
117
118 return tesSUCCESS;
119}
120
121} // namespace xrpl
STTx const & tx
beast::Journal const journal
ApplyView & view()
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.
Definition ApplyView.h:289
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
TER doApply() override
Attempt to create the Permissioned Domain.
static bool checkExtraFeatures(PreflightContext const &ctx)
static TER preclaim(PreclaimContext 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 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.
Definition Rules.cpp:120
XRPAmount xrp() const
Definition STAmount.cpp:261
void push_back(STObject const &object)
Definition STArray.h:189
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1055
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:593
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:680
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:456
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:623
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:73
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:635
AccountID const account_
Definition Transactor.h:116
ApplyView & view()
Definition Transactor.h:132
ApplyContext & ctx_
Definition Transactor.h:112
T is_same_v
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:336
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Definition Indexes.cpp:522
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
@ tefINTERNAL
Definition TER.h:153
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.
std::size_t constexpr maxPermissionedDomainCredentialsArraySize
The maximum number of credentials can be passed in array for permissioned domain.
Definition Protocol.h:228
@ temMALFORMED
Definition TER.h:67
bool isTesSuccess(TER x) noexcept
Definition TER.h:651
@ tecDIR_FULL
Definition TER.h:268
@ tecNO_ENTRY
Definition TER.h:287
@ tecINSUFFICIENT_RESERVE
Definition TER.h:288
@ tecNO_PERMISSION
Definition TER.h:286
@ tecNO_ISSUER
Definition TER.h:280
@ tesSUCCESS
Definition TER.h:225
XRPAmount accountReserve(std::size_t ownerCount) const
Returns the account reserve given the owner count, in drops.
A pair of SHAMap key and LedgerEntryType.
Definition Keylet.h:19
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