rippled
Loading...
Searching...
No Matches
JTx.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012, 2013 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TEST_JTX_JTX_H_INCLUDED
21#define RIPPLE_TEST_JTX_JTX_H_INCLUDED
22
23#include <test/jtx/basic_prop.h>
24#include <test/jtx/requires.h>
25
26#include <xrpl/json/json_value.h>
27#include <xrpl/protocol/ErrorCodes.h>
28#include <xrpl/protocol/STTx.h>
29#include <xrpl/protocol/TER.h>
30
31#include <functional>
32#include <memory>
33#include <vector>
34
35namespace ripple {
36namespace test {
37namespace jtx {
38
39class Env;
40
44struct JTx
45{
52 bool fill_fee = true;
53 bool fill_seq = true;
54 bool fill_sig = true;
55 bool fill_netid = true;
57 // Functions that sign the transaction from the Account
59 // Functions that sign something else after the mainSigners, such as
60 // sfCounterpartySignature
62
63 JTx() = default;
64 JTx(JTx const&) = default;
65 JTx&
66 operator=(JTx const&) = default;
67 JTx(JTx&&) = default;
68 JTx&
69 operator=(JTx&&) = default;
70
71 JTx(Json::Value&& jv_) : jv(std::move(jv_))
72 {
73 }
74
75 JTx(Json::Value const& jv_) : jv(jv_)
76 {
77 }
78
79 template <class Key>
81 operator[](Key const& key)
82 {
83 return jv[key];
84 }
85
91 template <class Prop>
92 Prop*
94 {
95 for (auto& prop : props_.list)
96 {
97 if (auto test = dynamic_cast<prop_type<Prop>*>(prop.get()))
98 return &test->t;
99 }
100 return nullptr;
101 }
102
103 template <class Prop>
104 Prop const*
105 get() const
106 {
107 for (auto& prop : props_.list)
108 {
109 if (auto test = dynamic_cast<prop_type<Prop> const*>(prop.get()))
110 return &test->t;
111 }
112 return nullptr;
113 }
121 void
123 {
124 for (auto& prop : props_.list)
125 {
126 if (prop->assignable(p.get()))
127 {
128 prop = std::move(p);
129 return;
130 }
131 }
132 props_.list.emplace_back(std::move(p));
133 }
134
135 template <class Prop, class... Args>
136 void
137 set(Args&&... args)
138 {
140 }
143private:
145 {
146 prop_list() = default;
147
148 prop_list(prop_list const& other)
149 {
150 for (auto const& prop : other.list)
151 list.emplace_back(prop->clone());
152 }
153
154 prop_list&
155 operator=(prop_list const& other)
156 {
157 if (this != &other)
158 {
159 list.clear();
160 for (auto const& prop : other.list)
161 list.emplace_back(prop->clone());
162 }
163 return *this;
164 }
165
166 prop_list(prop_list&& src) = default;
167 prop_list&
168 operator=(prop_list&& src) = default;
169
171 };
172
174};
175
176} // namespace jtx
177} // namespace test
178} // namespace ripple
179
180#endif
Represents a JSON value.
Definition json_value.h:149
A transaction testing environment.
Definition Env.h:121
Set the expected result code for a JTx The test will fail if the code doesn't match.
Definition ter.h:35
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:25
@ tesSUCCESS
Definition TER.h:244
STL namespace.
prop_list & operator=(prop_list &&src)=default
prop_list(prop_list const &other)
Definition JTx.h:148
prop_list & operator=(prop_list const &other)
Definition JTx.h:155
std::vector< std::unique_ptr< basic_prop > > list
Definition JTx.h:170
prop_list(prop_list &&src)=default
Execution context for applying a JSON transaction.
Definition JTx.h:45
Prop * get()
Return a property if it exists.
Definition JTx.h:93
std::vector< std::function< void(Env &, JTx &)> > postSigners
Definition JTx.h:61
JTx(JTx const &)=default
void set(Args &&... args)
Definition JTx.h:137
JTx(JTx &&)=default
std::optional< std::pair< error_code_i, std::string > > rpcCode
Definition JTx.h:49
std::shared_ptr< STTx const > stx
Definition JTx.h:56
Json::Value jv
Definition JTx.h:46
std::optional< std::pair< std::string, std::optional< std::string > > > rpcException
Definition JTx.h:51
void set(std::unique_ptr< basic_prop > p)
Set a property If the property already exists, it is replaced.
Definition JTx.h:122
JTx(Json::Value &&jv_)
Definition JTx.h:71
Json::Value & operator[](Key const &key)
Definition JTx.h:81
JTx & operator=(JTx const &)=default
requires_t require
Definition JTx.h:47
Prop const * get() const
Definition JTx.h:105
std::vector< std::function< void(Env &, JTx &)> > mainSigners
Definition JTx.h:58
prop_list props_
Definition JTx.h:173
JTx(Json::Value const &jv_)
Definition JTx.h:75
JTx & operator=(JTx &&)=default
Set a property on a JTx.
Definition prop.h:34