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{
51 rpcException = std::nullopt;
52 bool fill_fee = true;
53 bool fill_seq = true;
54 bool fill_sig = true;
55 bool fill_netid = true;
58
59 JTx() = default;
60 JTx(JTx const&) = default;
61 JTx&
62 operator=(JTx const&) = default;
63 JTx(JTx&&) = default;
64 JTx&
65 operator=(JTx&&) = default;
66
67 JTx(Json::Value&& jv_) : jv(std::move(jv_))
68 {
69 }
70
71 JTx(Json::Value const& jv_) : jv(jv_)
72 {
73 }
74
75 template <class Key>
77 operator[](Key const& key)
78 {
79 return jv[key];
80 }
81
87 template <class Prop>
88 Prop*
90 {
91 for (auto& prop : props_.list)
92 {
93 if (auto test = dynamic_cast<prop_type<Prop>*>(prop.get()))
94 return &test->t;
95 }
96 return nullptr;
97 }
98
99 template <class Prop>
100 Prop const*
101 get() const
102 {
103 for (auto& prop : props_.list)
104 {
105 if (auto test = dynamic_cast<prop_type<Prop> const*>(prop.get()))
106 return &test->t;
107 }
108 return nullptr;
109 }
117 void
119 {
120 for (auto& prop : props_.list)
121 {
122 if (prop->assignable(p.get()))
123 {
124 prop = std::move(p);
125 return;
126 }
127 }
128 props_.list.emplace_back(std::move(p));
129 }
130
131 template <class Prop, class... Args>
132 void
133 set(Args&&... args)
134 {
135 set(std::make_unique<prop_type<Prop>>(std::forward<Args>(args)...));
136 }
139private:
141 {
142 prop_list() = default;
143
144 prop_list(prop_list const& other)
145 {
146 for (auto const& prop : other.list)
147 list.emplace_back(prop->clone());
148 }
149
150 prop_list&
151 operator=(prop_list const& other)
152 {
153 if (this != &other)
154 {
155 list.clear();
156 for (auto const& prop : other.list)
157 list.emplace_back(prop->clone());
158 }
159 return *this;
160 }
161
162 prop_list(prop_list&& src) = default;
163 prop_list&
164 operator=(prop_list&& src) = default;
165
167 };
168
170};
171
172} // namespace jtx
173} // namespace test
174} // namespace ripple
175
176#endif
Represents a JSON value.
Definition: json_value.h:150
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 make_unique(T... args)
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
@ tesSUCCESS
Definition: TER.h:244
STL namespace.
prop_list & operator=(prop_list &&src)=default
prop_list(prop_list const &other)
Definition: JTx.h:144
prop_list & operator=(prop_list const &other)
Definition: JTx.h:151
std::vector< std::unique_ptr< basic_prop > > list
Definition: JTx.h:166
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:89
JTx(JTx const &)=default
void set(Args &&... args)
Definition: JTx.h:133
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:118
std::function< void(Env &, JTx &)> signer
Definition: JTx.h:57
JTx(Json::Value &&jv_)
Definition: JTx.h:67
Json::Value & operator[](Key const &key)
Definition: JTx.h:77
JTx & operator=(JTx const &)=default
requires_t require
Definition: JTx.h:47
Prop const * get() const
Definition: JTx.h:101
prop_list props_
Definition: JTx.h:169
JTx(Json::Value const &jv_)
Definition: JTx.h:71
JTx & operator=(JTx &&)=default
Set a property on a JTx.
Definition: prop.h:34