Skip to content

Commit

Permalink
change to serde err
Browse files Browse the repository at this point in the history
  • Loading branch information
OlofBlomqvist committed Jul 19, 2023
1 parent 0bfcc10 commit 750954c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ plutus_data = { version = "0.0.6", optional = true }
console_error_panic_hook = { version = "0.1.7", optional = true }
serde_derive = { version = "1.0.171", optional = true }
#uplc = { git = "https://github.com/txpipe/aiken", optional = true }
hex = { version = "0.4.3", optional = true }
hex = { version = "0.4.3" }
minicbor = { version = "0.19.1", optional = true }

getrandom = { version = "0.2.10", features = ["js"], optional = true}
Expand Down Expand Up @@ -49,7 +49,6 @@ wasi = []
utils = [
"dep:minicbor",
"dep:plutus_data",
"dep:hex",
"dep:serde_derive" ]
js = [
"utils",
Expand Down
8 changes: 8 additions & 0 deletions src/lib/extras/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ use crate::extras::utils::*;

use plutus_data::FromPlutusData;


#[cfg(feature="infinite-recursion")]
pub fn basic_deserialize<'a,T : 'static>(json:&str) -> Result<T,serde_json::Error>
where T : serde::de::DeserializeOwned + std::marker::Send{
let j = json.to_owned();
Expand All @@ -20,9 +22,15 @@ where T : serde::de::DeserializeOwned + std::marker::Send{
let deserializer = serde_stacker::Deserializer::new(&mut deserializer);
let value = T::deserialize(deserializer).unwrap();
Ok(value)
}

#[cfg(not(feature="infinite-recursion"))]
pub fn basic_deserialize<'a,T : 'static>(json:&str) -> Result<T,serde_json::Error>
where T : serde::de::DeserializeOwned + std::marker::Send{
serde_json::de::from_str(&json)
}


#[wasm_bindgen]
pub fn decode_marlowe_dsl_from_json(dsl:&str) -> String {
let result : Contract = basic_deserialize(dsl).unwrap();
Expand Down
2 changes: 2 additions & 0 deletions src/lib/serialization/cborhex.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[cfg(feature="utils")]
pub fn serialize<T>(contract:T) -> Result<String,String> where T:plutus_data::ToPlutusData{
match plutus_data::to_hex(
&(contract.to_plutus_data(&[])?)
Expand All @@ -7,6 +8,7 @@ pub fn serialize<T>(contract:T) -> Result<String,String> where T:plutus_data::To
}
}

#[cfg(feature="utils")]
pub fn to_bytes<T>(contract:T) -> Result<Vec<u8>,String> where T:plutus_data::ToPlutusData{
match plutus_data::to_bytes(
&(contract.to_plutus_data(&[])?)
Expand Down

0 comments on commit 750954c

Please sign in to comment.