Skip to content

Commit d27df1a

Browse files
authored
Merge pull request #160 from filecoin-project/feat/adjust-allocator-json
Feat/adjust allocator json
2 parents 6c441c2 + ed9eedf commit d27df1a

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,32 +37,34 @@ pub async fn create_from_json(file: web::Json<ChangedAllocator>) -> actix_web::R
3737

3838
match process_allocator_file(file_name).await {
3939
Ok(model) => {
40-
if model.multisig_address.is_empty() {
40+
if model.pathway_addresses.msig.is_empty() {
4141
return Ok(HttpResponse::BadRequest().body("Missing or invalid multisig_address"));
4242
}
4343
let verifiers_gh_handles = if model.application.verifiers_gh_handles.is_empty() {
4444
None
4545
} else {
4646
Some(model.application.verifiers_gh_handles.join(", ")) // Join verifiers in a string if exists
4747
};
48-
48+
let owner = model.owner.clone().unwrap_or_default().to_string();
49+
let repo = model.repo.clone().unwrap_or_default().to_string();
50+
4951
let allocator_model = match allocators_db::create_or_update_allocator(
50-
model.owner.clone(),
51-
model.repo.clone(),
52+
owner.clone(),
53+
repo.clone(),
5254
None,
53-
Some(model.multisig_address),
55+
Some(model.pathway_addresses.msig),
5456
verifiers_gh_handles,
5557
model.multisig_threshold
5658
).await {
5759
Ok(allocator_model) => allocator_model,
5860
Err(e) => return Ok(HttpResponse::BadRequest().body(e.to_string())),
5961
};
6062

61-
match is_allocator_repo_created(&model.owner, &model.repo).await {
63+
match is_allocator_repo_created(&owner, &repo).await {
6264
Ok(true) => Ok(HttpResponse::Ok().json(allocator_model)),
6365
Ok(false) => {
6466
//Create allocator repo. If it fails, return http error
65-
match create_allocator_repo(&model.owner, &model.repo).await {
67+
match create_allocator_repo(&owner, &repo).await {
6668
Ok(files_list) => {
6769
log::info!("Allocator repo created successfully: {:?}", files_list);
6870
Ok(HttpResponse::Ok().json(allocator_model))

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,24 @@ use serde::{Serialize, Deserialize};
22

33
#[derive(Serialize, Deserialize, Debug)]
44
pub struct AllocatorModel {
5-
#[serde(rename = "slug")]
6-
pub repo: String,
7-
#[serde(rename = "organization")]
8-
pub owner: String,
9-
#[serde(rename = "address")]
10-
pub multisig_address: String,
115
pub application: Application,
12-
#[serde(rename = "multisig_threshold")]
136
pub multisig_threshold: Option<i32>,
7+
pub pathway_addresses: AllocatorModelPathwayAddresses,
8+
pub owner: Option<String>,
9+
pub repo: Option<String>,
10+
}
11+
12+
#[derive(Serialize, Deserialize, Debug)]
13+
pub struct AllocatorModelPathwayAddresses {
14+
pub msig: String,
15+
pub signer: Vec<String>,
1416
}
1517

1618
#[derive(Serialize, Deserialize, Debug)]
1719
pub struct Application {
1820
#[serde(rename = "github_handles")]
19-
pub verifiers_gh_handles: Vec<String>
21+
pub verifiers_gh_handles: Vec<String>,
22+
pub allocation_bookkeeping: String,
2023
}
2124

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

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)