use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum JobStatus {
Queued,
Running,
Proving,
Done,
Failed,
Settled,
}
impl JobStatus {
pub fn is_terminal(&self) -> bool {
matches!(self, Self::Failed | Self::Settled)
}
pub fn is_success(&self) -> bool {
matches!(self, Self::Settled)
}
}
impl std::fmt::Display for JobStatus {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Self::Queued => "queued",
Self::Running => "running",
Self::Proving => "proving",
Self::Done => "done",
Self::Failed => "failed",
Self::Settled => "settled",
};
write!(f, "{s}")
}
}
#[derive(Debug, Clone, Serialize)]
pub(crate) struct SubmitJobRequest {
pub input_data: Vec<Vec<f64>>,
pub model_id: String,
}
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct SubmitJobResponse {
pub job_id: String,
pub status: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Job {
pub job_id: String,
pub status: JobStatus,
pub proof_path: Option<String>,
pub tx_hash: Option<String>,
pub attestation_hash: Option<String>,
pub reason: Option<String>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Proof {
pub job_id: String,
pub proof_hex: String,
pub size_bytes: usize,
}
#[derive(Debug, Clone, Serialize)]
pub struct RegisterModelRequest {
pub name: String,
pub version: String,
pub artifact_b64: String,
pub input_shape: Vec<u64>,
}
#[derive(Debug, Clone, Deserialize)]
pub struct RegisterModelResponse {
pub model_id: String,
pub on_chain_model_id: String,
pub ipfs_cid: String,
pub gateway_url: String,
pub on_chain_hash: String,
}
#[derive(Debug, Clone, Deserialize)]
pub struct Health {
pub status: String,
pub version: String,
pub settle_enabled: bool,
pub db: String,
}
impl Health {
pub fn is_healthy(&self) -> bool {
self.status == "ok" && self.db == "connected"
}
}
#[derive(Debug, Clone)]
pub struct VerifyResult {
pub job_id: String,
pub status: JobStatus,
pub tx_hash: Option<String>,
pub attestation_hash: Option<String>,
pub elapsed_ms: u64,
}