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/PermissionedDEXHelpers.h>
21
22#include <xrpl/ledger/CredentialHelpers.h>
23
24namespace ripple {
25namespace permissioned_dex {
26
27bool
29 ReadView const& view,
30 AccountID const& account,
31 Domain const& domainID)
32{
33 auto const sleDomain = view.read(keylet::permissionedDomain(domainID));
34 if (!sleDomain)
35 return false;
36
37 // domain owner is in the domain
38 if (sleDomain->getAccountID(sfOwner) == account)
39 return true;
40
41 auto const& credentials = sleDomain->getFieldArray(sfAcceptedCredentials);
42
43 bool const inDomain = std::any_of(
44 credentials.begin(), credentials.end(), [&](auto const& credential) {
45 auto const sleCred = view.read(keylet::credential(
46 account, credential[sfIssuer], credential[sfCredentialType]));
47 if (!sleCred || !sleCred->isFlag(lsfAccepted))
48 return false;
49
50 return !credentials::checkExpired(
51 sleCred, view.info().parentCloseTime);
52 });
53
54 return inDomain;
55}
56
57bool
59 ReadView const& view,
60 uint256 const& offerID,
61 Domain const& domainID,
63{
64 auto const sleOffer = view.read(keylet::offer(offerID));
65
66 // The following are defensive checks that should never happen, since this
67 // function is used to check against the order book offers, which should not
68 // have any of the following wrong behavior
69 if (!sleOffer)
70 return false; // LCOV_EXCL_LINE
71 if (!sleOffer->isFieldPresent(sfDomainID))
72 return false; // LCOV_EXCL_LINE
73 if (sleOffer->getFieldH256(sfDomainID) != domainID)
74 return false; // LCOV_EXCL_LINE
75
76 if (sleOffer->isFlag(lsfHybrid) &&
77 !sleOffer->isFieldPresent(sfAdditionalBooks))
78 {
79 JLOG(j.error()) << "Hybrid offer " << offerID
80 << " missing AdditionalBooks field";
81 return false; // LCOV_EXCL_LINE
82 }
83
84 return accountInDomain(view, sleOffer->getAccountID(sfAccount), domainID);
85}
86
87} // namespace permissioned_dex
88
89} // 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:51
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.