Skip to content

Commit a20afeb

Browse files
committed
Changed to verifiers
Some notary and gov team cleanup
1 parent 0cb7fb3 commit a20afeb

File tree

8 files changed

+26
-159
lines changed

8 files changed

+26
-159
lines changed

fplus-http-server/src/main.rs

-2
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ async fn main() -> std::io::Result<()> {
4242
.service(router::application::validate_application_approval)
4343
.service(router::blockchain::address_allowance)
4444
.service(router::blockchain::verified_clients)
45-
.service(router::notary::notaries)
46-
.service(router::notary::ldn_actors)
4745
.service(router::govteam::gov_team_members)
4846
.service(router::allocator::allocators)
4947
})

fplus-http-server/src/router/govteam.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use fplus_lib::core::LDNApplication;
33

44
#[get("/gov-team-members")]
55
pub async fn gov_team_members() -> actix_web::Result<impl Responder> {
6-
match LDNApplication::fetch_gov().await {
6+
match LDNApplication::fetch_verifiers().await {
77
Ok(notaries) => {
88
Ok(HttpResponse::Ok().json(notaries))
99
}

fplus-http-server/src/router/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use actix_web::{get, HttpResponse, Responder};
33
pub mod application;
44
pub mod blockchain;
55
pub mod govteam;
6-
pub mod notary;
76
pub mod allocator;
87

98
/// Return server health status

fplus-http-server/src/router/notary.rs

-32
This file was deleted.

fplus-lib/Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,5 @@ tokio = { version = "1.32.0", features = ["rt", "macros"] }
2929
uuidv4 = "1.0.0"
3030
rayon = "1.8.0"
3131
log = "0.4.20"
32+
fplus-database = { path = "../fplus-database", version = "1.0.19"}
33+

fplus-lib/src/base64.rs

+1-21
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::io::Cursor;
22

33
use base64;
44

5-
use crate::core::application::file::{ApplicationFile, ValidNotaryList, ValidGovTeamList};
5+
use crate::core::application::file::{ApplicationFile, ValidVerifierList};
66

77
pub fn decode(i: &str) -> Option<ApplicationFile> {
88
let mut binding = Cursor::new(i);
@@ -13,23 +13,3 @@ pub fn decode(i: &str) -> Option<ApplicationFile> {
1313
};
1414
Some(app_file)
1515
}
16-
17-
pub fn decode_notary(i: &str) -> Option<ValidNotaryList> {
18-
let mut binding = Cursor::new(i);
19-
let decoder = base64::read::DecoderReader::new(&mut binding, base64::STANDARD);
20-
let notaries: ValidNotaryList = match serde_json::from_reader(decoder) {
21-
Ok(f) => f,
22-
Err(_) => return None,
23-
};
24-
Some(notaries)
25-
}
26-
27-
pub fn decode_gov_team(i: &str) -> Option<ValidGovTeamList> {
28-
let mut binding = Cursor::new(i);
29-
let decoder = base64::read::DecoderReader::new(&mut binding, base64::STANDARD);
30-
let gov_team: ValidGovTeamList = match serde_json::from_reader(decoder) {
31-
Ok(f) => f,
32-
Err(_) => return None,
33-
};
34-
Some(gov_team)
35-
}

fplus-lib/src/core/application/file.rs

+2-41
Original file line numberDiff line numberDiff line change
@@ -345,51 +345,12 @@ pub struct AllocationRequest {
345345
pub allocation_amount: String,
346346
}
347347

348-
#[derive(Serialize, Deserialize, Clone, Debug)]
349-
pub struct NotaryConfig {
350-
pub active_signer: bool,
351-
pub signing_address: String,
352-
}
353-
354-
#[derive(Serialize, Deserialize, Debug, Clone)]
355-
pub struct ValidNotary {
356-
pub id: i32,
357-
pub organization: String,
358-
pub name: String,
359-
pub election_round: String,
360-
pub status: String,
361-
pub use_case: String,
362-
pub location: String,
363-
pub notary_application_link: String,
364-
pub website: String,
365-
pub email: Vec<String>,
366-
pub fil_slack_id: String,
367-
pub github_user: Vec<String>,
368-
pub ldn_config: NotaryConfig,
369-
pub direct_config: NotaryConfig,
370-
}
371-
372-
#[derive(Serialize, Deserialize, Debug, Clone)]
373-
pub struct ValidNotaryList {
374-
pub notaries: Vec<ValidNotary>,
375-
}
376-
377-
impl ValidNotaryList {
378-
pub fn is_valid(&self, notary: &str) -> bool {
379-
self.notaries
380-
.iter()
381-
.filter(|n| n.ldn_config.signing_address == notary)
382-
.count()
383-
> 0
384-
}
385-
}
386-
387348
#[derive(Serialize, Deserialize, Debug, Clone)]
388-
pub struct ValidGovTeamList {
349+
pub struct ValidVerifierList {
389350
pub gov_team: Vec<String>,
390351
}
391352

392-
impl ValidGovTeamList {
353+
impl ValidVerifierList {
393354
pub fn is_valid(&self, member: &str) -> bool {
394355
self.gov_team.contains(&member.to_string())
395356
}

fplus-lib/src/core/mod.rs

+20-61
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ use crate::{
2020

2121
use self::application::file::{
2222
AllocationRequest, AllocationRequestType, AppState, ApplicationFile, NotaryInput,
23-
ValidNotaryList, ValidGovTeamList,
23+
ValidVerifierList,
2424
};
2525
use rayon::prelude::*;
2626
use crate::core::application::file::Allocation;
27-
27+
use fplus_database::database;
2828
pub mod application;
2929

3030
#[derive(Deserialize)]
@@ -518,43 +518,21 @@ impl LDNApplication {
518518
}
519519
}
520520

521-
pub async fn fetch_notaries() -> Result<ValidNotaryList, LDNError> {
522-
let gh = GithubWrapper::new();
523-
let notaries = gh
524-
.get_file("data/notaries.json", "main")
525-
.await
526-
.map_err(|e| LDNError::Load(format!("Failed to retrieve notaries /// {}", e)))?;
527-
528-
let notaries = &notaries.items[0]
529-
.content
530-
.clone()
531-
.and_then(|f| base64::decode_notary(&f.replace("\n", "")))
532-
.and_then(|f| Some(f));
533-
if let Some(notaries) = notaries {
534-
return Ok(notaries.clone());
535-
} else {
536-
return Err(LDNError::Load(format!("Failed to retrieve notaries ///")));
521+
pub async fn fetch_verifiers() -> Result<ValidVerifierList, LDNError> {
522+
let allocators = database::get_allocators().await.map_err(|e| LDNError::Load(format!("Failed to retrieve allocators /// {}", e)))?;
523+
524+
let mut gov_team_handles = Vec::new();
525+
for allocator in allocators {
526+
if let Some(handles) = allocator.verifiers_gh_handles {
527+
gov_team_handles.extend(handles.split(',').map(String::from));
528+
}
537529
}
538-
}
539-
540-
pub async fn fetch_gov() -> Result<ValidGovTeamList, LDNError> {
541-
let gh = GithubWrapper::new();
542-
let gov_team = gh
543-
.get_file("data/govteam.json", "main")
544-
.await
545-
.map_err(|e| LDNError::Load(format!("Failed to retrieve gov team /// {}", e)))?;
546-
547-
let gov_team = &gov_team.items[0]
548-
.content
549-
.clone()
550-
.and_then(|f| base64::decode_gov_team(&f.replace("\n", "")))
551-
.and_then(|f| Some(f));
552-
553-
if let Some(gov_team) = gov_team {
554-
return Ok(gov_team.clone());
555-
} else {
556-
return Err(LDNError::Load(format!("Failed to retrieve gov team ///")));
530+
531+
if gov_team_handles.is_empty() {
532+
return Err(LDNError::Load("No governance team found".into()));
557533
}
534+
535+
Ok(ValidVerifierList { gov_team: gov_team_handles })
558536
}
559537

560538
async fn single_merged(application_id: String) -> Result<(Content, ApplicationFile), LDNError> {
@@ -802,7 +780,7 @@ impl LDNApplication {
802780
let validated_at = application_file.lifecycle.validated_at.clone();
803781
let app_state = application_file.lifecycle.get_state();
804782
let active_request_id = application_file.lifecycle.active_request.clone();
805-
let valid_gov_team = Self::fetch_gov().await?;
783+
let valid_gov_team = Self::fetch_verifiers().await?;
806784
let bot_user = get_env_var_or_default("BOT_USER", "filplus-github-bot-read-write[bot]");
807785

808786
let res: bool = match app_state {
@@ -970,8 +948,8 @@ impl LDNApplication {
970948
}
971949
let signer = signers.0.get(1).unwrap();
972950
let signer_address = signer.signing_address.clone();
973-
let valid_notaries = Self::fetch_notaries().await?;
974-
if valid_notaries.is_valid(&signer_address) {
951+
let valid_verifiers = Self::fetch_verifiers().await?;
952+
if valid_verifiers.is_valid(&signer_address) {
975953
log::info!("- Validated!");
976954
Self::issue_datacap_request_signature(application_file.clone(), "approved".to_string()).await?;
977955
Self::update_issue_labels(application_file.issue_number.clone(), &[AppState::Granted.as_str()]).await?;
@@ -1021,8 +999,8 @@ impl LDNApplication {
1021999
}
10221000
let signer = signers.0.get(0).unwrap();
10231001
let signer_address = signer.signing_address.clone();
1024-
let valid_notaries = Self::fetch_notaries().await?;
1025-
if valid_notaries.is_valid(&signer_address) {
1002+
let valid_verifiers = Self::fetch_verifiers().await?;
1003+
if valid_verifiers.is_valid(&signer_address) {
10261004
Self::issue_start_sign_dc(application_file.issue_number.clone()).await?;
10271005
Self::issue_datacap_request_signature(application_file.clone(), "proposed".to_string()).await?;
10281006
Self::update_issue_labels(application_file.issue_number.clone(), &[AppState::StartSignDatacap.as_str()]).await?;
@@ -1298,25 +1276,6 @@ Your Datacap Allocation Request has been {} by the Notary
12981276
Ok(true)
12991277
}
13001278

1301-
pub async fn fetch_gov_and_notary_gh_users() -> Result<(Vec<String>, Vec<String>), LDNError> {
1302-
let gov_team_list = Self::fetch_gov()
1303-
.await
1304-
.map_err(|e| LDNError::Load(format!("Failed to retrieve gov team: {}", e)))?;
1305-
1306-
let notary_list = Self::fetch_notaries()
1307-
.await
1308-
.map_err(|e| LDNError::Load(format!("Failed to retrieve notaries: {}", e)))?;
1309-
1310-
let notary_gh_names = notary_list
1311-
.notaries
1312-
.into_iter()
1313-
.flat_map(|notary| notary.github_user)
1314-
.filter(|username| !username.is_empty())
1315-
.collect();
1316-
1317-
Ok((gov_team_list.gov_team, notary_gh_names))
1318-
}
1319-
13201279
async fn add_error_label(issue_number: String, comment: String) -> Result<(), LDNError> {
13211280
let gh = GithubWrapper::new();
13221281
let num: u64 = issue_number.parse().expect("Not a valid integer");

0 commit comments

Comments
 (0)