Skip to content

Commit ed9eedf

Browse files
committed
Completed structure change
1 parent 38ade6b commit ed9eedf

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::R
4545
} else {
4646
Some(model.application.verifiers_gh_handles.join(", ")) // Join verifiers in a string if exists
4747
};
48-
49-
let owner_repo_parts: Vec<&str> = model.application.allocation_bookkeeping.split('/').collect();
50-
let owner = parts[owner_repo_parts.len() - 2];
51-
let repo = parts[owner_repo_parts.len() - 1];
48+
let owner = model.owner.clone().unwrap_or_default().to_string();
49+
let repo = model.repo.clone().unwrap_or_default().to_string();
5250

5351
let allocator_model = match allocators_db::create_or_update_allocator(
54-
owner.to_string(),
55-
repo.to_string(),
52+
owner.clone(),
53+
repo.clone(),
5654
None,
5755
Some(model.pathway_addresses.msig),
5856
verifiers_gh_handles,
@@ -62,11 +60,11 @@ pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::R
6260
Err(e) => return Ok(HttpResponse::BadRequest().body(e.to_string())),
6361
};
6462

65-
match is_allocator_repo_created(&model.owner, &model.repo).await {
63+
match is_allocator_repo_created(&owner, &repo).await {
6664
Ok(true) => Ok(HttpResponse::Ok().json(allocator_model)),
6765
Ok(false) => {
6866
//Create allocator repo. If it fails, return http error
69-
match create_allocator_repo(&model.owner, &model.repo).await {
67+
match create_allocator_repo(&owner, &repo).await {
7068
Ok(files_list) => {
7169
log::info!("Allocator repo created successfully: {:?}", files_list);
7270
Ok(HttpResponse::Ok().json(allocator_model))

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@ use serde::{Serialize, Deserialize};
33
#[derive(Serialize, Deserialize, Debug)]
44
pub struct AllocatorModel {
55
pub application: Application,
6-
#[serde(rename = "multisig_threshold")]
76
pub multisig_threshold: Option<i32>,
8-
pub pathway_addresses: AllocatorModelPathwayAddresses
7+
pub pathway_addresses: AllocatorModelPathwayAddresses,
8+
pub owner: Option<String>,
9+
pub repo: Option<String>,
910
}
1011

1112
#[derive(Serialize, Deserialize, Debug)]
1213
pub struct AllocatorModelPathwayAddresses {
1314
pub msig: String,
15+
pub signer: Vec<String>,
1416
}
1517

1618
#[derive(Serialize, Deserialize, Debug)]

fplus-lib/src/core/allocator/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub async fn process_allocator_file(file_name: &str) -> Result<AllocatorModel, L
2929
let mut model = content_items_to_allocator_model(content_items).map_err(|e| LDNError::Load(e.to_string()))?;
3030

3131
// Get multisig threshold from the blockchain if multisig address is available
32-
if let Ok(blockchain_threshold) = get_multisig_threshold_for_actor(&model.multisig_address).await {
32+
if let Ok(blockchain_threshold) = get_multisig_threshold_for_actor(&model.pathway_addresses.msig).await {
3333
model.multisig_threshold = Some(blockchain_threshold as i32);
3434
} else {
3535
log::warn!("Blockchain multisig threshold not found, using default or provided value");
@@ -55,7 +55,16 @@ fn content_items_to_allocator_model(file: ContentItems) -> Result<AllocatorModel
5555
log::info!("Cleaned content: {:?}", cleaned_content);
5656

5757
match decode_allocator_model(&cleaned_content) {
58-
Some(model) => {
58+
Some(mut model) => {
59+
let owner_repo_parts: Vec<&str> = model.application.allocation_bookkeeping.split('/').collect();
60+
if owner_repo_parts.len() < 2 {
61+
log::error!("Failed to parse allocator model");
62+
return Err(LDNError::Load("Failed to parse allocator model".to_string()));
63+
}
64+
65+
model.owner = Some(owner_repo_parts[owner_repo_parts.len() - 2].to_string());
66+
model.repo = Some(owner_repo_parts[owner_repo_parts.len() - 1].to_string());
67+
5968
log::info!("Parsed allocator model successfully");
6069
Ok(model)
6170
}

0 commit comments

Comments
 (0)