Skip to content

Commit

Permalink
network deserialization fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lisicky committed Oct 13, 2024
1 parent 05a0be9 commit 44190b6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/sidan-csl-rs/src/core/utils/evaluator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ pub fn evaluate_tx_scripts_js(
match serde_json::from_str(utxo_json.as_str()) {
Ok(utxo) => deserialized_utxos.push(utxo),
Err(e) => {
return WasmResult::new_error("failure".to_string(), format!("{:?}", e));
return WasmResult::new_error("failure".to_string(), format!("Error in decoding UTXO: {:?}", e));
}
}
}

let deserialize_network = match serde_json::from_str(network.as_str()) {
let deserialize_network = match network.try_into() {
Ok(network) => network,
Err(e) => {
return WasmResult::new_error("failure".to_string(), format!("Error in decoding network: {:?}", e));
Expand Down
13 changes: 13 additions & 0 deletions packages/sidan-csl-rs/src/model/tx_builder_types/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,16 @@ pub enum Network {
Preview,
Custom(Vec<Vec<i64>>),
}

impl TryFrom<String> for Network {
type Error = serde_json::Error;

fn try_from(s: String) -> Result<Self, Self::Error> {
match s.to_lowercase().as_str() {
"mainnet" => Ok(Network::Mainnet),
"preprod" => Ok(Network::Preprod),
"preview" => Ok(Network::Preview),
_ => serde_json::from_str(&s),
}
}
}

0 comments on commit 44190b6

Please sign in to comment.