rippled
Loading...
Searching...
No Matches
paths.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TEST_JTX_PATHS_H_INCLUDED
21#define RIPPLE_TEST_JTX_PATHS_H_INCLUDED
22
23#include <test/jtx/Env.h>
24#include <xrpl/protocol/Issue.h>
25
26#include <type_traits>
27
28namespace ripple {
29namespace test {
30namespace jtx {
31
33class paths
34{
35private:
37 int depth_;
38 unsigned int limit_;
39
40public:
41 paths(Issue const& in, int depth = 7, unsigned int limit = 4)
42 : in_(in), depth_(depth), limit_(limit)
43 {
44 }
45
46 void
47 operator()(Env&, JTx& jt) const;
48};
49
50//------------------------------------------------------------------------------
51
56class path
57{
58private:
60
61public:
63
64 template <class T, class... Args>
65 explicit path(T const& t, Args const&... args);
66
67 void
68 operator()(Env&, JTx& jt) const;
69
70private:
72 create();
73
74 void
75 append_one(Account const& account);
76
77 void
78 append_one(AccountID const& account);
79
80 template <class T>
82 append_one(T const& t)
83 {
85 }
86
87 void
88 append_one(IOU const& iou);
89
90 void
91 append_one(BookSpec const& book);
92
93 template <class T, class... Args>
94 void
95 append(T const& t, Args const&... args);
96};
97
98template <class T, class... Args>
99path::path(T const& t, Args const&... args) : jv_(Json::arrayValue)
100{
101 append(t, args...);
102}
103
104template <class T, class... Args>
105void
106path::append(T const& t, Args const&... args)
107{
108 append_one(t);
109 if constexpr (sizeof...(args) > 0)
110 append(args...);
111}
112
113} // namespace jtx
114} // namespace test
115} // namespace ripple
116
117#endif
Represents a JSON value.
Definition: json_value.h:148
A currency issued by an account.
Definition: Issue.h:36
Immutable cryptographic account descriptor.
Definition: Account.h:39
A transaction testing environment.
Definition: Env.h:118
Converts to IOU Issue or STAmount.
Add a path.
Definition: paths.h:57
std::enable_if_t< std::is_constructible< Account, T >::value > append_one(T const &t)
Definition: paths.h:82
Json::Value jv_
Definition: paths.h:59
Json::Value & create()
Definition: paths.cpp:61
void append(T const &t, Args const &... args)
Definition: paths.h:106
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:96
void append_one(Account const &account)
Definition: paths.cpp:67
Set Paths, SendMax on a JTx.
Definition: paths.h:34
unsigned int limit_
Definition: paths.h:38
paths(Issue const &in, int depth=7, unsigned int limit=4)
Definition: paths.h:41
void operator()(Env &, JTx &jt) const
Definition: paths.cpp:29
JSON (JavaScript Object Notation).
Definition: json_errors.h:25
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
Execution context for applying a JSON transaction.
Definition: JTx.h:44