casper_client/cli/session_str_params.rs
1use casper_types::bytesrepr::Bytes;
2
3/// Container for session-related arguments used while constructing a `Deploy`.
4///
5/// ## `session_args_simple`
6///
7/// For methods taking `session_args_simple`, this parameter is the session contract arguments, in
8/// the form `<NAME:TYPE='VALUE'>` or `<NAME:TYPE=null>`.
9///
10/// There are further details in
11/// [the docs for the equivalent
12/// `payment_args_simple`](struct.PaymentStrParams.html#payment_args_simple).
13///
14/// ## `session_args_json`
15///
16/// For methods taking `session_args_json`, this parameter is the session contract arguments, as a
17/// JSON-encoded Array of JSON Objects of the form:
18/// ```json
19/// [{"name":<String>,"type":<VALUE>,"value":<VALUE>}]
20/// ```
21///
22/// There are further details in
23/// [the docs for the equivalent `payment_args_json`](struct.PaymentStrParams.html#payment_args_json).
24///
25/// ---
26///
27/// **Note** while multiple session args can be specified for a single session code instance, only
28/// one of `session_args_simple`, or `session_args_json` may be used.
29#[derive(Default, Debug)]
30pub struct SessionStrParams<'a> {
31 pub(super) session_hash: &'a str,
32 pub(super) session_name: &'a str,
33 pub(super) session_package_hash: &'a str,
34 pub(super) session_package_name: &'a str,
35 pub(super) session_path: &'a str,
36 pub(super) session_bytes: Bytes,
37 pub(super) session_args_simple: Vec<&'a str>,
38 pub(super) session_args_json: &'a str,
39 pub(super) session_version: &'a str,
40 pub(super) session_entry_point: &'a str,
41 pub(super) is_session_transfer: bool,
42 pub(super) session_chunked_args: Option<&'a [u8]>,
43}
44
45impl<'a> SessionStrParams<'a> {
46 /// Constructs a `SessionStrParams` using a session smart contract file.
47 ///
48 /// * `session_path` is the path to the compiled Wasm session code.
49 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
50 /// [`session_args_json`](#session_args_json)
51 pub fn with_path(
52 session_path: &'a str,
53 session_args_simple: Vec<&'a str>,
54 session_args_json: &'a str,
55 ) -> Self {
56 Self {
57 session_path,
58 session_args_simple,
59 session_args_json,
60 ..Default::default()
61 }
62 }
63
64 /// Constructs a `SessionStrParams` using session bytes.
65 ///
66 /// * `session_bytes` are the bytes of the compiled Wasm session code.
67 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
68 /// [`session_args_json`](#session_args_json)
69 pub fn with_bytes(
70 session_bytes: Bytes,
71 session_args_simple: Vec<&'a str>,
72 session_args_json: &'a str,
73 ) -> Self {
74 Self {
75 session_bytes,
76 session_args_simple,
77 session_args_json,
78 ..Default::default()
79 }
80 }
81
82 /// Constructs a `SessionStrParams` using a stored contract's name.
83 ///
84 /// * `session_name` is the name of the stored contract (associated with the executing account)
85 /// to be called as the session.
86 /// * `session_entry_point` is the name of the method that will be used when calling the session
87 /// contract.
88 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
89 /// [`session_args_json`](#session_args_json)
90 pub fn with_name(
91 session_name: &'a str,
92 session_entry_point: &'a str,
93 session_args_simple: Vec<&'a str>,
94 session_args_json: &'a str,
95 ) -> Self {
96 Self {
97 session_name,
98 session_args_simple,
99 session_args_json,
100 session_entry_point,
101 ..Default::default()
102 }
103 }
104
105 /// Constructs a `SessionStrParams` using a stored contract's hex-encoded hash.
106 ///
107 /// * `session_hash` is the hex-encoded hash of the stored contract to be called as the session.
108 /// * `session_entry_point` is the name of the method that will be used when calling the session
109 /// contract.
110 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
111 /// [`session_args_json`](#session_args_json)
112 pub fn with_hash(
113 session_hash: &'a str,
114 session_entry_point: &'a str,
115 session_args_simple: Vec<&'a str>,
116 session_args_json: &'a str,
117 ) -> Self {
118 Self {
119 session_hash,
120 session_args_simple,
121 session_args_json,
122 session_entry_point,
123 ..Default::default()
124 }
125 }
126
127 /// Constructs a `SessionStrParams` using a stored contract's package name.
128 ///
129 /// * `session_package_name` is the name of the stored package to be called as the session.
130 /// * `session_version` is the version of the called session contract. The latest will be used
131 /// if `session_version` is empty.
132 /// * `session_entry_point` is the name of the method that will be used when calling the session
133 /// contract.
134 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
135 /// [`session_args_json`](#session_args_json)
136 pub fn with_package_name(
137 session_package_name: &'a str,
138 session_version: &'a str,
139 session_entry_point: &'a str,
140 session_args_simple: Vec<&'a str>,
141 session_args_json: &'a str,
142 ) -> Self {
143 Self {
144 session_package_name,
145 session_args_simple,
146 session_args_json,
147 session_version,
148 session_entry_point,
149 ..Default::default()
150 }
151 }
152
153 /// Constructs a `SessionStrParams` using a stored contract's package hash.
154 ///
155 /// * `session_package_hash` is the hex-encoded hash of the stored package to be called as the
156 /// session.
157 /// * `session_version` is the version of the called session contract. The latest will be used
158 /// if `session_version` is empty.
159 /// * `session_entry_point` is the name of the method that will be used when calling the session
160 /// contract.
161 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
162 /// [`session_args_json`](#session_args_json)
163 pub fn with_package_hash(
164 session_package_hash: &'a str,
165 session_version: &'a str,
166 session_entry_point: &'a str,
167 session_args_simple: Vec<&'a str>,
168 session_args_json: &'a str,
169 ) -> Self {
170 Self {
171 session_package_hash,
172 session_args_simple,
173 session_args_json,
174 session_version,
175 session_entry_point,
176 ..Default::default()
177 }
178 }
179
180 /// Constructs a `SessionStrParams` representing a `Transfer` type of `Deploy`.
181 ///
182 /// * See the struct docs for a description of [`session_args_simple`](#session_args_simple),
183 /// [`session_args_json`](#session_args_json)
184 pub fn with_transfer(session_args_simple: Vec<&'a str>, session_args_json: &'a str) -> Self {
185 Self {
186 is_session_transfer: true,
187 session_args_simple,
188 session_args_json,
189 ..Default::default()
190 }
191 }
192}