verifier/api/
models.rs

1use super::types::VerifyJobStatus;
2use semver;
3use serde::Deserialize;
4use std::path::PathBuf;
5
6#[derive(Debug, Deserialize)]
7pub struct Error {
8    pub error: String,
9}
10
11#[derive(Debug, Deserialize)]
12pub struct VerificationJobDispatch {
13    pub job_id: String,
14}
15
16#[derive(Debug, Deserialize)]
17pub struct VerificationJob {
18    pub job_id: String,
19    pub status: VerifyJobStatus,
20    pub status_description: Option<String>,
21    pub message: Option<String>,
22    pub error_category: Option<String>,
23    pub class_hash: Option<String>,
24    pub created_timestamp: Option<f64>,
25    pub updated_timestamp: Option<f64>,
26    pub address: Option<String>,
27    pub contract_file: Option<String>,
28    pub name: Option<String>,
29    pub version: Option<String>,
30    pub license: Option<String>,
31}
32
33impl VerificationJob {
34    pub const fn status(&self) -> &VerifyJobStatus {
35        &self.status
36    }
37
38    pub fn class_hash(&self) -> &str {
39        self.class_hash.as_deref().unwrap_or("unknown")
40    }
41
42    pub fn job_id(&self) -> &str {
43        &self.job_id
44    }
45
46    pub fn name(&self) -> Option<&str> {
47        self.name.as_deref()
48    }
49
50    pub fn contract_file(&self) -> Option<&str> {
51        self.contract_file.as_deref()
52    }
53
54    pub fn status_description(&self) -> Option<&str> {
55        self.status_description.as_deref()
56    }
57
58    pub fn message(&self) -> Option<&str> {
59        self.message.as_deref()
60    }
61
62    pub fn error_category(&self) -> Option<&str> {
63        self.error_category.as_deref()
64    }
65
66    pub const fn created_timestamp(&self) -> Option<f64> {
67        self.created_timestamp
68    }
69
70    pub const fn updated_timestamp(&self) -> Option<f64> {
71        self.updated_timestamp
72    }
73
74    pub fn address(&self) -> Option<&str> {
75        self.address.as_deref()
76    }
77
78    pub fn version(&self) -> Option<&str> {
79        self.version.as_deref()
80    }
81
82    pub fn license(&self) -> Option<&str> {
83        self.license.as_deref()
84    }
85
86    pub const fn is_completed(&self) -> bool {
87        matches!(
88            self.status,
89            VerifyJobStatus::Success | VerifyJobStatus::Fail | VerifyJobStatus::CompileFailed
90        )
91    }
92
93    pub const fn has_failed(&self) -> bool {
94        matches!(
95            self.status,
96            VerifyJobStatus::Fail | VerifyJobStatus::CompileFailed
97        )
98    }
99}
100
101#[derive(Debug, Eq, PartialEq)]
102pub struct FileInfo {
103    pub name: String,
104    pub path: PathBuf,
105}
106
107#[derive(Debug, Clone)]
108pub struct ProjectMetadataInfo {
109    pub cairo_version: semver::Version,
110    pub scarb_version: semver::Version,
111    pub project_dir_path: String,
112    pub contract_file: String,
113    pub package_name: String,
114}