use crate::error::{Error, Result};
use serde::{Deserialize, Serialize};
use serde_json::Value;
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
pub struct ProofSpec {
pub strategy: Value,
pub dataset_ref: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub engine_version: Option<String>,
}
impl ProofSpec {
pub fn from_json(s: &str) -> Result<Self> {
let spec: Self = serde_json::from_str(s)?;
spec.validate()?;
Ok(spec)
}
pub fn from_toml(s: &str) -> Result<Self> {
let spec: Self = toml::from_str(s).map_err(|e| Error::Parse(e.to_string()))?;
spec.validate()?;
Ok(spec)
}
pub(crate) fn validate(&self) -> Result<()> {
if !self.strategy.is_object() {
return Err(Error::BadSpec(
"strategy must be a JSON object (a StrategySpec)".to_string(),
));
}
Ok(())
}
}