rippled
Loading...
Searching...
No Matches
PermissionedDEXHelpers.cpp
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2025 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#include <xrpld/app/misc/CredentialHelpers.h>
21#include <xrpld/app/misc/PermissionedDEXHelpers.h>
22
23namespace ripple {
24namespace permissioned_dex {
25
26bool
28 ReadView const& view,
29 AccountID const& account,
30 Domain const& domainID)
31{
32 auto const sleDomain = view.read(keylet::permissionedDomain(domainID));
33 if (!sleDomain)
34 return false;
35
36 // domain owner is in the domain
37 if (sleDomain->getAccountID(sfOwner) == account)
38 return true;
39
40 auto const& credentials = sleDomain->getFieldArray(sfAcceptedCredentials);
41
42 bool const inDomain = std::any_of(
43 credentials.begin(), credentials.end(), [&](auto const& credential) {
44 auto const sleCred = view.read(keylet::credential(
45 account, credential[sfIssuer], credential[sfCredentialType]));
46 if (!sleCred || !sleCred->isFlag(lsfAccepted))
47 return false;
48
49 return !credentials::checkExpired(
50 sleCred, view.info().parentCloseTime);
51 });
52
53 return inDomain;
54}
55
56bool
58 ReadView const& view,
59 uint256 const& offerID,
60 Domain const& domainID,
62{
63 auto const sleOffer = view.read(keylet::offer(offerID));
64
65 // The following are defensive checks that should never happen, since this
66 // function is used to check against the order book offers, which should not
67 // have any of the following wrong behavior
68 if (!sleOffer)
69 return false; // LCOV_EXCL_LINE
70 if (!sleOffer->isFieldPresent(sfDomainID))
71 return false; // LCOV_EXCL_LINE
72 if (sleOffer->getFieldH256(sfDomainID) != domainID)
73 return false; // LCOV_EXCL_LINE
74
75 if (sleOffer->isFlag(lsfHybrid) &&
76 !sleOffer->isFieldPresent(sfAdditionalBooks))
77 {
78 JLOG(j.error()) << "Hybrid offer " << offerID
79 << " missing AdditionalBooks field";
80 return false; // LCOV_EXCL_LINE
81 }
82
83 return accountInDomain(view, sleOffer->getAccountID(sfAccount), domainID);
84}
85
86} // namespace permissioned_dex
87
88} // namespace ripple
T any_of(T... args)
A generic endpoint for log messages.
Definition: Journal.h:60
Stream error() const
Definition: Journal.h:346
A view into a ledger.
Definition: ReadView.h:52
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:570
Keylet offer(AccountID const &id, std::uint32_t seq) noexcept
An offer from an account.
Definition: Indexes.cpp:274
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:25
@ credential
Credentials signature.