rippled
Loading...
Searching...
No Matches
PermissionedDEXHelpers.cpp
1#include <xrpl/ledger/helpers/CredentialHelpers.h>
2#include <xrpl/tx/transactors/dex/PermissionedDEXHelpers.h>
3
4namespace xrpl {
5namespace permissioned_dex {
6
7bool
8accountInDomain(ReadView const& view, AccountID const& account, Domain const& domainID)
9{
10 auto const sleDomain = view.read(keylet::permissionedDomain(domainID));
11 if (!sleDomain)
12 return false;
13
14 // domain owner is in the domain
15 if (sleDomain->getAccountID(sfOwner) == account)
16 return true;
17
18 auto const& credentials = sleDomain->getFieldArray(sfAcceptedCredentials);
19
20 bool const inDomain =
21 std::any_of(credentials.begin(), credentials.end(), [&](auto const& credential) {
22 auto const sleCred = view.read(
23 keylet::credential(account, credential[sfIssuer], credential[sfCredentialType]));
24 if (!sleCred || !sleCred->isFlag(lsfAccepted))
25 return false;
26
27 return !credentials::checkExpired(sleCred, view.header().parentCloseTime);
28 });
29
30 return inDomain;
31}
32
33bool
35 ReadView const& view,
36 uint256 const& offerID,
37 Domain const& domainID,
39{
40 auto const sleOffer = view.read(keylet::offer(offerID));
41
42 // The following are defensive checks that should never happen, since this
43 // function is used to check against the order book offers, which should not
44 // have any of the following wrong behavior
45 if (!sleOffer)
46 return false; // LCOV_EXCL_LINE
47 if (!sleOffer->isFieldPresent(sfDomainID))
48 return false; // LCOV_EXCL_LINE
49 if (sleOffer->getFieldH256(sfDomainID) != domainID)
50 return false; // LCOV_EXCL_LINE
51
52 if (sleOffer->isFlag(lsfHybrid) && !sleOffer->isFieldPresent(sfAdditionalBooks))
53 {
54 JLOG(j.error()) << "Hybrid offer " << offerID << " missing AdditionalBooks field";
55 return false; // LCOV_EXCL_LINE
56 }
57
58 return accountInDomain(view, sleOffer->getAccountID(sfAccount), domainID);
59}
60
61} // namespace permissioned_dex
62
63} // namespace xrpl
T any_of(T... args)
A generic endpoint for log messages.
Definition Journal.h:40
Stream error() const
Definition Journal.h:319
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:243
Keylet permissionedDomain(AccountID const &account, std::uint32_t seq) noexcept
Definition Indexes.cpp:522
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