pub fn decode_plutus_datum_to_json_str(
datum: &PlutusData,
schema: PlutusDatumSchema
) -> Result<String, JsError>
Examples found in repository?
src/plutus.rs (line 716)
715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
pub fn to_json(&self, schema: PlutusDatumSchema) -> Result<String, JsError> {
decode_plutus_datum_to_json_str(self, schema)
}
pub fn from_json(json: &str, schema: PlutusDatumSchema) -> Result<PlutusData, JsError> {
encode_json_str_to_plutus_datum(json, schema)
}
}
//TODO: replace this by cardano-node schemas
impl JsonSchema for PlutusData {
fn is_referenceable() -> bool {
String::is_referenceable()
}
fn schema_name() -> String {
String::from("PlutusData")
}
fn json_schema(gen: &mut schemars::gen::SchemaGenerator) -> schemars::schema::Schema {
String::json_schema(gen)
}
}
//TODO: need to figure out what schema to use here
impl serde::Serialize for PlutusData {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: serde::Serializer {
let json = decode_plutus_datum_to_json_str(
self,
PlutusDatumSchema::DetailedSchema)
.map_err(|ser_err| serde::ser::Error::custom(&format!("Serialization error: {:?}", ser_err)))?;
serializer.serialize_str(&json)
}