whisky_js/wasm/
tx_builder.rs1use crate::*;
2use wasm::WasmResult;
3use whisky_common::*;
4use whisky_csl::WhiskyCSL;
5
6#[wasm_bindgen]
19pub fn js_serialize_tx_body(tx_builder_body_json: &str, params_json: &str) -> WasmResult {
20 let tx_builder_body: TxBuilderBody = match serde_json::from_str(tx_builder_body_json) {
21 Ok(tx_builder_body) => tx_builder_body,
22 Err(e) => {
23 return WasmResult::new_error("failure".to_string(), format!("Invalid JSON: {:?}", e))
24 }
25 };
26
27 let params: Option<Protocol> = match serde_json::from_str(params_json) {
28 Ok(params) => Some(params),
29 Err(e) => {
30 return WasmResult::new_error(
31 "failure".to_string(),
32 format!("Invalid Protocol Param JSON: {:?} \n {:?}", params_json, e),
33 )
34 }
35 };
36
37 let mut tx_builder = WhiskyCSL::new(params).unwrap();
38 tx_builder.tx_builder_body = tx_builder_body;
39
40 match tx_builder.unbalanced_serialize_tx_body() {
41 Ok(tx_hex) => WasmResult::new("success".to_string(), tx_hex.to_string()),
42 Err(e) => WasmResult::new_error("failure".to_string(), format!("{:?}", e.to_string())),
43 }
44}