rippled
Loading...
Searching...
No Matches
PermissionedDEXHelpers.cpp
1#include <xrpld/app/misc/PermissionedDEXHelpers.h>
2
3#include <xrpl/ledger/CredentialHelpers.h>
4
5namespace xrpl {
6namespace permissioned_dex {
7
8bool
9accountInDomain(ReadView const& view, AccountID const& account, Domain const& domainID)
10{
11 auto const sleDomain = view.read(keylet::permissionedDomain(domainID));
12 if (!sleDomain)
13 return false;
14
15 // domain owner is in the domain
16 if (sleDomain->getAccountID(sfOwner) == account)
17 return true;
18
19 auto const& credentials = sleDomain->getFieldArray(sfAcceptedCredentials);
20
21 bool const inDomain = std::any_of(credentials.begin(), credentials.end(), [&](auto const& credential) {
22 auto const sleCred = view.read(keylet::credential(account, credential[sfIssuer], credential[sfCredentialType]));
23 if (!sleCred || !sleCred->isFlag(lsfAccepted))
24 return false;
25
26 return !credentials::checkExpired(sleCred, view.header().parentCloseTime);
27 });
28
29 return inDomain;
30}
31
32bool
33offerInDomain(ReadView const& view, uint256 const& offerID, Domain const& domainID, beast::Journal j)
34{
35 auto const sleOffer = view.read(keylet::offer(offerID));
36
37 // The following are defensive checks that should never happen, since this
38 // function is used to check against the order book offers, which should not
39 // have any of the following wrong behavior
40 if (!sleOffer)
41 return false; // LCOV_EXCL_LINE
42 if (!sleOffer->isFieldPresent(sfDomainID))
43 return false; // LCOV_EXCL_LINE
44 if (sleOffer->getFieldH256(sfDomainID) != domainID)
45 return false; // LCOV_EXCL_LINE
46
47 if (sleOffer->isFlag(lsfHybrid) && !sleOffer->isFieldPresent(sfAdditionalBooks))
48 {
49 JLOG(j.error()) << "Hybrid offer " << offerID << " missing AdditionalBooks field";
50 return false; // LCOV_EXCL_LINE
51 }
52
53 return accountInDomain(view, sleOffer->getAccountID(sfAccount), domainID);
54}
55
56} // namespace permissioned_dex
57
58} // namespace xrpl
T any_of(T... args)
A generic endpoint for log messages.
Definition Journal.h:40
Stream error() const
Definition Journal.h:318
A view into a ledger.
Definition ReadView.h:31
virtual std::shared_ptr< SLE const > read(Keylet const &k) const =0
Return the state item associated with a key.
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition Indexes.cpp:235
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Definition Indexes.cpp:510
bool offerInDomain(ReadView const &view, uint256 const &offerID, Domain const &domainID, beast::Journal j)
bool accountInDomain(ReadView const &view, AccountID const &account, Domain const &domainID)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5