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 <vector>
14
15namespace xrpl::test::jtx {
16
17class Env;
18
22struct JTx
23{
29 bool fillFee = true;
30 bool fillSeq = true;
31 bool fillSig = true;
32 bool fillNetid = true;
34 // Functions that sign the transaction from the Account
36 // Functions that sign something else after the mainSigners, such as
37 // sfCounterpartySignature
39
40 JTx() = default;
41 JTx(JTx const&) = default;
42 JTx&
43 operator=(JTx const&) = default;
44 JTx(JTx&&) = default;
45 JTx&
46 operator=(JTx&&) = default;
47
48 JTx(json::Value&& jv) : jv(std::move(jv))
49 {
50 }
51
52 JTx(json::Value const& jv) : jv(jv)
53 {
54 }
55
56 template <class Key>
58 operator[](Key const& key)
59 {
60 return jv[key];
61 }
62
68 template <class Prop>
69 Prop*
71 {
72 for (auto& prop : props_.list)
73 {
74 if (auto test = dynamic_cast<PropType<Prop>*>(prop.get()))
75 return &test->t;
76 }
77 return nullptr;
78 }
79
80 template <class Prop>
81 [[nodiscard]] Prop const*
82 get() const
83 {
84 for (auto& prop : props_.list)
85 {
86 if (auto test = dynamic_cast<PropType<Prop> const*>(prop.get()))
87 return &test->t;
88 }
89 return nullptr;
90 }
91
92
98 void
100 {
101 for (auto& prop : props_.list)
102 {
103 if (prop->assignable(p.get()))
104 {
105 prop = std::move(p);
106 return;
107 }
108 }
109 props_.list.emplace_back(std::move(p));
110 }
111
112 template <class Prop, class... Args>
113 void
114 set(Args&&... args)
115 {
117 }
118
119
120private:
121 struct PropList
122 {
123 PropList() = default;
124
125 PropList(PropList const& other)
126 {
127 for (auto const& prop : other.list)
128 list.emplace_back(prop->clone());
129 }
130
131 PropList&
132 operator=(PropList const& other)
133 {
134 if (this != &other)
135 {
136 list.clear();
137 for (auto const& prop : other.list)
138 list.emplace_back(prop->clone());
139 }
140 return *this;
141 }
142
143 PropList(PropList&& src) = default;
144 PropList&
145 operator=(PropList&& src) = default;
146
148 };
149
151};
152
153} // namespace xrpl::test::jtx
Represents a JSON value.
Definition json_value.h:130
A transaction testing environment.
Definition Env.h:143
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:634
@ tesSUCCESS
Definition TER.h:240
PropList(PropList &&src)=default
PropList(PropList const &other)
Definition JTx.h:125
PropList & operator=(PropList const &other)
Definition JTx.h:132
PropList & operator=(PropList &&src)=default
std::vector< std::unique_ptr< BasicProp > > list
Definition JTx.h:147
std::optional< TER > ter
Definition JTx.h:26
JTx(json::Value const &jv)
Definition JTx.h:52
Prop const * get() const
Definition JTx.h:82
JTx & operator=(JTx const &)=default
JTx & operator=(JTx &&)=default
Prop * get()
Return a property if it exists.
Definition JTx.h:70
JTx(JTx &&)=default
void set(Args &&... args)
Definition JTx.h:114
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition JTx.h:38
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition JTx.h:35
requires_t require
Definition JTx.h:25
std::shared_ptr< STTx const > stx
Definition JTx.h:33
json::Value & operator[](Key const &key)
Definition JTx.h:58
PropList props_
Definition JTx.h:150
void set(std::unique_ptr< BasicProp > p)
Set a property If the property already exists, it is replaced.
Definition JTx.h:99
json::Value jv
Definition JTx.h:24
std::optional< std::pair< ErrorCodeI, std::string > > rpcCode
Definition JTx.h:27
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:28
JTx(JTx const &)=default
JTx(json::Value &&jv)
Definition JTx.h:48
Set a property on a JTx.
Definition prop.h:12