2021-04-27 16:53:01 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2021 Fluence Labs Limited
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
use crate::error::ServiceError;
|
2022-02-24 16:37:58 +03:00
|
|
|
use crate::record::Record;
|
2022-03-10 19:49:38 +04:00
|
|
|
use crate::route::Route;
|
2021-06-17 19:26:55 +03:00
|
|
|
use marine_rs_sdk::marine;
|
2021-04-27 16:53:01 +03:00
|
|
|
|
2021-05-11 18:32:37 +03:00
|
|
|
#[marine]
|
|
|
|
#[derive(Debug)]
|
2021-05-31 13:30:23 +03:00
|
|
|
pub struct DhtResult {
|
2021-05-11 18:32:37 +03:00
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
impl From<Result<(), ServiceError>> for DhtResult {
|
|
|
|
fn from(result: Result<(), ServiceError>) -> Self {
|
2021-04-27 16:53:01 +03:00
|
|
|
match result {
|
|
|
|
Ok(_) => Self {
|
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-11 18:32:37 +03:00
|
|
|
#[marine]
|
2022-02-24 16:37:58 +03:00
|
|
|
#[derive(Debug)]
|
2022-03-10 19:49:38 +04:00
|
|
|
pub struct RegisterRouteResult {
|
2022-02-24 16:37:58 +03:00
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
2022-03-10 19:49:38 +04:00
|
|
|
pub route_id: String,
|
2022-02-24 16:37:58 +03:00
|
|
|
}
|
|
|
|
|
2022-03-10 19:49:38 +04:00
|
|
|
impl From<Result<String, ServiceError>> for RegisterRouteResult {
|
2022-02-24 16:37:58 +03:00
|
|
|
fn from(result: Result<String, ServiceError>) -> Self {
|
|
|
|
match result {
|
2022-03-10 19:49:38 +04:00
|
|
|
Ok(route_id) => Self {
|
2022-02-24 16:37:58 +03:00
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
2022-03-10 19:49:38 +04:00
|
|
|
route_id,
|
2022-02-24 16:37:58 +03:00
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
2022-03-10 19:49:38 +04:00
|
|
|
route_id: "".to_string(),
|
2022-02-24 16:37:58 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 18:32:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[marine]
|
2021-04-27 16:53:01 +03:00
|
|
|
#[derive(Debug)]
|
2021-05-11 18:32:37 +03:00
|
|
|
pub struct GetValuesResult {
|
2021-04-27 16:53:01 +03:00
|
|
|
pub success: bool,
|
2021-05-11 18:32:37 +03:00
|
|
|
pub error: String,
|
|
|
|
pub result: Vec<Record>,
|
2021-04-27 16:53:01 +03:00
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
impl From<Result<Vec<Record>, ServiceError>> for GetValuesResult {
|
|
|
|
fn from(result: Result<Vec<Record>, ServiceError>) -> Self {
|
2021-04-27 16:53:01 +03:00
|
|
|
match result {
|
|
|
|
Ok(result) => Self {
|
|
|
|
success: true,
|
2021-05-11 18:32:37 +03:00
|
|
|
error: "".to_string(),
|
2021-04-27 16:53:01 +03:00
|
|
|
result,
|
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
2021-05-11 18:32:37 +03:00
|
|
|
error: err.to_string(),
|
|
|
|
result: vec![],
|
2021-04-27 16:53:01 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-11 18:32:37 +03:00
|
|
|
#[marine]
|
2021-04-27 16:53:01 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct ClearExpiredResult {
|
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
2022-03-10 19:49:38 +04:00
|
|
|
pub count_routes: u64,
|
2021-05-13 19:04:11 +03:00
|
|
|
pub count_values: u64,
|
2021-04-27 16:53:01 +03:00
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
impl From<Result<(u64, u64), ServiceError>> for ClearExpiredResult {
|
|
|
|
fn from(result: Result<(u64, u64), ServiceError>) -> Self {
|
2021-04-27 16:53:01 +03:00
|
|
|
match result {
|
2022-03-10 19:49:38 +04:00
|
|
|
Ok((routes, values)) => Self {
|
2021-04-27 16:53:01 +03:00
|
|
|
success: true,
|
2022-03-10 19:49:38 +04:00
|
|
|
count_routes: routes,
|
2021-05-13 19:04:11 +03:00
|
|
|
count_values: values,
|
2021-04-27 16:53:01 +03:00
|
|
|
error: "".to_string(),
|
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
2022-03-10 19:49:38 +04:00
|
|
|
count_routes: 0,
|
2021-05-13 19:04:11 +03:00
|
|
|
count_values: 0,
|
2021-04-27 16:53:01 +03:00
|
|
|
error: err.to_string(),
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-11 18:32:37 +03:00
|
|
|
#[marine]
|
2021-04-27 16:53:01 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct GetStaleRecordsResult {
|
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
|
|
|
pub result: Vec<Record>,
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
impl From<Result<Vec<Record>, ServiceError>> for GetStaleRecordsResult {
|
|
|
|
fn from(result: Result<Vec<Record>, ServiceError>) -> Self {
|
2021-04-27 16:53:01 +03:00
|
|
|
match result {
|
|
|
|
Ok(result) => Self {
|
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
|
|
|
result,
|
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
|
|
|
result: vec![],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 18:32:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[marine]
|
2022-03-10 19:49:38 +04:00
|
|
|
pub struct GetRouteMetadataResult {
|
2021-05-11 18:32:37 +03:00
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
2022-03-10 19:49:38 +04:00
|
|
|
pub route: Route,
|
2021-05-11 18:32:37 +03:00
|
|
|
}
|
|
|
|
|
2022-03-10 19:49:38 +04:00
|
|
|
impl From<Result<Route, ServiceError>> for GetRouteMetadataResult {
|
|
|
|
fn from(result: Result<Route, ServiceError>) -> Self {
|
2021-05-11 18:32:37 +03:00
|
|
|
match result {
|
2022-03-10 19:49:38 +04:00
|
|
|
Ok(route) => Self {
|
2021-05-11 18:32:37 +03:00
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
2022-03-10 19:49:38 +04:00
|
|
|
route,
|
2021-05-11 18:32:37 +03:00
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
2022-03-10 19:49:38 +04:00
|
|
|
route: Route::default(),
|
2021-05-11 18:32:37 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-13 19:04:11 +03:00
|
|
|
|
|
|
|
#[marine]
|
|
|
|
pub struct RepublishValuesResult {
|
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
|
|
|
pub updated: u64,
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
impl From<Result<u64, ServiceError>> for RepublishValuesResult {
|
|
|
|
fn from(result: Result<u64, ServiceError>) -> Self {
|
2021-05-13 19:04:11 +03:00
|
|
|
match result {
|
|
|
|
Ok(count) => Self {
|
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
|
|
|
updated: count,
|
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
|
|
|
updated: 0,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-16 23:06:07 +03:00
|
|
|
|
2021-05-17 18:09:53 +03:00
|
|
|
#[marine]
|
|
|
|
pub struct EvictStaleItem {
|
2022-03-10 19:49:38 +04:00
|
|
|
pub route: Route,
|
2021-05-17 18:09:53 +03:00
|
|
|
pub records: Vec<Record>,
|
|
|
|
}
|
|
|
|
|
2021-05-17 15:35:57 +03:00
|
|
|
#[marine]
|
|
|
|
pub struct EvictStaleResult {
|
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
2021-05-17 18:09:53 +03:00
|
|
|
pub results: Vec<EvictStaleItem>,
|
|
|
|
}
|
|
|
|
|
2021-11-24 17:57:38 +03:00
|
|
|
impl From<Result<Vec<EvictStaleItem>, ServiceError>> for EvictStaleResult {
|
|
|
|
fn from(result: Result<Vec<EvictStaleItem>, ServiceError>) -> Self {
|
2021-05-17 18:09:53 +03:00
|
|
|
match result {
|
|
|
|
Ok(results) => Self {
|
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
|
|
|
results,
|
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
|
|
|
results: vec![],
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-05-17 15:35:57 +03:00
|
|
|
}
|
2021-05-26 23:58:46 +03:00
|
|
|
|
|
|
|
#[marine]
|
2022-02-24 16:37:58 +03:00
|
|
|
pub struct PutHostRecordResult {
|
2021-05-26 23:58:46 +03:00
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
2022-02-24 16:37:58 +03:00
|
|
|
pub value: Vec<Record>,
|
2021-05-26 23:58:46 +03:00
|
|
|
}
|
|
|
|
|
2022-02-24 16:37:58 +03:00
|
|
|
impl From<Result<Record, ServiceError>> for PutHostRecordResult {
|
|
|
|
fn from(result: Result<Record, ServiceError>) -> Self {
|
2021-05-26 23:58:46 +03:00
|
|
|
match result {
|
|
|
|
Ok(result) => Self {
|
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
2022-02-24 16:37:58 +03:00
|
|
|
value: vec![result],
|
2021-05-26 23:58:46 +03:00
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
2022-02-24 16:37:58 +03:00
|
|
|
value: vec![],
|
2021-05-26 23:58:46 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-06-08 14:29:15 +03:00
|
|
|
|
|
|
|
#[marine]
|
2022-02-24 16:37:58 +03:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct MergeResult {
|
2021-06-08 14:29:15 +03:00
|
|
|
pub success: bool,
|
|
|
|
pub error: String,
|
2022-02-24 16:37:58 +03:00
|
|
|
pub result: Vec<Record>,
|
2021-06-08 14:29:15 +03:00
|
|
|
}
|
|
|
|
|
2022-02-24 16:37:58 +03:00
|
|
|
impl From<Result<Vec<Record>, ServiceError>> for MergeResult {
|
|
|
|
fn from(result: Result<Vec<Record>, ServiceError>) -> Self {
|
2021-06-08 14:29:15 +03:00
|
|
|
match result {
|
|
|
|
Ok(result) => Self {
|
|
|
|
success: true,
|
|
|
|
error: "".to_string(),
|
2022-02-24 16:37:58 +03:00
|
|
|
result,
|
2021-06-08 14:29:15 +03:00
|
|
|
},
|
|
|
|
Err(err) => Self {
|
|
|
|
success: false,
|
|
|
|
error: err.to_string(),
|
2022-02-24 16:37:58 +03:00
|
|
|
result: vec![],
|
2021-06-08 14:29:15 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|