rippled
Loading...
Searching...
No Matches
PathSet.h
1#pragma once
2
3#include <test/jtx.h>
4
5#include <xrpl/basics/Log.h>
6#include <xrpl/ledger/helpers/DirectoryHelpers.h>
7#include <xrpl/protocol/TxFlags.h>
8
9namespace xrpl {
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;
22 forEachItem(*env.current(), account, [&](std::shared_ptr<SLE const> const& sle) {
23 if (sle->getType() == ltOFFER && sle->getFieldAmount(sfTakerPays).issue() == takerPays &&
24 sle->getFieldAmount(sfTakerGets).issue() == takerGets)
25 ++count;
26 });
27 return count;
28}
29
30inline std::size_t
32 jtx::Env& env,
33 jtx::Account const& account,
34 STAmount const& takerPays,
35 STAmount const& takerGets)
36{
37 size_t count = 0;
38 forEachItem(*env.current(), account, [&](std::shared_ptr<SLE const> const& sle) {
39 if (sle->getType() == ltOFFER && sle->getFieldAmount(sfTakerPays) == takerPays &&
40 sle->getFieldAmount(sfTakerGets) == takerGets)
41 ++count;
42 });
43 return count;
44}
45
48inline bool
50 jtx::Env& env,
51 jtx::Account const& account,
52 STAmount const& takerPays,
53 STAmount const& takerGets)
54{
55 return countOffers(env, account, takerPays, takerGets) > 0;
56}
57
60inline bool
61isOffer(jtx::Env& env, jtx::Account const& account, Issue const& takerPays, Issue const& takerGets)
62{
63 return countOffers(env, account, takerPays, takerGets) > 0;
64}
65
66class Path
67{
68public:
70
71 Path() = default;
72 Path(Path const&) = default;
73 Path&
74 operator=(Path const&) = default;
75 Path(Path&&) = default;
76 Path&
77 operator=(Path&&) = default;
78
79 template <class First, class... Rest>
80 explicit Path(First&& first, Rest&&... rest)
81 {
83 }
84 Path&
85 push_back(Issue const& iss);
86 Path&
87 push_back(jtx::Account const& acc);
88 Path&
89 push_back(STPathElement const& pe);
91 json() const;
92
93private:
94 template <class First, class... Rest>
95 void
96 addHelper(First&& first, Rest&&... rest);
97};
98
99inline Path&
101{
102 path.emplace_back(pe);
103 return *this;
104}
105
106inline Path&
108{
109 path.emplace_back(
111 beast::zero,
112 iss.currency,
113 iss.account);
114 return *this;
115}
116
117inline Path&
119{
120 path.emplace_back(account.id(), beast::zero, beast::zero);
121 return *this;
122}
123
124template <class First, class... Rest>
125void
126Path::addHelper(First&& first, Rest&&... rest)
127{
129 if constexpr (sizeof...(rest) > 0)
131}
132
133inline Json::Value
135{
136 return path.getJson(JsonOptions::none);
137}
138
140{
141public:
143
144 PathSet() = default;
145 PathSet(PathSet const&) = default;
146 PathSet&
147 operator=(PathSet const&) = default;
148 PathSet(PathSet&&) = default;
149 PathSet&
150 operator=(PathSet&&) = default;
151
152 template <class First, class... Rest>
153 explicit PathSet(First&& first, Rest&&... rest)
154 {
156 }
158 json() const
159 {
160 Json::Value v;
161 v["Paths"] = paths.getJson(JsonOptions::none);
162 return v;
163 }
164
165private:
166 template <class First, class... Rest>
167 void
168 addHelper(First first, Rest... rest)
169 {
170 paths.emplace_back(std::move(first.path));
171 if constexpr (sizeof...(rest) > 0)
172 addHelper(std::move(rest)...);
173 }
174};
175
176} // namespace test
177} // namespace xrpl
Represents a JSON value.
Definition json_value.h:130
A currency issued by an account.
Definition Issue.h:13
Currency currency
Definition Issue.h:15
AccountID account
Definition Issue.h:16
void addHelper(First first, Rest... rest)
Definition PathSet.h:168
STPathSet paths
Definition PathSet.h:142
PathSet(First &&first, Rest &&... rest)
Definition PathSet.h:153
PathSet(PathSet const &)=default
PathSet & operator=(PathSet &&)=default
Json::Value json() const
Definition PathSet.h:158
PathSet(PathSet &&)=default
PathSet & operator=(PathSet const &)=default
Path(First &&first, Rest &&... rest)
Definition PathSet.h:80
Path & push_back(Issue const &iss)
Definition PathSet.h:107
Path(Path &&)=default
Path & operator=(Path &&)=default
Path(Path const &)=default
void addHelper(First &&first, Rest &&... rest)
Definition PathSet.h:126
Path & operator=(Path const &)=default
Json::Value json() const
Definition PathSet.h:134
Immutable cryptographic account descriptor.
Definition Account.h:19
A transaction testing environment.
Definition Env.h:122
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:329
Add a path.
Definition paths.h:38
Set Paths, SendMax on a JTx.
Definition paths.h:15
T is_same_v
std::size_t countOffers(jtx::Env &env, jtx::Account const &account, Issue const &takerPays, Issue const &takerGets)
Count offer.
Definition PathSet.h:15
bool isOffer(jtx::Env &env, jtx::Account const &account, STAmount const &takerPays, STAmount const &takerGets)
An offer exists.
Definition PathSet.h:49
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
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.