xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
PathSet.h
1
#pragma once
2
3
#include <test/jtx/Account.h>
4
#include <test/jtx/Env.h>
5
6
#include <xrpl/beast/utility/Zero.h>
7
#include <xrpl/core/ServiceRegistry.h>
8
#include <xrpl/json/json_value.h>
9
#include <xrpl/ledger/helpers/DirectoryHelpers.h>
10
#include <xrpl/protocol/Asset.h>
11
#include <xrpl/protocol/Issue.h>
12
#include <xrpl/protocol/LedgerFormats.h>
13
#include <xrpl/protocol/MPTIssue.h>
14
#include <xrpl/protocol/SField.h>
15
#include <xrpl/protocol/STPathSet.h>
16
17
#include <
cstddef
>
18
19
namespace
xrpl::test
{
20
24
inline
std::size_t
25
countOffers
(
26
jtx::Env
const
& env,
27
jtx::Account
const
& account,
28
Asset
const
& takerPays,
29
Asset
const
& takerGets)
30
{
31
size_t
count = 0;
32
forEachItem
(*env.
current
(), account, [&](
SLE::ConstRef
sle) {
33
if (sle->getType() == ltOFFER && sle->getFieldAmount(sfTakerPays).asset() == takerPays &&
34
sle->getFieldAmount(sfTakerGets).asset() == takerGets)
35
++count;
36
});
37
return
count;
38
}
39
40
inline
std::size_t
41
countOffers
(
42
jtx::Env
const
& env,
43
jtx::Account
const
& account,
44
STAmount
const
& takerPays,
45
STAmount
const
& takerGets)
46
{
47
size_t
count = 0;
48
forEachItem
(*env.
current
(), account, [&](
SLE::ConstRef
sle) {
49
if (sle->getType() == ltOFFER && sle->getFieldAmount(sfTakerPays) == takerPays &&
50
sle->getFieldAmount(sfTakerGets) == takerGets)
51
++count;
52
});
53
return
count;
54
}
55
59
inline
bool
60
isOffer
(
61
jtx::Env
const
& env,
62
jtx::Account
const
& account,
63
STAmount
const
& takerPays,
64
STAmount
const
& takerGets)
65
{
66
return
countOffers
(env, account, takerPays, takerGets) > 0;
67
}
68
72
inline
bool
73
isOffer
(
74
jtx::Env
const
& env,
75
jtx::Account
const
& account,
76
Asset
const
& takerPays,
77
Asset
const
& takerGets)
78
{
79
return
countOffers
(env, account, takerPays, takerGets) > 0;
80
}
81
82
class
TestPath
83
{
84
public
:
85
STPath
path
;
86
87
TestPath
() =
default
;
88
TestPath
(
TestPath
const
&) =
default
;
89
TestPath
&
90
operator=
(
TestPath
const
&) =
default
;
91
TestPath
(
TestPath
&&) =
default
;
92
TestPath
&
93
operator=
(
TestPath
&&) =
default
;
94
95
template
<
class
First,
class
... Rest>
96
explicit
TestPath
(First&& first, Rest&&... rest)
97
{
98
addHelper
(
std::forward<First>
(first),
std::forward<Rest>
(rest)...);
99
}
100
TestPath
&
101
pushBack
(
Issue
const
& iss);
102
TestPath
&
103
pushBack
(
MPTIssue
const
& iss);
104
TestPath
&
105
pushBack
(
jtx::Account
const
& acc);
106
TestPath
&
107
pushBack
(
STPathElement
const
& pe);
108
[[nodiscard]]
json::Value
109
json
()
const
;
110
111
private
:
112
template
<
class
First,
class
... Rest>
113
void
114
addHelper
(First&& first, Rest&&... rest);
115
};
116
117
inline
TestPath&
118
TestPath::pushBack
(
STPathElement
const
& pe)
119
{
120
path
.emplaceBack(pe);
121
return
*
this
;
122
}
123
124
inline
TestPath
&
125
TestPath::pushBack
(
Issue
const
& iss)
126
{
127
path
.emplaceBack(
128
STPathElement::TypeCurrency
|
STPathElement::TypeIssuer
,
129
beast::kZero
,
130
iss.
currency
,
131
iss.
account
);
132
return
*
this
;
133
}
134
135
inline
TestPath
&
136
TestPath::pushBack
(
MPTIssue
const
& iss)
137
{
138
path
.emplaceBack(
139
STPathElement::TypeMpt
|
STPathElement::TypeIssuer
,
140
beast::kZero
,
141
iss.
getMptID
(),
142
iss.
getIssuer
());
143
return
*
this
;
144
}
145
146
inline
TestPath
&
147
TestPath::pushBack
(
jtx::Account
const
& account)
148
{
149
path
.emplaceBack(account.id(),
Currency
{beast::kZero},
beast::kZero
);
150
return
*
this
;
151
}
152
153
template
<
class
First,
class
... Rest>
154
void
155
TestPath::addHelper
(First&& first, Rest&&... rest)
156
{
157
pushBack
(
std::forward<First>
(first));
158
if
constexpr
(
sizeof
...(rest) > 0)
159
addHelper
(
std::forward<Rest>
(rest)...);
160
}
161
162
inline
json::Value
163
TestPath::json
()
const
164
{
165
return
path
.getJson(
JsonOptions::Values::None
);
166
}
167
168
class
PathSet
169
{
170
public
:
171
STPathSet
paths
;
172
173
PathSet
() =
default
;
174
PathSet
(
PathSet
const
&) =
default
;
175
PathSet
&
176
operator=
(
PathSet
const
&) =
default
;
177
PathSet
(
PathSet
&&) =
default
;
178
PathSet
&
179
operator=
(
PathSet
&&) =
default
;
180
181
template
<
class
First,
class
... Rest>
182
explicit
PathSet
(First&& first, Rest&&... rest)
183
{
184
addHelper
(
std::forward<First>
(first),
std::forward<Rest>
(rest)...);
185
}
186
[[nodiscard]]
json::Value
187
json
()
const
188
{
189
json::Value
v;
190
v[
"Paths"
] =
paths
.getJson(
JsonOptions::Values::None
);
191
return
v;
192
}
193
194
private
:
195
template
<
class
First,
class
... Rest>
196
void
197
addHelper
(First first, Rest... rest)
198
{
199
paths
.emplaceBack(std::move(first.path));
200
if
constexpr
(
sizeof
...(rest) > 0)
201
addHelper
(std::move(rest)...);
202
}
203
};
204
205
}
// namespace xrpl::test
json::Value
Represents a JSON value.
Definition
json_value.h:121
xrpl::Asset
Definition
Asset.h:52
xrpl::Issue
A currency issued by an account.
Definition
Issue.h:18
xrpl::Issue::currency
Currency currency
Definition
Issue.h:20
xrpl::Issue::account
AccountID account
Definition
Issue.h:21
xrpl::MPTIssue
Definition
MPTIssue.h:23
xrpl::MPTIssue::getMptID
constexpr MPTID const & getMptID() const
Definition
MPTIssue.h:43
xrpl::MPTIssue::getIssuer
AccountID const & getIssuer() const
Definition
MPTIssue.cpp:29
xrpl::STAmount
Definition
STAmount.h:46
xrpl::STLedgerEntry::ConstRef
std::shared_ptr< STLedgerEntry const > const & ConstRef
Definition
STLedgerEntry.h:37
xrpl::STPathElement
Definition
STPathSet.h:24
xrpl::STPathElement::TypeIssuer
@ TypeIssuer
Definition
STPathSet.h:40
xrpl::STPathElement::TypeCurrency
@ TypeCurrency
Definition
STPathSet.h:39
xrpl::STPathElement::TypeMpt
@ TypeMpt
Definition
STPathSet.h:41
xrpl::STPathSet
Definition
STPathSet.h:200
xrpl::STPath
Definition
STPathSet.h:134
xrpl::test::PathSet::addHelper
void addHelper(First first, Rest... rest)
Definition
PathSet.h:197
xrpl::test::PathSet::paths
STPathSet paths
Definition
PathSet.h:171
xrpl::test::PathSet::PathSet
PathSet(First &&first, Rest &&... rest)
Definition
PathSet.h:182
xrpl::test::PathSet::PathSet
PathSet(PathSet const &)=default
xrpl::test::PathSet::operator=
PathSet & operator=(PathSet &&)=default
xrpl::test::PathSet::PathSet
PathSet()=default
xrpl::test::PathSet::PathSet
PathSet(PathSet &&)=default
xrpl::test::PathSet::json
json::Value json() const
Definition
PathSet.h:187
xrpl::test::PathSet::operator=
PathSet & operator=(PathSet const &)=default
xrpl::test::TestPath
Definition
PathSet.h:83
xrpl::test::TestPath::TestPath
TestPath(TestPath const &)=default
xrpl::test::TestPath::TestPath
TestPath(TestPath &&)=default
xrpl::test::TestPath::addHelper
void addHelper(First &&first, Rest &&... rest)
Definition
PathSet.h:155
xrpl::test::TestPath::TestPath
TestPath()=default
xrpl::test::TestPath::TestPath
TestPath(First &&first, Rest &&... rest)
Definition
PathSet.h:96
xrpl::test::TestPath::operator=
TestPath & operator=(TestPath &&)=default
xrpl::test::TestPath::operator=
TestPath & operator=(TestPath const &)=default
xrpl::test::TestPath::path
STPath path
Definition
PathSet.h:85
xrpl::test::TestPath::json
json::Value json() const
Definition
PathSet.h:163
xrpl::test::TestPath::pushBack
TestPath & pushBack(Issue const &iss)
Definition
PathSet.h:125
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
xrpl::test::jtx::Env::current
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition
Env.h:377
cstddef
std::forward
T forward(T... args)
beast::kZero
constexpr Zero kZero
Definition
Zero.h:30
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::test::isOffer
bool isOffer(jtx::Env const &env, jtx::Account const &account, STAmount const &takerPays, STAmount const &takerGets)
An offer exists.
Definition
PathSet.h:60
xrpl::test::countOffers
std::size_t countOffers(jtx::Env const &env, jtx::Account const &account, Asset const &takerPays, Asset const &takerGets)
Count offer.
Definition
PathSet.h:25
xrpl::forEachItem
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(SLE::ConstRef)> const &f)
Iterate all items in the given directory.
Definition
DirectoryHelpers.cpp:63
xrpl::Currency
BaseUInt< 160, detail::CurrencyTag > Currency
Currency is a hash representing a specific currency.
Definition
UintTypes.h:42
std::size_t
xrpl::JsonOptions::Values::None
@ None
Definition
STBase.h:27
Generated by
1.17.0