Skip to content

[FIL-780] Prepare allocator.tech for the new allocator JSON file #270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions fplus-database/src/database/allocators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ pub async fn get_allocator(
* @param verifiers_gh_handles: Option<String> - The GitHub handles of the verifiers
* @param address: Option<String> - Address of the Allocator
* @param tooling: Option<String> - Supported tooling
* @param data_types: Option<Vec<String>> - Supported data_types
* @param required_sps: Option<String> - Required number of SPs
* @param required_replicas: Option<String> - Required number of replicas
* @param registry_file_path: Option<String> - Path to JSON file specifying the allocator in registry repo
* @param ma_address: Option<String> - Metaallocator address
*
* # Returns
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation
Expand All @@ -67,11 +67,11 @@ pub async fn create_or_update_allocator(
allocation_amount_type: Option<String>,
address: Option<String>,
tooling: Option<String>,
data_types: Option<Vec<String>>,
required_sps: Option<String>,
required_replicas: Option<String>,
registry_file_path: Option<String>,
client_contract_address: Option<String>,
ma_address: Option<String>,
) -> Result<AllocatorModel, sea_orm::DbErr> {
let existing_allocator = get_allocator(&owner, &repo).await?;
if let Some(allocator_model) = existing_allocator {
Expand Down Expand Up @@ -109,8 +109,14 @@ pub async fn create_or_update_allocator(
allocator_active_model.tooling = Set(tooling);
}

if data_types.is_some() {
allocator_active_model.data_types = Set(data_types);
if let Some(ma_address) = ma_address {
if !ma_address.is_empty() {
allocator_active_model.ma_address = Set(Some(ma_address));
} else {
allocator_active_model.ma_address = Set(None);
}
} else {
allocator_active_model.ma_address = Set(None);
}

if required_sps.is_some() {
Expand Down Expand Up @@ -175,8 +181,12 @@ pub async fn create_or_update_allocator(
new_allocator.tooling = Set(tooling);
}

if data_types.is_some() {
new_allocator.data_types = Set(data_types);
if let Some(ma_address) = ma_address {
if !ma_address.is_empty() {
new_allocator.ma_address = Set(Some(ma_address));
} else {
new_allocator.ma_address = Set(None);
}
}

if required_sps.is_some() {
Expand Down
16 changes: 5 additions & 11 deletions fplus-database/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,11 @@ mod tests {
let amount_type = Some("Fixed".to_string());
let address = Some("0x1234567890".to_string());
let tooling = Some("common_ui, smart_contract_allocator".to_string());
let data_types = Some(vec![
"Public Open Dataset (Research/Non-Profit)".to_string(),
"Public Open Commercial/Enterprise".to_string(),
]);
let required_sps = Some("5+".to_string());
let required_replicas = Some("5+".to_string());
let registry_file_path = Some("Allocators/123.json".to_string());
let client_contract_address = Some("f1owcbryeqlq3vl7kydzax7r75sbtyvgpnny7fswy".to_string());

let ma_address = Some("f11234567890".to_string());
let result = database::allocators::create_or_update_allocator(
owner,
repo,
Expand All @@ -140,11 +136,11 @@ mod tests {
amount_type,
address,
tooling,
data_types,
required_sps,
required_replicas,
registry_file_path,
client_contract_address,
ma_address,
)
.await;
assert!(result.is_ok());
Expand Down Expand Up @@ -215,14 +211,12 @@ mod tests {
let amount_type = Some("Fixed".to_string());
let address = Some("0x1234567890".to_string());
let tooling = Some("common_ui, smart_contract_allocator".to_string());
let data_types = Some(vec![
"Public Open Dataset (Research/Non-Profit)".to_string(),
"Public Open Commercial/Enterprise".to_string(),
]);
let required_sps = Some("5+".to_string());
let required_replicas = Some("5+".to_string());
let registry_file_path = Some("Allocators/123.json".to_string());
let client_contract_address = Some("f1owcbryeqlq3vl7kydzax7r75sbtyvgpnny7fswy".to_string());
let ma_address = Some("f11234567890".to_string());

let result = database::allocators::create_or_update_allocator(
owner.clone(),
repo.clone(),
Expand All @@ -233,11 +227,11 @@ mod tests {
amount_type,
address,
tooling,
data_types,
required_sps,
required_replicas,
registry_file_path,
client_contract_address,
ma_address,
)
.await;

Expand Down
2 changes: 1 addition & 1 deletion fplus-database/src/models/allocators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub struct Model {
pub allocation_amount_type: Option<String>,
pub address: Option<String>,
pub tooling: Option<String>,
pub data_types: Option<Vec<String>>,
pub ma_address: Option<String>,
pub required_sps: Option<String>,
pub required_replicas: Option<String>,
pub registry_file_path: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion fplus-lib/src/core/allocator/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub struct AllocatorModel {
pub owner: Option<String>,
pub repo: Option<String>,
pub address: Option<String>,
pub ma_address: Option<String>,
pub client_contract_address: Option<String>,
}

Expand All @@ -24,7 +25,6 @@ pub struct Application {
pub allocation_bookkeeping: String,
pub allocation_amount: Option<AllocationAmount>,
pub tooling: Vec<String>,
pub data_types: Vec<String>,
pub required_sps: String,
pub required_replicas: String,
pub client_contract_address: Option<String>,
Expand Down
2 changes: 1 addition & 1 deletion fplus-lib/src/core/allocator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,11 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
.and_then(|a| a.amount_type.clone()),
model.address,
tooling,
Some(model.application.data_types),
Some(model.application.required_sps),
Some(model.application.required_replicas),
Some(file_name.to_owned()),
model.application.client_contract_address,
model.ma_address,
)
.await
.map_err(|e| LDNError::New(format!("Create or update allocator failed: {}", e)))?;
Expand Down
2 changes: 2 additions & 0 deletions manual-migrations/2025-04-22.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE IF EXISTS public.allocators
ADD COLUMN ma_address text;