xrpld
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 <optional>
14#include <string>
15#include <utility>
16#include <vector>
17
18namespace xrpl::test::jtx {
19
20class Env;
21
26struct JTx
27{
33 bool fillFee = true;
34 bool fillSeq = true;
35 bool fillSig = true;
36 bool fillNetid = true;
38 // Functions that sign the transaction from the Account
40 // Functions that sign something else after the mainSigners, such as
41 // sfCounterpartySignature and sfSponsorSignature
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
73 template <class Prop>
74 Prop*
76 {
77 for (auto& prop : props_.list)
78 {
79 if (auto test = dynamic_cast<PropType<Prop>*>(prop.get()))
80 return &test->t;
81 }
82 return nullptr;
83 }
84
85 template <class Prop>
86 [[nodiscard]] Prop const*
87 get() const
88 {
89 for (auto& prop : props_.list)
90 {
91 if (auto test = dynamic_cast<PropType<Prop> const*>(prop.get()))
92 return &test->t;
93 }
94 return nullptr;
95 }
96
97
104 void
106 {
107 for (auto& prop : props_.list)
108 {
109 if (prop->assignable(p.get()))
110 {
111 prop = std::move(p);
112 return;
113 }
114 }
115 props_.list.emplace_back(std::move(p));
116 }
117
118 template <class Prop, class... Args>
119 void
120 set(Args&&... args)
121 {
123 }
124
125
126private:
127 struct PropList
128 {
129 PropList() = default;
130
131 PropList(PropList const& other)
132 {
133 for (auto const& prop : other.list)
134 list.emplace_back(prop->clone());
135 }
136
137 PropList&
138 operator=(PropList const& other)
139 {
140 if (this != &other)
141 {
142 list.clear();
143 for (auto const& prop : other.list)
144 list.emplace_back(prop->clone());
145 }
146 return *this;
147 }
148
149 PropList(PropList&& src) = default;
150 PropList&
151 operator=(PropList&& src) = default;
152
154 };
155
157};
158
159} // namespace xrpl::test::jtx
Represents a JSON value.
Definition json_value.h:117
A transaction testing environment.
Definition Env.h:161
T forward(T... args)
T get(T... args)
T make_unique(T... args)
STL namespace.
std::vector< require_t > requires_t
Definition requires.h:11
TERSubset< CanCvtToTER > TER
Definition TER.h:647
@ tesSUCCESS
Definition TER.h:245
PropList(PropList &&src)=default
PropList(PropList const &other)
Definition JTx.h:131
PropList & operator=(PropList const &other)
Definition JTx.h:138
PropList & operator=(PropList &&src)=default
std::vector< std::unique_ptr< BasicProp > > list
Definition JTx.h:153
std::optional< TER > ter
Definition JTx.h:30
JTx(json::Value const &jv)
Definition JTx.h:56
Prop const * get() const
Definition JTx.h:87
JTx & operator=(JTx const &)=default
JTx & operator=(JTx &&)=default
Prop * get()
Return a property if it exists.
Definition JTx.h:75
JTx(JTx &&)=default
void set(Args &&... args)
Definition JTx.h:120
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition JTx.h:42
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition JTx.h:39
requires_t require
Definition JTx.h:29
std::shared_ptr< STTx const > stx
Definition JTx.h:37
json::Value & operator[](Key const &key)
Definition JTx.h:62
PropList props_
Definition JTx.h:156
void set(std::unique_ptr< BasicProp > p)
Set a property If the property already exists, it is replaced.
Definition JTx.h:105
json::Value jv
Definition JTx.h:28
std::optional< std::pair< ErrorCodeI, std::string > > rpcCode
Definition JTx.h:31
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:32
JTx(JTx const &)=default
JTx(json::Value &&jv)
Definition JTx.h:52
Set a property on a JTx.
Definition prop.h:16