Skip to content

Commit

Permalink
Merge pull request #92 from filecoin-project/get-rkh-notaries
Browse files Browse the repository at this point in the history
Get rkh notaries
  • Loading branch information
clriesco authored Dec 4, 2023
2 parents d24268f + b711d2f commit c5a59e6
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 16 deletions.
3 changes: 3 additions & 0 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ 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::notary::ldn_actors)
.service(router::rkh::rkhs)
})
.bind(("0.0.0.0", 8080))?
.run()
Expand Down
1 change: 1 addition & 0 deletions fplus-http-server/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
31 changes: 25 additions & 6 deletions fplus-http-server/src/router/notary.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,29 @@
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, application::file::LDNActorsResponse};

#[get("/notary")]
pub async fn get() -> HttpResponse {
HttpResponse::InternalServerError().finish()
#[get("/notaries")]
pub async fn notaries() -> actix_web::Result<impl Responder> {
match LDNApplication::fetch_notaries().await {
Ok(notaries) => {
Ok(HttpResponse::Ok().json(notaries))
}
Err(e) => {
Ok(HttpResponse::InternalServerError().body(e.to_string()))
}
}
}

#[get("/ldn-actors")]
pub async fn ldn_actors() -> actix_web::Result<impl Responder> {
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")]
Expand Down
18 changes: 14 additions & 4 deletions fplus-http-server/src/router/rkh.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
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<impl Responder> {
match LDNApplication::fetch_rkh().await {
Ok(notaries) => {
Ok(HttpResponse::Ok().json(notaries))
}
Err(e) => {
Ok(HttpResponse::InternalServerError().body(e.to_string()))
}
}
}


10 changes: 8 additions & 2 deletions fplus-lib/src/core/application/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ pub struct ValidNotary {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidNotaryList {
notaries: Vec<ValidNotary>,
pub notaries: Vec<ValidNotary>,
}

impl ValidNotaryList {
Expand All @@ -380,11 +380,17 @@ impl ValidNotaryList {

#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ValidRKHList {
rkh: Vec<String>,
pub rkh: Vec<String>,
}

impl ValidRKHList {
pub fn is_valid(&self, rkh: &str) -> bool {
self.rkh.contains(&rkh.to_string())
}
}

#[derive(Serialize)]
pub struct LDNActorsResponse {
pub governance_gh_handles: Vec<String>,
pub notary_gh_handles: Vec<String>,
}
22 changes: 18 additions & 4 deletions fplus-lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl LDNApplication {
}
}

async fn fetch_noatries() -> Result<ValidNotaryList, LDNError> {
pub async fn fetch_notaries() -> Result<ValidNotaryList, LDNError> {
let gh = GithubWrapper::new();
let notaries = gh
.get_file("data/notaries.json", "main")
Expand All @@ -538,7 +538,7 @@ impl LDNApplication {
}
}

async fn fetch_rkh() -> Result<ValidRKHList, LDNError> {
pub async fn fetch_rkh() -> Result<ValidRKHList, LDNError> {
let gh = GithubWrapper::new();
let rkh = gh
.get_file("data/rkh.json", "main")
Expand Down Expand Up @@ -875,7 +875,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);
Expand Down Expand Up @@ -918,7 +918,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);
Expand Down Expand Up @@ -1088,6 +1088,20 @@ impl LDNApplication {
.unwrap();
Ok(true)
}

pub async fn fetch_rkh_and_notary_gh_users() -> Result<(Vec<String>, Vec<String>), 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)]
Expand Down

0 comments on commit c5a59e6

Please sign in to comment.