rippled
Loading...
Searching...
No Matches
PermissionedDomainSet.cpp
1#include <xrpld/app/tx/detail/PermissionedDomainSet.h>
2
3#include <xrpl/ledger/CredentialHelpers.h>
4#include <xrpl/ledger/View.h>
5#include <xrpl/protocol/STObject.h>
6#include <xrpl/protocol/TxFlags.h>
7
8#include <optional>
9
10namespace ripple {
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(
47 keylet::account(credential.getAccountID(sfIssuer))))
48 return tecNO_ISSUER;
49 }
50
51 if (ctx.tx.isFieldPresent(sfDomainID))
52 {
53 auto const sleDomain = ctx.view.read(
55 if (!sleDomain)
56 return tecNO_ENTRY;
57 if (sleDomain->getAccountID(sfOwner) != account)
58 return tecNO_PERMISSION;
59 }
60
61 return tesSUCCESS;
62}
63
65TER
67{
68 auto const ownerSle = view().peek(keylet::account(account_));
69 if (!ownerSle)
70 return tefINTERNAL; // LCOV_EXCL_LINE
71
72 auto const sortedTxCredentials =
73 credentials::makeSorted(ctx_.tx.getFieldArray(sfAcceptedCredentials));
74 STArray sortedLE(sfAcceptedCredentials, sortedTxCredentials.size());
75 for (auto const& p : sortedTxCredentials)
76 {
77 auto cred = STObject::makeInnerObject(sfCredential);
78 cred.setAccountID(sfIssuer, p.first);
79 cred.setFieldVL(sfCredentialType, p.second);
80 sortedLE.push_back(std::move(cred));
81 }
82
83 if (ctx_.tx.isFieldPresent(sfDomainID))
84 {
85 // Modify existing permissioned domain.
86 auto slePd = view().peek(
88 if (!slePd)
89 return tefINTERNAL; // LCOV_EXCL_LINE
90 slePd->peekFieldArray(sfAcceptedCredentials) = std::move(sortedLE);
91 view().update(slePd);
92 }
93 else
94 {
95 // Create new permissioned domain.
96 // Check reserve availability for new object creation
97 auto const balance = STAmount((*ownerSle)[sfBalance]).xrp();
98 auto const reserve =
99 ctx_.view().fees().accountReserve((*ownerSle)[sfOwnerCount] + 1);
100 if (balance < reserve)
102
103 Keylet const pdKeylet = keylet::permissionedDomain(
104 account_, ctx_.tx.getFieldU32(sfSequence));
105 auto slePd = std::make_shared<SLE>(pdKeylet);
106 if (!slePd)
107 return tefINTERNAL; // LCOV_EXCL_LINE
108
109 slePd->setAccountID(sfOwner, account_);
110 slePd->setFieldU32(sfSequence, ctx_.tx.getFieldU32(sfSequence));
111 slePd->peekFieldArray(sfAcceptedCredentials) = std::move(sortedLE);
112 auto const page = view().dirInsert(
114 if (!page)
115 return tecDIR_FULL; // LCOV_EXCL_LINE
116
117 slePd->setFieldU64(sfOwnerNode, *page);
118 // If we succeeded, the new entry counts against the creator's reserve.
119 adjustOwnerCount(view(), ownerSle, 1, ctx_.journal);
120 view().insert(slePd);
121 }
122
123 return tesSUCCESS;
124}
125
126} // namespace ripple
ApplyView & view()
beast::Journal const journal
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:300
virtual std::shared_ptr< SLE > peek(Keylet const &k)=0
Prepare to modify the SLE associated with key.
static NotTEC preflight(PreflightContext const &ctx)
static TER preclaim(PreclaimContext const &ctx)
TER doApply() override
Attempt to create the Permissioned Domain.
static bool checkExtraFeatures(PreflightContext const &ctx)
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
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.
Definition Rules.cpp:111
XRPAmount xrp() const
Definition STAmount.cpp:264
void push_back(STObject const &object)
Definition STArray.h:193
AccountID getAccountID(SField const &field) const
Definition STObject.cpp:638
STArray const & getFieldArray(SField const &field) const
Definition STObject.cpp:683
T::value_type at(TypedField< T > const &f) const
Get the value of a field.
Definition STObject.h:1028
std::uint32_t getFieldU32(SField const &field) const
Definition STObject.cpp:596
bool isFieldPresent(SField const &field) const
Definition STObject.cpp:465
static STObject makeInnerObject(SField const &name)
Definition STObject.cpp:76
uint256 getFieldH256(SField const &field) const
Definition STObject.cpp:626
AccountID const account_
Definition Transactor.h:128
ApplyView & view()
Definition Transactor.h:144
ApplyContext & ctx_
Definition Transactor.h:124
T is_same_v
NotTEC checkArray(STArray const &credentials, unsigned maxSize, beast::Journal j)
std::set< std::pair< AccountID, Slice > > makeSorted(STArray const &credentials)
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Definition Indexes.cpp:551
Keylet account(AccountID const &id) noexcept
AccountID root.
Definition Indexes.cpp:165
Keylet ownerDir(AccountID const &id) noexcept
The root page of an account's directory.
Definition Indexes.cpp:355
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
std::size_t constexpr maxPermissionedDomainCredentialsArraySize
The maximum number of credentials can be passed in array for permissioned domain.
Definition Protocol.h:94
void adjustOwnerCount(ApplyView &view, std::shared_ptr< SLE > const &sle, std::int32_t amount, beast::Journal j)
Adjust the owner count up or down.
Definition View.cpp:1013
std::function< void(SLE::ref)> describeOwnerDir(AccountID const &account)
Definition View.cpp:1031
@ tefINTERNAL
Definition TER.h:154
@ tecNO_ENTRY
Definition TER.h:288
@ tecNO_ISSUER
Definition TER.h:281
@ tecDIR_FULL
Definition TER.h:269
@ tecNO_PERMISSION
Definition TER.h:287
@ tecINSUFFICIENT_RESERVE
Definition TER.h:289
@ tesSUCCESS
Definition TER.h:226
bool isTesSuccess(TER x) noexcept
Definition TER.h:659
@ credential
Credentials signature.
@ temMALFORMED
Definition TER.h:68
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:20
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:16
beast::Journal const j
Definition Transactor.h:23