142 lines
3.5 KiB
Rust
Raw Normal View History

use crate::dto::{Certificate, Trust};
2021-02-12 14:42:51 +03:00
use crate::service_impl::ServiceError;
2021-08-01 16:31:13 +03:00
use marine_rs_sdk::marine;
2021-08-01 16:31:13 +03:00
#[marine]
pub struct InsertResult {
pub success: bool,
pub error: String,
}
2021-02-11 17:57:09 +03:00
impl From<Result<(), ServiceError>> for InsertResult {
fn from(result: Result<(), ServiceError>) -> Self {
match result {
Ok(()) => InsertResult {
success: true,
error: "".to_string(),
},
Err(e) => InsertResult {
success: false,
2021-02-11 17:57:09 +03:00
error: format!("{}", e),
},
}
}
}
2021-08-01 16:31:13 +03:00
#[marine]
pub struct WeightResult {
pub success: bool,
pub weight: Vec<u32>,
2021-02-10 15:26:26 +03:00
pub error: String,
}
2021-02-11 17:57:09 +03:00
impl From<Result<Option<u32>, ServiceError>> for WeightResult {
fn from(result: Result<Option<u32>, ServiceError>) -> Self {
match result {
Ok(wo) => WeightResult {
success: true,
weight: wo.map(|w| vec![w]).unwrap_or(vec![]),
error: "".to_string(),
},
Err(e) => WeightResult {
success: false,
weight: vec![],
2021-02-11 17:57:09 +03:00
error: format!("{}", e),
},
}
}
}
2021-08-01 16:31:13 +03:00
#[marine]
pub struct AllCertsResult {
pub success: bool,
pub certificates: Vec<Certificate>,
2021-02-10 15:26:26 +03:00
pub error: String,
}
2021-02-11 17:57:09 +03:00
impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
fn from(result: Result<Vec<Certificate>, ServiceError>) -> Self {
match result {
Ok(certs) => AllCertsResult {
success: true,
certificates: certs,
error: "".to_string(),
},
Err(e) => AllCertsResult {
success: false,
certificates: vec![],
2021-02-11 17:57:09 +03:00
error: format!("{}", e),
},
}
}
2021-02-10 15:26:26 +03:00
}
2021-02-12 14:54:08 +03:00
2021-08-01 16:31:13 +03:00
#[marine]
2021-02-12 14:54:08 +03:00
pub struct AddRootResult {
pub success: bool,
2021-02-12 14:54:08 +03:00
pub error: String,
}
impl From<Result<(), ServiceError>> for AddRootResult {
fn from(result: Result<(), ServiceError>) -> Self {
match result {
Ok(()) => AddRootResult {
success: true,
2021-02-12 14:54:08 +03:00
error: "".to_string(),
},
Err(e) => AddRootResult {
success: false,
2021-02-12 14:54:08 +03:00
error: format!("{}", e),
},
}
}
}
#[marine]
pub struct GetTrustMetadataResult {
pub success: bool,
pub error: String,
pub result: Vec<u8>,
}
impl From<Result<Vec<u8>, ServiceError>> for GetTrustMetadataResult {
fn from(result: Result<Vec<u8>, ServiceError>) -> Self {
match result {
Ok(res) => GetTrustMetadataResult {
success: true,
error: "".to_string(),
result: res
},
Err(e) => GetTrustMetadataResult {
success: false,
error: format!("{}", e),
result: vec![]
},
}
}
}
#[marine]
pub struct IssueTrustResult {
pub success: bool,
pub error: String,
pub trust: Trust,
}
impl From<Result<Trust, ServiceError>> for IssueTrustResult {
fn from(result: Result<Trust, ServiceError>) -> Self {
match result {
Ok(trust) => IssueTrustResult {
success: true,
error: "".to_string(),
trust,
},
Err(e) => IssueTrustResult {
success: false,
error: format!("{}", e),
trust: Trust::default(),
},
}
}
}