whisky_js/wasm/
mod.rs

1use crate::*;
2mod transaction;
3mod tx_builder;
4mod tx_evaluator;
5mod tx_parser;
6mod utils;
7pub use transaction::*;
8pub use tx_builder::*;
9pub use tx_evaluator::*;
10pub use tx_parser::*;
11pub use utils::*;
12
13use whisky_common::*;
14
15#[wasm_bindgen]
16#[derive(Clone, Debug, Eq, Hash, PartialEq)]
17pub struct WasmResult {
18    status: String,
19    data: String,
20    error: String,
21}
22
23#[wasm_bindgen]
24impl WasmResult {
25    pub fn new(status: String, data: String) -> Self {
26        Self {
27            status,
28            data,
29            error: "".to_string(),
30        }
31    }
32
33    pub fn new_error(status: String, error: String) -> Self {
34        Self {
35            status,
36            data: "".to_string(),
37            error,
38        }
39    }
40
41    #[wasm_bindgen]
42    pub fn get_status(&self) -> String {
43        self.status.clone()
44    }
45
46    #[wasm_bindgen]
47    pub fn get_data(&self) -> String {
48        self.data.clone()
49    }
50
51    #[wasm_bindgen]
52    pub fn get_error(&self) -> String {
53        self.error.clone()
54    }
55}
56
57impl WasmResult {
58    pub fn from_result(result: Result<String, WError>) -> Self {
59        match result {
60            Ok(data) => Self::new("success".to_string(), data),
61            Err(e) => Self::new_error("failure".to_string(), format!("{:?}", e)),
62        }
63    }
64}