This commit is contained in:
fmtabbara
2023-06-06 10:01:27 +01:00
parent d4ce1635a8
commit e509989ac3
4 changed files with 55 additions and 3 deletions
+12 -3
View File
@@ -1,4 +1,4 @@
use crate::service_providers::models::DirectoryService;
use crate::service_providers::models::{DirectoryService, HarbourMasterService, PagedResult};
use okapi::openapi3::OpenApi;
use reqwest::Error as ReqwestError;
use rocket::{serde::json::Json, Route};
@@ -7,15 +7,24 @@ use rocket_okapi::settings::OpenApiSettings;
static SERVICE_PROVIDER_WELLKNOWN_URL: &str =
"https://nymtech.net/.wellknown/connect/service-providers.json";
static HARBOUR_MASTER_URL: &str = "https://harbourmaster.nymtech.net/v1/services/?size=100";
pub fn service_providers_make_default_routes(settings: &OpenApiSettings) -> (Vec<Route>, OpenApi) {
openapi_get_routes_spec![settings: get_service_providers]
}
pub async fn get_services() -> Result<Vec<DirectoryService>, ReqwestError> {
reqwest::get(SERVICE_PROVIDER_WELLKNOWN_URL)
let services_res = reqwest::get(SERVICE_PROVIDER_WELLKNOWN_URL)
.await?
.json::<Vec<DirectoryService>>()
.await
.await;
let active_services_res = reqwest::get(HARBOUR_MASTER_URL)
.await?
.json::<PagedResult<HarbourMasterService>>()
.await?;
return services_res;
}
#[openapi(tag = "service_providers")]
@@ -8,9 +8,36 @@ pub struct DirectoryServiceProvider {
pub gateway: String,
}
pub struct DirectoryServiceProviderDetailed {
pub id: String,
pub description: String,
pub address: String,
pub gateway: String,
pub routing_score: f32,
pub service_type: String,
}
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
pub struct DirectoryService {
pub id: String,
pub description: String,
pub items: Vec<DirectoryServiceProvider>,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct HarbourMasterService {
pub service_provider_client_id: String,
pub gateway_identity_key: String,
pub ip_address: String,
pub last_successful_ping_utc: String,
pub last_updated_utc: String,
pub routing_score: f32,
}
#[derive(Debug, Clone, Deserialize, Serialize)]
pub struct PagedResult<T> {
pub page: u32,
pub size: u32,
pub total: i32,
pub items: Vec<T>,
}
@@ -10,6 +10,18 @@ const columns = [
headerName: 'Client ID',
field: 'address',
disableColumnMenu: true,
flex: 2,
},
{
headerName: 'Type',
field: 'type',
disableColumnMenu: true,
flex: 1,
},
{
headerName: 'Routing score',
field: 'routingScore',
disableColumnMenu: true,
flex: 1,
},
];
+4
View File
@@ -241,11 +241,15 @@ export type MixNodeEconomicDynamicsStatsResponse = {
export type Environment = 'mainnet' | 'sandbox' | 'qa';
export type ServiceProviderType = 'Network Requester';
export type DirectoryServiceProvider = {
id: string;
description: string;
address: string;
gateway: string;
routingScore: number;
serviceType: ServiceProviderType;
};
export type DirectoryService = {