xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
libxrpl
ledger
helpers
PermissionedDEXHelpers.cpp
1
#include <xrpl/ledger/helpers/PermissionedDEXHelpers.h>
2
3
#include <xrpl/basics/Log.h>
4
#include <xrpl/basics/base_uint.h>
5
#include <xrpl/beast/utility/Journal.h>
6
#include <xrpl/beast/utility/Zero.h>
7
#include <xrpl/beast/utility/instrumentation.h>
8
#include <xrpl/ledger/ReadView.h>
9
#include <xrpl/ledger/helpers/CredentialHelpers.h>
10
#include <xrpl/protocol/AccountID.h>
11
#include <xrpl/protocol/Feature.h>
12
#include <xrpl/protocol/Indexes.h>
13
#include <xrpl/protocol/LedgerFormats.h>
14
#include <xrpl/protocol/SField.h>
15
#include <xrpl/protocol/UintTypes.h>
16
17
#include <
algorithm
>
18
19
namespace
xrpl::permissioned_dex
{
20
21
bool
22
accountInDomain
(
ReadView
const
& view,
AccountID
const
& account,
Domain
const
& domainID)
23
{
24
// Avoid constructing a zero-key PermissionedDomain keylet.
25
// keylet::permissionedDomain(UInt256) uses the DomainID as the ledger key.
26
if
(view.
rules
().
enabled
(fixCleanup3_2_0) && domainID ==
beast::kZero
)
27
{
28
// LCOV_EXCL_START
29
UNREACHABLE(
"xrpl::permissioned_dex::accountInDomain : domainID is zero"
);
30
return
false
;
31
// LCOV_EXCL_STOP
32
}
33
34
auto
const
sleDomain = view.
read
(
keylet::permissionedDomain
(domainID));
35
if
(!sleDomain)
36
return
false
;
37
38
// domain owner is in the domain
39
if
(sleDomain->getAccountID(sfOwner) == account)
40
return
true
;
41
42
auto
const
&
credentials
= sleDomain->getFieldArray(sfAcceptedCredentials);
43
44
bool
const
inDomain =
std::ranges::any_of
(
credentials
, [&](
auto
const
& credential) {
45
auto
const
sleCred = view.
read
(
46
keylet::credential
(account, credential[sfIssuer], credential[sfCredentialType]));
47
if
(!sleCred || !sleCred->isFlag(lsfAccepted))
48
return
false
;
49
50
return
!
credentials::checkExpired
(*sleCred, view.
header
().
parentCloseTime
);
51
});
52
53
return
inDomain;
54
}
55
56
bool
57
offerInDomain
(
58
ReadView
const
& view,
59
UInt256
const
& offerID,
60
Domain
const
& domainID,
61
beast::Journal
j)
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
(view.
rules
().
enabled
(fixCleanup3_1_3))
76
{
77
// post-fixCleanup3_1_3: a valid hybrid offer must have
78
// sfAdditionalBooks present with exactly 1 entry
79
if
(sleOffer->isFlag(lsfHybrid) &&
80
(!sleOffer->isFieldPresent(sfAdditionalBooks) ||
81
sleOffer->getFieldArray(sfAdditionalBooks).size() != 1))
82
{
83
JLOG(j.
error
()) <<
"Hybrid offer "
<< offerID
84
<<
" missing or malformed AdditionalBooks field"
;
85
return
false
;
// LCOV_EXCL_LINE
86
}
87
}
88
else
89
{
90
// pre-fixCleanup3_1_3: a valid hybrid offer must have
91
// sfAdditionalBooks present (size is not checked)
92
if
(sleOffer->isFlag(lsfHybrid) && !sleOffer->isFieldPresent(sfAdditionalBooks))
93
{
94
JLOG(j.
error
()) <<
"Hybrid offer "
<< offerID <<
" missing AdditionalBooks field"
;
95
return
false
;
// LCOV_EXCL_LINE
96
}
97
}
98
99
return
accountInDomain
(view, sleOffer->getAccountID(sfAccount), domainID);
100
}
101
102
}
// namespace xrpl::permissioned_dex
algorithm
std::ranges::any_of
T any_of(T... args)
beast::Journal
A generic endpoint for log messages.
Definition
Journal.h:44
beast::Journal::error
Stream error() const
Definition
Journal.h:362
xrpl::ReadView
A view into a ledger.
Definition
ReadView.h:41
xrpl::ReadView::rules
virtual Rules const & rules() const =0
Returns the tx processing rules.
xrpl::ReadView::read
virtual SLE::const_pointer read(Keylet const &k) const =0
Return the state item associated with a key.
xrpl::ReadView::header
virtual LedgerHeader const & header() const =0
Returns information about the ledger.
xrpl::Rules::enabled
bool enabled(UInt256 const &feature) const
Returns true if a feature is enabled.
Definition
Rules.cpp:182
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl::credentials
Definition
CredentialHelpers.h:22
xrpl::credentials::checkExpired
bool checkExpired(SLE const &sleCredential, NetClock::time_point const &closed)
Definition
CredentialHelpers.cpp:38
xrpl::keylet::offer
Keylet offer(AccountID const &id, SeqProxy const &seq) noexcept
An offer from an account.
Definition
Indexes.cpp:298
xrpl::keylet::permissionedDomain
Keylet permissionedDomain(AccountID const &account, SeqProxy const &seq) noexcept
Definition
Indexes.cpp:609
xrpl::keylet::credential
Keylet credential(AccountID const &subject, AccountID const &issuer, Slice const &credType) noexcept
Definition
Indexes.cpp:585
xrpl::permissioned_dex
Definition
PermissionedDEXHelpers.h:9
xrpl::permissioned_dex::accountInDomain
bool accountInDomain(ReadView const &view, AccountID const &account, Domain const &domainID)
Definition
PermissionedDEXHelpers.cpp:22
xrpl::permissioned_dex::offerInDomain
bool offerInDomain(ReadView const &view, UInt256 const &offerID, Domain const &domainID, beast::Journal j)
Definition
PermissionedDEXHelpers.cpp:57
xrpl::Domain
BaseUInt< 256 > Domain
Domain is a 256-bit hash representing a specific domain.
Definition
UintTypes.h:59
xrpl::UInt256
BaseUInt< 256 > UInt256
Definition
base_uint.h:580
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
xrpl::LedgerHeader::parentCloseTime
NetClock::time_point parentCloseTime
Definition
LedgerHeader.h:27
Generated by
1.17.0