259 lines
6.3 KiB
Rust
Raw Normal View History

2021-09-27 16:04:59 +03:00
use crate::dto::{Certificate, Revoke, 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,
2021-09-14 14:21:26 +03:00
pub weight: u32,
pub peer_id: String,
2021-02-10 15:26:26 +03:00
pub error: String,
}
impl From<Result<(u32, String), ServiceError>> for WeightResult {
fn from(result: Result<(u32, String), ServiceError>) -> Self {
match result {
Ok((weight, peer_id)) => WeightResult {
success: true,
weight,
peer_id,
error: "".to_string(),
},
Err(e) => WeightResult {
success: false,
weight: 0u32,
peer_id: "".to_string(),
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 GetTrustBytesResult {
pub success: bool,
pub error: String,
pub result: Vec<u8>,
}
impl From<Result<Vec<u8>, ServiceError>> for GetTrustBytesResult {
fn from(result: Result<Vec<u8>, ServiceError>) -> Self {
match result {
Ok(res) => GetTrustBytesResult {
success: true,
error: "".to_string(),
2021-09-06 18:13:08 +03:00
result: res,
},
Err(e) => GetTrustBytesResult {
success: false,
error: format!("{}", e),
2021-09-06 18:13:08 +03:00
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(),
},
}
}
}
2021-09-06 18:13:08 +03:00
#[marine]
pub struct VerifyTrustResult {
pub success: bool,
pub error: String,
}
impl From<Result<(), ServiceError>> for VerifyTrustResult {
fn from(result: Result<(), ServiceError>) -> Self {
match result {
Ok(()) => VerifyTrustResult {
success: true,
error: "".to_string(),
},
Err(e) => VerifyTrustResult {
success: false,
error: format!("{}", e),
},
}
}
}
#[marine]
2021-09-14 14:21:26 +03:00
pub struct AddTrustResult {
2021-09-06 18:13:08 +03:00
pub success: bool,
pub error: String,
2021-09-14 14:21:26 +03:00
pub weight: u32,
2021-09-06 18:13:08 +03:00
}
2021-09-14 14:21:26 +03:00
impl From<Result<u32, ServiceError>> for AddTrustResult {
fn from(result: Result<u32, ServiceError>) -> Self {
2021-09-06 18:13:08 +03:00
match result {
2021-09-14 14:21:26 +03:00
Ok(weight) => AddTrustResult {
2021-09-06 18:13:08 +03:00
success: true,
error: "".to_string(),
2021-09-14 14:21:26 +03:00
weight,
2021-09-06 18:13:08 +03:00
},
2021-09-14 14:21:26 +03:00
Err(e) => AddTrustResult {
2021-09-06 18:13:08 +03:00
success: false,
error: format!("{}", e),
2021-09-14 14:21:26 +03:00
weight: u32::default(),
2021-09-06 18:13:08 +03:00
},
}
}
}
2021-09-27 16:04:59 +03:00
#[marine]
pub struct GetRevokeBytesResult {
pub success: bool,
pub error: String,
pub result: Vec<u8>,
}
impl From<Result<Vec<u8>, ServiceError>> for GetRevokeBytesResult {
fn from(result: Result<Vec<u8>, ServiceError>) -> Self {
match result {
Ok(res) => GetRevokeBytesResult {
success: true,
error: "".to_string(),
result: res,
},
Err(e) => GetRevokeBytesResult {
success: false,
error: format!("{}", e),
result: vec![],
},
}
}
}
#[marine]
pub struct IssueRevocationResult {
pub success: bool,
pub error: String,
pub revoke: Revoke,
}
impl From<Result<Revoke, ServiceError>> for IssueRevocationResult {
fn from(result: Result<Revoke, ServiceError>) -> Self {
match result {
Ok(revoke) => IssueRevocationResult {
success: true,
error: "".to_string(),
revoke,
},
Err(e) => IssueRevocationResult {
success: false,
error: format!("{}", e),
revoke: Revoke::default(),
},
}
}
}
#[marine]
pub struct RevokeResult {
pub success: bool,
pub error: String,
}
impl From<Result<(), ServiceError>> for RevokeResult {
fn from(result: Result<(), ServiceError>) -> Self {
match result {
Ok(()) => RevokeResult {
success: true,
error: "".to_string(),
},
Err(e) => RevokeResult {
success: false,
error: format!("{}", e),
},
}
}
}