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#include <type_traits>
26
27namespace ripple {
28namespace test {
29namespace jtx {
30
32class paths
33{
34private:
36 int depth_;
37 unsigned int limit_;
38
39public:
40 paths(Issue const& in, int depth = 7, unsigned int limit = 4)
41 : in_(in), depth_(depth), limit_(limit)
42 {
43 }
44
45 void
46 operator()(Env&, JTx& jt) const;
47};
48
49//------------------------------------------------------------------------------
50
55class path
56{
57private:
59
60public:
62
63 template <class T, class... Args>
64 explicit path(T const& t, Args const&... args);
65
66 void
67 operator()(Env&, JTx& jt) const;
68
69private:
71 create();
72
73 void
74 append_one(Account const& account);
75
76 void
77 append_one(AccountID const& account);
78
79 template <class T>
81 append_one(T const& t)
82 {
84 }
85
86 void
87 append_one(IOU const& iou);
88
89 void
90 append_one(BookSpec const& book);
91
92 template <class T, class... Args>
93 void
94 append(T const& t, Args const&... args);
95};
96
97template <class T, class... Args>
98path::path(T const& t, Args const&... args) : jv_(Json::arrayValue)
99{
100 append(t, args...);
101}
102
103template <class T, class... Args>
104void
105path::append(T const& t, Args const&... args)
106{
107 append_one(t);
108 if constexpr (sizeof...(args) > 0)
109 append(args...);
110}
111
112} // namespace jtx
113} // namespace test
114} // namespace ripple
115
116#endif
Represents a JSON value.
Definition: json_value.h:147
A currency issued by an account.
Definition: Issue.h:36
Immutable cryptographic account descriptor.
Definition: Account.h:38
A transaction testing environment.
Definition: Env.h:117
Converts to IOU Issue or STAmount.
Add a path.
Definition: paths.h:56
std::enable_if_t< std::is_constructible< Account, T >::value > append_one(T const &t)
Definition: paths.h:81
Json::Value jv_
Definition: paths.h:58
Json::Value & create()
Definition: paths.cpp:61
void append(T const &t, Args const &... args)
Definition: paths.h:105
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:33
unsigned int limit_
Definition: paths.h:37
paths(Issue const &in, int depth=7, unsigned int limit=4)
Definition: paths.h:40
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