2021-08-26 17:27:05 +03:00
|
|
|
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-02-10 15:23:51 +03:00
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-10 15:23:51 +03:00
|
|
|
pub struct InsertResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
pub success: bool,
|
2021-02-10 15:23:51 +03:00
|
|
|
pub error: String,
|
|
|
|
}
|
|
|
|
|
2021-02-11 17:57:09 +03:00
|
|
|
impl From<Result<(), ServiceError>> for InsertResult {
|
|
|
|
fn from(result: Result<(), ServiceError>) -> Self {
|
2021-02-10 15:23:51 +03:00
|
|
|
match result {
|
|
|
|
Ok(()) => InsertResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: true,
|
2021-02-10 15:23:51 +03:00
|
|
|
error: "".to_string(),
|
|
|
|
},
|
|
|
|
Err(e) => InsertResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: false,
|
2021-02-11 17:57:09 +03:00
|
|
|
error: format!("{}", e),
|
2021-02-10 15:23:51 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-10 15:23:51 +03:00
|
|
|
pub struct WeightResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
pub success: bool,
|
2021-02-10 15:23:51 +03:00
|
|
|
pub weight: Vec<u32>,
|
2021-02-10 15:26:26 +03:00
|
|
|
pub error: String,
|
2021-02-10 15:23:51 +03:00
|
|
|
}
|
|
|
|
|
2021-02-11 17:57:09 +03:00
|
|
|
impl From<Result<Option<u32>, ServiceError>> for WeightResult {
|
|
|
|
fn from(result: Result<Option<u32>, ServiceError>) -> Self {
|
2021-02-10 15:23:51 +03:00
|
|
|
match result {
|
|
|
|
Ok(wo) => WeightResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: true,
|
2021-02-10 15:23:51 +03:00
|
|
|
weight: wo.map(|w| vec![w]).unwrap_or(vec![]),
|
|
|
|
error: "".to_string(),
|
|
|
|
},
|
|
|
|
Err(e) => WeightResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: false,
|
2021-02-10 15:23:51 +03:00
|
|
|
weight: vec![],
|
2021-02-11 17:57:09 +03:00
|
|
|
error: format!("{}", e),
|
2021-02-10 15:23:51 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-01 16:31:13 +03:00
|
|
|
#[marine]
|
2021-02-10 15:23:51 +03:00
|
|
|
pub struct AllCertsResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
pub success: bool,
|
2021-02-10 15:23:51 +03:00
|
|
|
pub certificates: Vec<Certificate>,
|
2021-02-10 15:26:26 +03:00
|
|
|
pub error: String,
|
2021-02-10 15:23:51 +03:00
|
|
|
}
|
|
|
|
|
2021-02-11 17:57:09 +03:00
|
|
|
impl From<Result<Vec<Certificate>, ServiceError>> for AllCertsResult {
|
|
|
|
fn from(result: Result<Vec<Certificate>, ServiceError>) -> Self {
|
2021-02-10 15:23:51 +03:00
|
|
|
match result {
|
|
|
|
Ok(certs) => AllCertsResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: true,
|
2021-02-10 15:23:51 +03:00
|
|
|
certificates: certs,
|
|
|
|
error: "".to_string(),
|
|
|
|
},
|
|
|
|
Err(e) => AllCertsResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: false,
|
2021-02-10 15:23:51 +03:00
|
|
|
certificates: vec![],
|
2021-02-11 17:57:09 +03:00
|
|
|
error: format!("{}", e),
|
2021-02-10 15:23:51 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
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 {
|
2021-08-26 17:27:05 +03:00
|
|
|
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 {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: true,
|
2021-02-12 14:54:08 +03:00
|
|
|
error: "".to_string(),
|
|
|
|
},
|
|
|
|
Err(e) => AddRootResult {
|
2021-08-26 17:27:05 +03:00
|
|
|
success: false,
|
2021-02-12 14:54:08 +03:00
|
|
|
error: format!("{}", e),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-08-26 17:27:05 +03:00
|
|
|
|
|
|
|
#[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(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|