rippled
Loading...
Searching...
No Matches
PathSet.h
1#ifndef XRPL_LEDGER_TESTS_PATHSET_H_INCLUDED
2#define XRPL_LEDGER_TESTS_PATHSET_H_INCLUDED
3
4#include <test/jtx.h>
5
6#include <xrpl/basics/Log.h>
7#include <xrpl/protocol/TxFlags.h>
8
9namespace ripple {
10namespace test {
11
14inline std::size_t
16 jtx::Env& env,
17 jtx::Account const& account,
18 Issue const& takerPays,
19 Issue const& takerGets)
20{
21 size_t count = 0;
23 *env.current(), account, [&](std::shared_ptr<SLE const> const& sle) {
24 if (sle->getType() == ltOFFER &&
25 sle->getFieldAmount(sfTakerPays).issue() == takerPays &&
26 sle->getFieldAmount(sfTakerGets).issue() == takerGets)
27 ++count;
28 });
29 return count;
30}
31
32inline std::size_t
34 jtx::Env& env,
35 jtx::Account const& account,
36 STAmount const& takerPays,
37 STAmount const& takerGets)
38{
39 size_t count = 0;
41 *env.current(), account, [&](std::shared_ptr<SLE const> const& sle) {
42 if (sle->getType() == ltOFFER &&
43 sle->getFieldAmount(sfTakerPays) == takerPays &&
44 sle->getFieldAmount(sfTakerGets) == takerGets)
45 ++count;
46 });
47 return count;
48}
49
52inline bool
54 jtx::Env& env,
55 jtx::Account const& account,
56 STAmount const& takerPays,
57 STAmount const& takerGets)
58{
59 return countOffers(env, account, takerPays, takerGets) > 0;
60}
61
64inline bool
66 jtx::Env& env,
67 jtx::Account const& account,
68 Issue const& takerPays,
69 Issue const& takerGets)
70{
71 return countOffers(env, account, takerPays, takerGets) > 0;
72}
73
74class Path
75{
76public:
78
79 Path() = default;
80 Path(Path const&) = default;
81 Path&
82 operator=(Path const&) = default;
83 Path(Path&&) = default;
84 Path&
85 operator=(Path&&) = default;
86
87 template <class First, class... Rest>
88 explicit Path(First&& first, Rest&&... rest)
89 {
91 }
92 Path&
93 push_back(Issue const& iss);
94 Path&
95 push_back(jtx::Account const& acc);
96 Path&
97 push_back(STPathElement const& pe);
99 json() const;
100
101private:
102 template <class First, class... Rest>
103 void
104 addHelper(First&& first, Rest&&... rest);
105};
106
107inline Path&
109{
110 path.emplace_back(pe);
111 return *this;
112}
113
114inline Path&
116{
117 path.emplace_back(
119 beast::zero,
120 iss.currency,
121 iss.account);
122 return *this;
123}
124
125inline Path&
127{
128 path.emplace_back(account.id(), beast::zero, beast::zero);
129 return *this;
130}
131
132template <class First, class... Rest>
133void
134Path::addHelper(First&& first, Rest&&... rest)
135{
137 if constexpr (sizeof...(rest) > 0)
139}
140
141inline Json::Value
143{
144 return path.getJson(JsonOptions::none);
145}
146
148{
149public:
151
152 PathSet() = default;
153 PathSet(PathSet const&) = default;
154 PathSet&
155 operator=(PathSet const&) = default;
156 PathSet(PathSet&&) = default;
157 PathSet&
158 operator=(PathSet&&) = default;
159
160 template <class First, class... Rest>
161 explicit PathSet(First&& first, Rest&&... rest)
162 {
164 }
166 json() const
167 {
168 Json::Value v;
169 v["Paths"] = paths.getJson(JsonOptions::none);
170 return v;
171 }
172
173private:
174 template <class First, class... Rest>
175 void
176 addHelper(First first, Rest... rest)
177 {
178 paths.emplace_back(std::move(first.path));
179 if constexpr (sizeof...(rest) > 0)
180 addHelper(std::move(rest)...);
181 }
182};
183
184} // namespace test
185} // namespace ripple
186
187#endif
Represents a JSON value.
Definition json_value.h:130
A currency issued by an account.
Definition Issue.h:14
AccountID account
Definition Issue.h:17
Currency currency
Definition Issue.h:16
PathSet & operator=(PathSet const &)=default
PathSet(First &&first, Rest &&... rest)
Definition PathSet.h:161
PathSet(PathSet &&)=default
Json::Value json() const
Definition PathSet.h:166
PathSet(PathSet const &)=default
void addHelper(First first, Rest... rest)
Definition PathSet.h:176
PathSet & operator=(PathSet &&)=default
Json::Value json() const
Definition PathSet.h:142
Path & operator=(Path &&)=default
Path(First &&first, Rest &&... rest)
Definition PathSet.h:88
void addHelper(First &&first, Rest &&... rest)
Definition PathSet.h:134
Path & push_back(Issue const &iss)
Definition PathSet.h:115
Path(Path &&)=default
Path(Path const &)=default
Path & operator=(Path const &)=default
Immutable cryptographic account descriptor.
Definition Account.h:20
A transaction testing environment.
Definition Env.h:102
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:312
Add a path.
Definition paths.h:39
Set Paths, SendMax on a JTx.
Definition paths.h:16
T is_same_v
bool isOffer(jtx::Env &env, jtx::Account const &account, STAmount const &takerPays, STAmount const &takerGets)
An offer exists.
Definition PathSet.h:53
std::size_t countOffers(jtx::Env &env, jtx::Account const &account, Issue const &takerPays, Issue const &takerGets)
Count offer.
Definition PathSet.h:15
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
void forEachItem(ReadView const &view, Keylet const &root, std::function< void(std::shared_ptr< SLE const > const &)> const &f)
Iterate all items in the given directory.
Definition View.cpp:637