whisky_js/wasm/
mod.rs

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