1use charms_client::{NormalizedSpell, tx::Tx};
2use wasm_bindgen::{JsValue, prelude::wasm_bindgen};
3
4pub const SPELL_VK: &str = "0x005a1df17094445572e4dd474b3e5dd9093936cba62ca3a62bb2ce63d9db8cba";
7
8#[wasm_bindgen(js_name = "extractAndVerifySpell")]
9pub fn extract_and_verify_spell_js(tx: JsValue, mock: bool) -> Result<JsValue, JsValue> {
10 let tx: Tx = serde_wasm_bindgen::from_value(tx)?;
11 let norm_spell = extract_and_verify_spell(&tx, mock)?;
12 let value = serde_wasm_bindgen::to_value(&norm_spell)?;
13 Ok(value)
14}
15
16pub fn extract_and_verify_spell(tx: &Tx, mock: bool) -> Result<NormalizedSpell, String> {
17 let norm_spell = charms_client::tx::extract_and_verify_spell(SPELL_VK, tx, mock)
18 .map_err(|e| e.to_string())?;
19 Ok(norm_spell)
20}
21
22#[cfg(test)]
23mod tests {
24 use super::*;
25
26 #[test]
27 fn test_extract_and_verify_spell() {
28 let tx_json = include_str!("../test/bitcoin-tx.json");
29 let tx: Tx = serde_json::from_str(tx_json).unwrap();
30 let norm_spell = extract_and_verify_spell(&tx, true).unwrap();
31 println!("{}", serde_json::to_string_pretty(&norm_spell).unwrap());
32 }
33}