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