xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
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
18
namespace
xrpl::test::jtx
{
19
20
class
Env
;
21
26
struct
JTx
27
{
28
json::Value
jv
;
29
RequiresT
require
;
30
std::optional<TER>
ter
=
TER
{
tesSUCCESS
};
31
std::optional<std::pair<ErrorCodeI, std::string>
>
rpcCode
= std::nullopt;
32
std::optional<std::pair<std::string, std::optional<std::string>
>>
rpcException
= std::nullopt;
33
bool
fillFee
=
true
;
34
bool
fillSeq
=
true
;
35
bool
fillSig
=
true
;
36
bool
fillNetid
=
true
;
37
std::shared_ptr<STTx const>
stx
;
38
// Functions that sign the transaction from the Account
39
std::vector
<
std::function
<void(
Env
&,
JTx
&)>>
mainSigners
;
40
// Functions that sign something else after the mainSigners, such as
41
// sfCounterpartySignature and sfSponsorSignature
42
std::vector
<
std::function
<void(
Env
&,
JTx
&)>>
postSigners
;
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>
61
json::Value
&
62
operator[]
(Key
const
& key)
63
{
64
return
jv
[key];
65
}
66
73
template
<
class
Prop>
74
Prop
*
75
get
()
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
105
set
(
std::unique_ptr<BasicProp>
p)
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
{
122
set
(
std::make_unique
<
PropType<Prop>
>(
std::forward<Args>
(args)...));
123
}
124
125
126
private
:
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
153
std::vector<std::unique_ptr<BasicProp>
>
list
;
154
};
155
156
PropList
props_
;
157
};
158
159
}
// namespace xrpl::test::jtx
json::Value
Represents a JSON value.
Definition
json_value.h:117
xrpl::test::jtx::Env
A transaction testing environment.
Definition
Env.h:161
std::forward
T forward(T... args)
std::function
functional
std::unique_ptr::get
T get(T... args)
std::make_unique
T make_unique(T... args)
memory
std
STL namespace.
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test::jtx::RequiresT
std::vector< RequireT > RequiresT
Definition
requires.h:11
xrpl::test
Definition
STLedgerEntry.h:21
xrpl::TER
TERSubset< CanCvtToTER > TER
Definition
TER.h:654
xrpl::tesSUCCESS
@ tesSUCCESS
Definition
TER.h:250
optional
std::shared_ptr
string
xrpl::test::jtx::JTx::PropList
Definition
JTx.h:128
xrpl::test::jtx::JTx::PropList::PropList
PropList(PropList &&src)=default
xrpl::test::jtx::JTx::PropList::PropList
PropList(PropList const &other)
Definition
JTx.h:131
xrpl::test::jtx::JTx::PropList::PropList
PropList()=default
xrpl::test::jtx::JTx::PropList::operator=
PropList & operator=(PropList const &other)
Definition
JTx.h:138
xrpl::test::jtx::JTx::PropList::operator=
PropList & operator=(PropList &&src)=default
xrpl::test::jtx::JTx::PropList::list
std::vector< std::unique_ptr< BasicProp > > list
Definition
JTx.h:153
xrpl::test::jtx::JTx::fillSeq
bool fillSeq
Definition
JTx.h:34
xrpl::test::jtx::JTx::ter
std::optional< TER > ter
Definition
JTx.h:30
xrpl::test::jtx::JTx::JTx
JTx()=default
xrpl::test::jtx::JTx::JTx
JTx(json::Value const &jv)
Definition
JTx.h:56
xrpl::test::jtx::JTx::get
Prop const * get() const
Definition
JTx.h:87
xrpl::test::jtx::JTx::operator=
JTx & operator=(JTx const &)=default
xrpl::test::jtx::JTx::fillFee
bool fillFee
Definition
JTx.h:33
xrpl::test::jtx::JTx::operator=
JTx & operator=(JTx &&)=default
xrpl::test::jtx::JTx::get
Prop * get()
Return a property if it exists.
Definition
JTx.h:75
xrpl::test::jtx::JTx::require
RequiresT require
Definition
JTx.h:29
xrpl::test::jtx::JTx::JTx
JTx(JTx &&)=default
xrpl::test::jtx::JTx::set
void set(Args &&... args)
Definition
JTx.h:120
xrpl::test::jtx::JTx::postSigners
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition
JTx.h:42
xrpl::test::jtx::JTx::mainSigners
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition
JTx.h:39
xrpl::test::jtx::JTx::stx
std::shared_ptr< STTx const > stx
Definition
JTx.h:37
xrpl::test::jtx::JTx::operator[]
json::Value & operator[](Key const &key)
Definition
JTx.h:62
xrpl::test::jtx::JTx::props_
PropList props_
Definition
JTx.h:156
xrpl::test::jtx::JTx::set
void set(std::unique_ptr< BasicProp > p)
Set a property If the property already exists, it is replaced.
Definition
JTx.h:105
xrpl::test::jtx::JTx::jv
json::Value jv
Definition
JTx.h:28
xrpl::test::jtx::JTx::rpcCode
std::optional< std::pair< ErrorCodeI, std::string > > rpcCode
Definition
JTx.h:31
xrpl::test::jtx::JTx::fillNetid
bool fillNetid
Definition
JTx.h:36
xrpl::test::jtx::JTx::rpcException
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition
JTx.h:32
xrpl::test::jtx::JTx::fillSig
bool fillSig
Definition
JTx.h:35
xrpl::test::jtx::JTx::JTx
JTx(JTx const &)=default
xrpl::test::jtx::JTx::JTx
JTx(json::Value &&jv)
Definition
JTx.h:52
xrpl::test::jtx::PropType
Definition
basic_prop.h:18
xrpl::test::jtx::Prop
Set a property on a JTx.
Definition
prop.h:16
std::unique_ptr
utility
vector
Generated by
1.17.0