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
& 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
& 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
& 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
(
jtx::Env
& env,
jtx::Account
const
& account,
Asset
const
& takerPays,
Asset
const
& takerGets)
74
{
75
return
countOffers
(env, account, takerPays, takerGets) > 0;
76
}
77
78
class
TestPath
79
{
80
public
:
81
STPath
path
;
82
83
TestPath
() =
default
;
84
TestPath
(
TestPath
const
&) =
default
;
85
TestPath
&
86
operator=
(
TestPath
const
&) =
default
;
87
TestPath
(
TestPath
&&) =
default
;
88
TestPath
&
89
operator=
(
TestPath
&&) =
default
;
90
91
template
<
class
First,
class
... Rest>
92
explicit
TestPath
(First&& first, Rest&&... rest)
93
{
94
addHelper
(
std::forward<First>
(first),
std::forward<Rest>
(rest)...);
95
}
96
TestPath
&
97
pushBack
(
Issue
const
& iss);
98
TestPath
&
99
pushBack
(
MPTIssue
const
& iss);
100
TestPath
&
101
pushBack
(
jtx::Account
const
& acc);
102
TestPath
&
103
pushBack
(
STPathElement
const
& pe);
104
[[nodiscard]]
json::Value
105
json
()
const
;
106
107
private
:
108
template
<
class
First,
class
... Rest>
109
void
110
addHelper
(First&& first, Rest&&... rest);
111
};
112
113
inline
TestPath&
114
TestPath::pushBack
(
STPathElement
const
& pe)
115
{
116
path
.emplaceBack(pe);
117
return
*
this
;
118
}
119
120
inline
TestPath
&
121
TestPath::pushBack
(
Issue
const
& iss)
122
{
123
path
.emplaceBack(
124
STPathElement::TypeCurrency
|
STPathElement::TypeIssuer
,
125
beast::kZero
,
126
iss.
currency
,
127
iss.
account
);
128
return
*
this
;
129
}
130
131
inline
TestPath
&
132
TestPath::pushBack
(
MPTIssue
const
& iss)
133
{
134
path
.emplaceBack(
135
STPathElement::TypeMpt
|
STPathElement::TypeIssuer
,
136
beast::kZero
,
137
iss.
getMptID
(),
138
iss.
getIssuer
());
139
return
*
this
;
140
}
141
142
inline
TestPath
&
143
TestPath::pushBack
(
jtx::Account
const
& account)
144
{
145
path
.emplaceBack(account.id(),
Currency
{beast::kZero},
beast::kZero
);
146
return
*
this
;
147
}
148
149
template
<
class
First,
class
... Rest>
150
void
151
TestPath::addHelper
(First&& first, Rest&&... rest)
152
{
153
pushBack
(
std::forward<First>
(first));
154
if
constexpr
(
sizeof
...(rest) > 0)
155
addHelper
(
std::forward<Rest>
(rest)...);
156
}
157
158
inline
json::Value
159
TestPath::json
()
const
160
{
161
return
path
.getJson(
JsonOptions::Values::None
);
162
}
163
164
class
PathSet
165
{
166
public
:
167
STPathSet
paths
;
168
169
PathSet
() =
default
;
170
PathSet
(
PathSet
const
&) =
default
;
171
PathSet
&
172
operator=
(
PathSet
const
&) =
default
;
173
PathSet
(
PathSet
&&) =
default
;
174
PathSet
&
175
operator=
(
PathSet
&&) =
default
;
176
177
template
<
class
First,
class
... Rest>
178
explicit
PathSet
(First&& first, Rest&&... rest)
179
{
180
addHelper
(
std::forward<First>
(first),
std::forward<Rest>
(rest)...);
181
}
182
[[nodiscard]]
json::Value
183
json
()
const
184
{
185
json::Value
v;
186
v[
"Paths"
] =
paths
.getJson(
JsonOptions::Values::None
);
187
return
v;
188
}
189
190
private
:
191
template
<
class
First,
class
... Rest>
192
void
193
addHelper
(First first, Rest... rest)
194
{
195
paths
.emplaceBack(std::move(first.path));
196
if
constexpr
(
sizeof
...(rest) > 0)
197
addHelper
(std::move(rest)...);
198
}
199
};
200
201
}
// namespace xrpl::test
json::Value
Represents a JSON value.
Definition
json_value.h:117
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:193
xrpl::test::PathSet::paths
STPathSet paths
Definition
PathSet.h:167
xrpl::test::PathSet::PathSet
PathSet(First &&first, Rest &&... rest)
Definition
PathSet.h:178
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:183
xrpl::test::PathSet::operator=
PathSet & operator=(PathSet const &)=default
xrpl::test::TestPath
Definition
PathSet.h:79
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:151
xrpl::test::TestPath::TestPath
TestPath()=default
xrpl::test::TestPath::TestPath
TestPath(First &&first, Rest &&... rest)
Definition
PathSet.h:92
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:81
xrpl::test::TestPath::json
json::Value json() const
Definition
PathSet.h:159
xrpl::test::TestPath::pushBack
TestPath & pushBack(Issue const &iss)
Definition
PathSet.h:121
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::countOffers
std::size_t countOffers(jtx::Env &env, jtx::Account const &account, Asset const &takerPays, Asset const &takerGets)
Count offer.
Definition
PathSet.h:25
xrpl::test::isOffer
bool isOffer(jtx::Env &env, jtx::Account const &account, STAmount const &takerPays, STAmount const &takerGets)
An offer exists.
Definition
PathSet.h:60
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