Get the value of a plaintext input as a javascript object (this function is not part of the public API)
(
&self,
plaintext: &PlaintextType<CurrentNetwork>,
visibility: Option<String>,
name: Option<String>,
)
| 243 | // Get the value of a plaintext input as a javascript object (this function is not part of the |
| 244 | // public API) |
| 245 | fn get_plaintext_input( |
| 246 | &self, |
| 247 | plaintext: &PlaintextType<CurrentNetwork>, |
| 248 | visibility: Option<String>, |
| 249 | name: Option<String>, |
| 250 | ) -> Result<Object, String> { |
| 251 | let input = Object::new(); |
| 252 | match plaintext { |
| 253 | PlaintextType::Array(array_type) => { |
| 254 | if let Some(name) = name { |
| 255 | Reflect::set(&input, &"name".into(), &name.into()).map_err(|_| "Failed to set property")?; |
| 256 | } |
| 257 | Reflect::set(&input, &"type".into(), &"array".into()).map_err(|_| "Failed to set property")?; |
| 258 | |
| 259 | // Set the element types of the Array and record the length |
| 260 | let element_type = self.get_plaintext_input(array_type.base_element_type(), None, None)?; |
| 261 | let length = **array_type.length(); |
| 262 | Reflect::set(&input, &"element_type".into(), &element_type).map_err(|_| "Failed to set property")?; |
| 263 | Reflect::set(&input, &"length".into(), &length.into()).map_err(|_| "Failed to set property")?; |
| 264 | } |
| 265 | PlaintextType::Literal(literal_type) => { |
| 266 | if let Some(name) = name { |
| 267 | Reflect::set(&input, &"name".into(), &name.into()).map_err(|_| "Failed to set property")?; |
| 268 | } |
| 269 | let value_type = JsValue::from_str(&literal_type.to_string()); |
| 270 | Reflect::set(&input, &"type".into(), &value_type).map_err(|_| "Failed to set property")?; |
| 271 | } |
| 272 | PlaintextType::Struct(struct_id) => { |
| 273 | let struct_name = struct_id.to_string(); |
| 274 | if let Some(name) = name { |
| 275 | Reflect::set(&input, &"name".into(), &name.into()).map_err(|_| "Failed to set property")?; |
| 276 | } |
| 277 | Reflect::set(&input, &"type".into(), &"struct".into()).map_err(|_| "Failed to set property")?; |
| 278 | Reflect::set(&input, &"struct_id".into(), &struct_name.as_str().into()) |
| 279 | .map_err(|_| "Failed to set property")?; |
| 280 | let inputs = self.get_struct_members(struct_name)?; |
| 281 | Reflect::set(&input, &"members".into(), &inputs.into()).map_err(|_| "Failed to set property")?; |
| 282 | } |
| 283 | PlaintextType::ExternalStruct(struct_locator) => { |
| 284 | let struct_name = struct_locator.name(); |
| 285 | |
| 286 | if let Some(name) = name { |
| 287 | Reflect::set(&input, &"name".into(), &name.into()).map_err(|_| "Failed to set property")?; |
| 288 | } |
| 289 | Reflect::set(&input, &"type".into(), &"struct".into()).map_err(|_| "Failed to set property")?; |
| 290 | Reflect::set(&input, &"struct_id".into(), &struct_name.to_string().into()) |
| 291 | .map_err(|_| "Failed to set property")?; |
| 292 | let inputs = self.get_struct_members(struct_name.to_string())?; |
| 293 | Reflect::set(&input, &"members".into(), &inputs.into()).map_err(|_| "Failed to set property")?; |
| 294 | } |
| 295 | } |
| 296 | if let Some(visibility) = visibility { |
| 297 | Reflect::set(&input, &"visibility".into(), &visibility.into()).map_err(|_| "Failed to set property")?; |
| 298 | } |
| 299 | |
| 300 | Ok(input) |
| 301 | } |
| 302 |
no test coverage detected