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