whisky_js/wasm/
tx_parser.rs

1use crate::*;
2use serde_json::json;
3use wasm::WasmResult;
4use whisky_common::*;
5use whisky_csl::*;
6
7#[wasm_bindgen]
8pub fn js_parse_tx_body(tx_hex: &str) -> WasmResult {
9    let tx_parser = TxParser::new(tx_hex);
10    match tx_parser {
11        Err(e) => WasmResult::new_error("failure".to_string(), format!("{:?}", e)),
12        Ok(parser) => WasmResult::new("success".to_string(), (json!(parser)).to_string()),
13    }
14}
15
16#[wasm_bindgen]
17pub fn js_get_tx_outs_utxo(tx_hex: &str) -> WasmResult {
18    let get_tx_outs_utxo = || -> Result<String, WError> {
19        let tx_parser = TxParser::new(tx_hex)?;
20        let tx_outs = tx_parser.get_tx_outs_utxo()?;
21        Ok((json!(tx_outs)).to_string())
22    };
23    let res = get_tx_outs_utxo();
24    WasmResult::from_result(res)
25}