From e18fb4fb157d42b6b6731579b2d8c483149d2218 Mon Sep 17 00:00:00 2001 From: kokal33 Date: Fri, 1 Dec 2023 18:11:06 +0100 Subject: [PATCH 1/3] init rkh working notaries doesnt --- fplus-http-server/src/main.rs | 2 ++ fplus-http-server/src/router/mod.rs | 1 + fplus-http-server/src/router/notary.rs | 18 ++++++++++++------ fplus-http-server/src/router/rkh.rs | 16 ++++++++++++---- fplus-lib/src/core/mod.rs | 10 ++++++---- 5 files changed, 33 insertions(+), 14 deletions(-) diff --git a/fplus-http-server/src/main.rs b/fplus-http-server/src/main.rs index 5abb1989..9ccb487a 100644 --- a/fplus-http-server/src/main.rs +++ b/fplus-http-server/src/main.rs @@ -38,6 +38,8 @@ async fn main() -> std::io::Result<()> { .service(router::application::validate_application_approval) .service(router::blockchain::address_allowance) .service(router::blockchain::verified_clients) + .service(router::notary::notaries) + .service(router::rkh::rkhs) }) .bind(("0.0.0.0", 8080))? .run() diff --git a/fplus-http-server/src/router/mod.rs b/fplus-http-server/src/router/mod.rs index 4fd6b492..331db0ff 100644 --- a/fplus-http-server/src/router/mod.rs +++ b/fplus-http-server/src/router/mod.rs @@ -3,6 +3,7 @@ use actix_web::{get, HttpResponse, Responder}; pub mod application; pub mod blockchain; pub mod rkh; +pub mod notary; /// Return server health status #[get("/health")] diff --git a/fplus-http-server/src/router/notary.rs b/fplus-http-server/src/router/notary.rs index 0abf787a..28e32c3c 100644 --- a/fplus-http-server/src/router/notary.rs +++ b/fplus-http-server/src/router/notary.rs @@ -1,10 +1,16 @@ -use actix_web::{get, http::header::ContentType, post, web, HttpResponse}; -use mongodb::Client; -use std::sync::Mutex; +use actix_web::{get, post, HttpResponse, Responder}; +use fplus_lib::core::LDNApplication; -#[get("/notary")] -pub async fn get() -> HttpResponse { - HttpResponse::InternalServerError().finish() +#[get("/notaries")] +pub async fn notaries() -> actix_web::Result { + match LDNApplication::fetch_notaries().await { + Ok(notaries) => { + Ok(HttpResponse::Ok().json(notaries)) + } + Err(e) => { + Ok(HttpResponse::InternalServerError().body(e.to_string())) + } + } } #[post("/notary")] diff --git a/fplus-http-server/src/router/rkh.rs b/fplus-http-server/src/router/rkh.rs index 24c90f78..eb7c441b 100644 --- a/fplus-http-server/src/router/rkh.rs +++ b/fplus-http-server/src/router/rkh.rs @@ -1,6 +1,14 @@ -use actix_web::{get, HttpResponse}; +use actix_web::{get, HttpResponse, Responder}; +use fplus_lib::core::LDNApplication; -#[get("/rkh")] -pub async fn get() -> HttpResponse { - HttpResponse::InternalServerError().finish() +#[get("/rkhs")] +pub async fn rkhs() -> actix_web::Result { + match LDNApplication::fetch_rkh().await { + Ok(notaries) => { + Ok(HttpResponse::Ok().json(notaries)) + } + Err(e) => { + Ok(HttpResponse::InternalServerError().body(e.to_string())) + } + } } diff --git a/fplus-lib/src/core/mod.rs b/fplus-lib/src/core/mod.rs index f9780cca..6d5ceb85 100644 --- a/fplus-lib/src/core/mod.rs +++ b/fplus-lib/src/core/mod.rs @@ -519,7 +519,7 @@ impl LDNApplication { } } - async fn fetch_noatries() -> Result { + pub async fn fetch_notaries() -> Result { let gh = GithubWrapper::new(); let notaries = gh .get_file("data/notaries.json", "main") @@ -539,7 +539,7 @@ impl LDNApplication { } } - async fn fetch_rkh() -> Result { + pub async fn fetch_rkh() -> Result { let gh = GithubWrapper::new(); let rkh = gh .get_file("data/rkh.json", "main") @@ -860,7 +860,7 @@ impl LDNApplication { } let signer = signers.0.get(1).unwrap(); let signer_address = signer.signing_address.clone(); - let valid_notaries = Self::fetch_noatries().await?; + let valid_notaries = Self::fetch_notaries().await?; if valid_notaries.is_valid(&signer_address) { dbg!("Valid notary"); return Ok(true); @@ -903,7 +903,7 @@ impl LDNApplication { } let signer = signers.0.get(0).unwrap(); let signer_address = signer.signing_address.clone(); - let valid_notaries = Self::fetch_noatries().await?; + let valid_notaries = Self::fetch_notaries().await?; if valid_notaries.is_valid(&signer_address) { dbg!("Valid notary"); return Ok(true); @@ -1073,6 +1073,8 @@ impl LDNApplication { .unwrap(); Ok(true) } + + } #[derive(Serialize, Deserialize, Debug)] From 657ba8ed8ede68bf0863848faed56f7b87e897df Mon Sep 17 00:00:00 2001 From: kokal33 Date: Mon, 4 Dec 2023 11:40:24 +0100 Subject: [PATCH 2/3] finished --- fplus-http-server/src/main.rs | 1 + fplus-http-server/src/router/notary.rs | 15 ++++++++- fplus-http-server/src/router/rkh.rs | 2 ++ fplus-lib/src/core/application/file.rs | 44 +++++++++++++++++++++++--- fplus-lib/src/core/mod.rs | 16 ++++++++-- 5 files changed, 71 insertions(+), 7 deletions(-) diff --git a/fplus-http-server/src/main.rs b/fplus-http-server/src/main.rs index 9ccb487a..30162cbb 100644 --- a/fplus-http-server/src/main.rs +++ b/fplus-http-server/src/main.rs @@ -39,6 +39,7 @@ async fn main() -> std::io::Result<()> { .service(router::blockchain::address_allowance) .service(router::blockchain::verified_clients) .service(router::notary::notaries) + .service(router::notary::ldn_actors) .service(router::rkh::rkhs) }) .bind(("0.0.0.0", 8080))? diff --git a/fplus-http-server/src/router/notary.rs b/fplus-http-server/src/router/notary.rs index 28e32c3c..74ac7216 100644 --- a/fplus-http-server/src/router/notary.rs +++ b/fplus-http-server/src/router/notary.rs @@ -1,5 +1,5 @@ use actix_web::{get, post, HttpResponse, Responder}; -use fplus_lib::core::LDNApplication; +use fplus_lib::core::{LDNApplication, application::file::LDNActorsResponse}; #[get("/notaries")] pub async fn notaries() -> actix_web::Result { @@ -13,6 +13,19 @@ pub async fn notaries() -> actix_web::Result { } } +#[get("/ldn-actors")] +pub async fn ldn_actors() -> actix_web::Result { + match LDNApplication::fetch_rkh_and_notary_gh_users().await { + Ok((governance_gh_handles, notary_gh_handles)) => { + let response = LDNActorsResponse { governance_gh_handles, notary_gh_handles }; + Ok(HttpResponse::Ok().json(response)) + } + Err(e) => { + Ok(HttpResponse::InternalServerError().body(e.to_string())) + } + } +} + #[post("/notary")] pub async fn post() -> HttpResponse { HttpResponse::InternalServerError().finish() diff --git a/fplus-http-server/src/router/rkh.rs b/fplus-http-server/src/router/rkh.rs index eb7c441b..7e19f4a1 100644 --- a/fplus-http-server/src/router/rkh.rs +++ b/fplus-http-server/src/router/rkh.rs @@ -12,3 +12,5 @@ pub async fn rkhs() -> actix_web::Result { } } } + + diff --git a/fplus-lib/src/core/application/file.rs b/fplus-lib/src/core/application/file.rs index 3041eac1..447ee4d8 100644 --- a/fplus-lib/src/core/application/file.rs +++ b/fplus-lib/src/core/application/file.rs @@ -339,20 +339,50 @@ pub struct AllocationRequest { pub allocation_amount: String, } +#[derive(serde::Serialize, serde::Deserialize, Debug, Clone)] +pub struct NotaryFile { + pub id: u32, + pub organization: String, + pub name: String, + pub election_round: String, + pub status: String, + pub use_case: String, + pub location: String, + pub notary_application_link: String, + pub website: String, + pub email: Vec, + pub fil_slack_id: String, + pub github_user: Vec, + pub ldn_config: NotaryConfig, + pub direct_config: NotaryConfig, + pub previous_config: PreviousConfig, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct NotaryConfig { + active_signer: bool, + signing_address: String, +} + +#[derive(Serialize, Deserialize, Debug, Clone)] +pub struct PreviousConfig { + signing_address: String, +} + #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ValidNotaryList { - notaries: Vec, + pub notaries: Vec, } impl ValidNotaryList { - pub fn is_valid(&self, notary: &str) -> bool { - self.notaries.contains(¬ary.to_string()) + pub fn is_valid(&self, notary_name: &str) -> bool { + self.notaries.iter().any(|notary| notary.name == notary_name) } } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ValidRKHList { - rkh: Vec, + pub rkh: Vec, } impl ValidRKHList { @@ -360,3 +390,9 @@ impl ValidRKHList { self.rkh.contains(&rkh.to_string()) } } + +#[derive(Serialize)] +pub struct LDNActorsResponse { + pub governance_gh_handles: Vec, + pub notary_gh_handles: Vec, +} diff --git a/fplus-lib/src/core/mod.rs b/fplus-lib/src/core/mod.rs index 6d5ceb85..3ed9600a 100644 --- a/fplus-lib/src/core/mod.rs +++ b/fplus-lib/src/core/mod.rs @@ -1073,8 +1073,20 @@ impl LDNApplication { .unwrap(); Ok(true) } - - + + pub async fn fetch_rkh_and_notary_gh_users() -> Result<(Vec, Vec), LDNError> { + let rkh_list = Self::fetch_rkh().await.map_err(|e| LDNError::Load(format!("Failed to retrieve rkh: {}", e)))?; + + let notary_list = Self::fetch_notaries().await.map_err(|e| LDNError::Load(format!("Failed to retrieve notaries: {}", e)))?; + + let notary_gh_names = notary_list.notaries.into_iter() + .flat_map(|notary| notary.github_user) + .filter(|username| !username.is_empty()) + .collect(); + + Ok((rkh_list.rkh, notary_gh_names)) + } + } #[derive(Serialize, Deserialize, Debug)] From b711d2fa540ec713937f422d8970cd826e0e17ef Mon Sep 17 00:00:00 2001 From: kokal33 Date: Mon, 4 Dec 2023 11:48:15 +0100 Subject: [PATCH 3/3] pub notaries for return --- fplus-lib/src/core/application/file.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fplus-lib/src/core/application/file.rs b/fplus-lib/src/core/application/file.rs index 41b040f7..217ff23c 100644 --- a/fplus-lib/src/core/application/file.rs +++ b/fplus-lib/src/core/application/file.rs @@ -365,7 +365,7 @@ pub struct ValidNotary { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct ValidNotaryList { - notaries: Vec, + pub notaries: Vec, } impl ValidNotaryList {