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/protocol/TxFlags.h>
7
8namespace xrpl {
9namespace test {
10
13inline std::size_t
14countOffers(jtx::Env& env, jtx::Account const& account, Issue const& takerPays, Issue const& takerGets)
15{
16 size_t count = 0;
17 forEachItem(*env.current(), account, [&](std::shared_ptr<SLE const> const& sle) {
18 if (sle->getType() == ltOFFER && sle->getFieldAmount(sfTakerPays).issue() == takerPays &&
19 sle->getFieldAmount(sfTakerGets).issue() == takerGets)
20 ++count;
21 });
22 return count;
23}
24
25inline std::size_t
26countOffers(jtx::Env& env, jtx::Account const& account, STAmount const& takerPays, STAmount const& takerGets)
27{
28 size_t count = 0;
29 forEachItem(*env.current(), account, [&](std::shared_ptr<SLE const> const& sle) {
30 if (sle->getType() == ltOFFER && sle->getFieldAmount(sfTakerPays) == takerPays &&
31 sle->getFieldAmount(sfTakerGets) == takerGets)
32 ++count;
33 });
34 return count;
35}
36
39inline bool
40isOffer(jtx::Env& env, jtx::Account const& account, STAmount const& takerPays, STAmount const& takerGets)
41{
42 return countOffers(env, account, takerPays, takerGets) > 0;
43}
44
47inline bool
48isOffer(jtx::Env& env, jtx::Account const& account, Issue const& takerPays, Issue const& takerGets)
49{
50 return countOffers(env, account, takerPays, takerGets) > 0;
51}
52
53class Path
54{
55public:
57
58 Path() = default;
59 Path(Path const&) = default;
60 Path&
61 operator=(Path const&) = default;
62 Path(Path&&) = default;
63 Path&
64 operator=(Path&&) = default;
65
66 template <class First, class... Rest>
67 explicit Path(First&& first, Rest&&... rest)
68 {
70 }
71 Path&
72 push_back(Issue const& iss);
73 Path&
74 push_back(jtx::Account const& acc);
75 Path&
76 push_back(STPathElement const& pe);
78 json() const;
79
80private:
81 template <class First, class... Rest>
82 void
83 addHelper(First&& first, Rest&&... rest);
84};
85
86inline Path&
88{
89 path.emplace_back(pe);
90 return *this;
91}
92
93inline Path&
95{
96 path.emplace_back(STPathElement::typeCurrency | STPathElement::typeIssuer, beast::zero, iss.currency, iss.account);
97 return *this;
98}
99
100inline Path&
102{
103 path.emplace_back(account.id(), beast::zero, beast::zero);
104 return *this;
105}
106
107template <class First, class... Rest>
108void
109Path::addHelper(First&& first, Rest&&... rest)
110{
112 if constexpr (sizeof...(rest) > 0)
114}
115
116inline Json::Value
118{
119 return path.getJson(JsonOptions::none);
120}
121
123{
124public:
126
127 PathSet() = default;
128 PathSet(PathSet const&) = default;
129 PathSet&
130 operator=(PathSet const&) = default;
131 PathSet(PathSet&&) = default;
132 PathSet&
133 operator=(PathSet&&) = default;
134
135 template <class First, class... Rest>
136 explicit PathSet(First&& first, Rest&&... rest)
137 {
139 }
141 json() const
142 {
143 Json::Value v;
144 v["Paths"] = paths.getJson(JsonOptions::none);
145 return v;
146 }
147
148private:
149 template <class First, class... Rest>
150 void
151 addHelper(First first, Rest... rest)
152 {
153 paths.emplace_back(std::move(first.path));
154 if constexpr (sizeof...(rest) > 0)
155 addHelper(std::move(rest)...);
156 }
157};
158
159} // namespace test
160} // 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:151
STPathSet paths
Definition PathSet.h:125
PathSet(First &&first, Rest &&... rest)
Definition PathSet.h:136
PathSet(PathSet const &)=default
PathSet & operator=(PathSet &&)=default
Json::Value json() const
Definition PathSet.h:141
PathSet(PathSet &&)=default
PathSet & operator=(PathSet const &)=default
Path(First &&first, Rest &&... rest)
Definition PathSet.h:67
Path & push_back(Issue const &iss)
Definition PathSet.h:94
Path(Path &&)=default
Path & operator=(Path &&)=default
Path(Path const &)=default
void addHelper(First &&first, Rest &&... rest)
Definition PathSet.h:109
Path & operator=(Path const &)=default
Json::Value json() const
Definition PathSet.h:117
Immutable cryptographic account descriptor.
Definition Account.h:19
A transaction testing environment.
Definition Env.h:119
std::shared_ptr< OpenView const > current() const
Returns the current ledger.
Definition Env.h:319
Add a path.
Definition paths.h:37
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:14
bool isOffer(jtx::Env &env, jtx::Account const &account, STAmount const &takerPays, STAmount const &takerGets)
An offer exists.
Definition PathSet.h:40
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.
Definition View.cpp:598