rippled
Loading...
Searching...
No Matches
JTx.h
1#ifndef XRPL_TEST_JTX_JTX_H_INCLUDED
2#define XRPL_TEST_JTX_JTX_H_INCLUDED
3
4#include <test/jtx/basic_prop.h>
5#include <test/jtx/requires.h>
6
7#include <xrpl/json/json_value.h>
8#include <xrpl/protocol/ErrorCodes.h>
9#include <xrpl/protocol/STTx.h>
10#include <xrpl/protocol/TER.h>
11
12#include <functional>
13#include <memory>
14#include <vector>
15
16namespace ripple {
17namespace test {
18namespace jtx {
19
20class Env;
21
25struct JTx
26{
33 bool fill_fee = true;
34 bool fill_seq = true;
35 bool fill_sig = true;
36 bool fill_netid = true;
38 // Functions that sign the transaction from the Account
40 // Functions that sign something else after the mainSigners, such as
41 // sfCounterpartySignature
43
44 JTx() = default;
45 JTx(JTx const&) = default;
46 JTx&
47 operator=(JTx const&) = default;
48 JTx(JTx&&) = default;
49 JTx&
50 operator=(JTx&&) = default;
51
52 JTx(Json::Value&& jv_) : jv(std::move(jv_))
53 {
54 }
55
56 JTx(Json::Value const& jv_) : jv(jv_)
57 {
58 }
59
60 template <class Key>
62 operator[](Key const& key)
63 {
64 return jv[key];
65 }
66
72 template <class Prop>
73 Prop*
75 {
76 for (auto& prop : props_.list)
77 {
78 if (auto test = dynamic_cast<prop_type<Prop>*>(prop.get()))
79 return &test->t;
80 }
81 return nullptr;
82 }
83
84 template <class Prop>
85 Prop const*
86 get() const
87 {
88 for (auto& prop : props_.list)
89 {
90 if (auto test = dynamic_cast<prop_type<Prop> const*>(prop.get()))
91 return &test->t;
92 }
93 return nullptr;
94 }
102 void
104 {
105 for (auto& prop : props_.list)
106 {
107 if (prop->assignable(p.get()))
108 {
109 prop = std::move(p);
110 return;
111 }
112 }
113 props_.list.emplace_back(std::move(p));
114 }
115
116 template <class Prop, class... Args>
117 void
118 set(Args&&... args)
119 {
121 }
124private:
126 {
127 prop_list() = default;
128
129 prop_list(prop_list const& other)
130 {
131 for (auto const& prop : other.list)
132 list.emplace_back(prop->clone());
133 }
134
135 prop_list&
136 operator=(prop_list const& other)
137 {
138 if (this != &other)
139 {
140 list.clear();
141 for (auto const& prop : other.list)
142 list.emplace_back(prop->clone());
143 }
144 return *this;
145 }
146
147 prop_list(prop_list&& src) = default;
148 prop_list&
149 operator=(prop_list&& src) = default;
150
152 };
153
155};
156
157} // namespace jtx
158} // namespace test
159} // namespace ripple
160
161#endif
Represents a JSON value.
Definition json_value.h:130
A transaction testing environment.
Definition Env.h:102
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:16
T get(T... args)
T is_same_v
T make_unique(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
@ tesSUCCESS
Definition TER.h:226
STL namespace.
prop_list & operator=(prop_list &&src)=default
prop_list(prop_list const &other)
Definition JTx.h:129
prop_list & operator=(prop_list const &other)
Definition JTx.h:136
std::vector< std::unique_ptr< basic_prop > > list
Definition JTx.h:151
prop_list(prop_list &&src)=default
Execution context for applying a JSON transaction.
Definition JTx.h:26
Prop * get()
Return a property if it exists.
Definition JTx.h:74
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition JTx.h:42
JTx(JTx const &)=default
void set(Args &&... args)
Definition JTx.h:118
JTx(JTx &&)=default
std::optional< std::pair< error_code_i, std::string > > rpcCode
Definition JTx.h:30
std::shared_ptr< STTx const > stx
Definition JTx.h:37
Json::Value jv
Definition JTx.h:27
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:32
void set(std::unique_ptr< basic_prop > p)
Set a property If the property already exists, it is replaced.
Definition JTx.h:103
JTx(Json::Value &&jv_)
Definition JTx.h:52
Json::Value & operator[](Key const &key)
Definition JTx.h:62
JTx & operator=(JTx const &)=default
requires_t require
Definition JTx.h:28
Prop const * get() const
Definition JTx.h:86
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition JTx.h:39
prop_list props_
Definition JTx.h:154
JTx(Json::Value const &jv_)
Definition JTx.h:56
JTx & operator=(JTx &&)=default
Set a property on a JTx.
Definition prop.h:15