sidan_csl_rs/wasm/
mod.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use crate::*;
mod transaction;
mod txbuilder;
use cardano_serialization_lib::JsError;
pub use transaction::*;
pub use txbuilder::*;

#[wasm_bindgen]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct WasmResult {
    status: String,
    data: String,
    error: String,
}

#[wasm_bindgen]
impl WasmResult {
    pub fn new(status: String, data: String) -> Self {
        Self {
            status,
            data,
            error: "".to_string(),
        }
    }

    pub fn new_error(status: String, error: String) -> Self {
        Self {
            status,
            data: "".to_string(),
            error,
        }
    }

    #[wasm_bindgen]
    pub fn get_status(&self) -> String {
        self.status.clone()
    }

    #[wasm_bindgen]
    pub fn get_data(&self) -> String {
        self.data.clone()
    }

    #[wasm_bindgen]
    pub fn get_error(&self) -> String {
        self.error.clone()
    }
}

impl WasmResult {
    pub fn from_result(result: Result<String, JsError>) -> Self {
        match result {
            Ok(data) => Self::new("success".to_string(), data),
            Err(e) => Self::new_error("failure".to_string(), format!("{:?}", e)),
        }
    }
}