whisky/builder/
data.rs

1use crate::*;
2
3#[derive(Clone, Debug)]
4pub enum WData {
5    JSON(String),
6    CBOR(String),
7}
8
9impl WData {
10    pub fn to_cbor(&self) -> Result<String, WError> {
11        match self {
12            WData::CBOR(data) => Ok(data.clone()),
13            WData::JSON(data) => {
14                let data_cbor =
15                    &csl::PlutusData::from_json(data, csl::PlutusDatumSchema::DetailedSchema)
16                        .map_err(WError::from_err("WData - to_cbor"))?
17                        .to_hex();
18                Ok(data_cbor.clone())
19            }
20        }
21    }
22
23    pub fn to_hash(&self) -> Result<String, WError> {
24        let cbor = self.to_cbor()?;
25        let hash = &csl::hash_plutus_data(
26            &csl::PlutusData::from_hex(&cbor).map_err(WError::from_err("WData - to_hash"))?,
27        )
28        .to_hex();
29        Ok(hash.to_string())
30    }
31}
32
33#[derive(Clone, Debug)]
34pub struct WRedeemer {
35    pub data: WData,
36    pub ex_units: Budget,
37}
38
39#[derive(Clone, Debug)]
40pub struct WDatum {
41    pub type_: String,
42    pub data: WData,
43}