Skip to content

Commit

Permalink
feat: use serde_json_wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
willemneal committed Mar 19, 2024
1 parent c52da3d commit ce1f83f
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions crates/stellar-xdr-wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ pub fn type_variants() -> String {

// #[cfg(feature = "schema")]
#[wasm_bindgen]
pub fn schema(type_variant: &str) -> String {
let Schema(json_schema): Schema = type_variant.parse().unwrap();
serde_json::to_string(&json_schema).unwrap_or_else(|e| format!("{{\"error\": \"{e}\"}}"))
}

#[wasm_bindgen]
pub fn transaction() -> String {
let Schema(json_schema): Schema = TypeVariant::Transaction.try_into().unwrap();
serde_json::to_string(&json_schema).unwrap_or_else(|e| format!("{{\"error\": \"{e}\"}}"))
pub fn schema(type_variant: &str) -> Result<String, JsValue> {
let Schema(json_schema): Schema = type_variant
.parse()
.map_err(|_| JsValue::from_str("unknown type"))?;
serde_json_wasm::to_string(&json_schema).map_err(|e| JsValue::from_str(&format!("{e:?}")))
}

#[wasm_bindgen]
Expand All @@ -48,7 +44,7 @@ pub fn from_xdr(xdr_base64: String, variant: Option<String>) -> String {
{
f.inner.reset();
if let Ok(res) = curr::Type::read_xdr_to_end(variant, &mut f) {
return serde_json::to_string(&res)
return serde_json_wasm::to_string(&res)
.unwrap_or_else(|e| format!("{{\"error\": \"{e}\"}}"));
}
}
Expand Down

0 comments on commit ce1f83f

Please sign in to comment.