casper_client/cli/
session_str_params.rs

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