Skip to content

Commit 43dd136

Browse files
authored
Prepare allocator.tech fo the new allocator JSON file (#270)
1 parent 1377249 commit 43dd136

File tree

6 files changed

+26
-20
lines changed

6 files changed

+26
-20
lines changed

fplus-database/src/database/allocators.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ pub async fn get_allocator(
4848
* @param verifiers_gh_handles: Option<String> - The GitHub handles of the verifiers
4949
* @param address: Option<String> - Address of the Allocator
5050
* @param tooling: Option<String> - Supported tooling
51-
* @param data_types: Option<Vec<String>> - Supported data_types
5251
* @param required_sps: Option<String> - Required number of SPs
5352
* @param required_replicas: Option<String> - Required number of replicas
5453
* @param registry_file_path: Option<String> - Path to JSON file specifying the allocator in registry repo
54+
* @param ma_address: Option<String> - Metaallocator address
5555
*
5656
* # Returns
5757
* @return Result<AllocatorModel, sea_orm::DbErr> - The result of the operation
@@ -67,11 +67,11 @@ pub async fn create_or_update_allocator(
6767
allocation_amount_type: Option<String>,
6868
address: Option<String>,
6969
tooling: Option<String>,
70-
data_types: Option<Vec<String>>,
7170
required_sps: Option<String>,
7271
required_replicas: Option<String>,
7372
registry_file_path: Option<String>,
7473
client_contract_address: Option<String>,
74+
ma_address: Option<String>,
7575
) -> Result<AllocatorModel, sea_orm::DbErr> {
7676
let existing_allocator = get_allocator(&owner, &repo).await?;
7777
if let Some(allocator_model) = existing_allocator {
@@ -109,8 +109,14 @@ pub async fn create_or_update_allocator(
109109
allocator_active_model.tooling = Set(tooling);
110110
}
111111

112-
if data_types.is_some() {
113-
allocator_active_model.data_types = Set(data_types);
112+
if let Some(ma_address) = ma_address {
113+
if !ma_address.is_empty() {
114+
allocator_active_model.ma_address = Set(Some(ma_address));
115+
} else {
116+
allocator_active_model.ma_address = Set(None);
117+
}
118+
} else {
119+
allocator_active_model.ma_address = Set(None);
114120
}
115121

116122
if required_sps.is_some() {
@@ -175,8 +181,12 @@ pub async fn create_or_update_allocator(
175181
new_allocator.tooling = Set(tooling);
176182
}
177183

178-
if data_types.is_some() {
179-
new_allocator.data_types = Set(data_types);
184+
if let Some(ma_address) = ma_address {
185+
if !ma_address.is_empty() {
186+
new_allocator.ma_address = Set(Some(ma_address));
187+
} else {
188+
new_allocator.ma_address = Set(None);
189+
}
180190
}
181191

182192
if required_sps.is_some() {

fplus-database/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,11 @@ mod tests {
121121
let amount_type = Some("Fixed".to_string());
122122
let address = Some("0x1234567890".to_string());
123123
let tooling = Some("common_ui, smart_contract_allocator".to_string());
124-
let data_types = Some(vec![
125-
"Public Open Dataset (Research/Non-Profit)".to_string(),
126-
"Public Open Commercial/Enterprise".to_string(),
127-
]);
128124
let required_sps = Some("5+".to_string());
129125
let required_replicas = Some("5+".to_string());
130126
let registry_file_path = Some("Allocators/123.json".to_string());
131127
let client_contract_address = Some("f1owcbryeqlq3vl7kydzax7r75sbtyvgpnny7fswy".to_string());
132-
128+
let ma_address = Some("f11234567890".to_string());
133129
let result = database::allocators::create_or_update_allocator(
134130
owner,
135131
repo,
@@ -140,11 +136,11 @@ mod tests {
140136
amount_type,
141137
address,
142138
tooling,
143-
data_types,
144139
required_sps,
145140
required_replicas,
146141
registry_file_path,
147142
client_contract_address,
143+
ma_address,
148144
)
149145
.await;
150146
assert!(result.is_ok());
@@ -215,14 +211,12 @@ mod tests {
215211
let amount_type = Some("Fixed".to_string());
216212
let address = Some("0x1234567890".to_string());
217213
let tooling = Some("common_ui, smart_contract_allocator".to_string());
218-
let data_types = Some(vec![
219-
"Public Open Dataset (Research/Non-Profit)".to_string(),
220-
"Public Open Commercial/Enterprise".to_string(),
221-
]);
222214
let required_sps = Some("5+".to_string());
223215
let required_replicas = Some("5+".to_string());
224216
let registry_file_path = Some("Allocators/123.json".to_string());
225217
let client_contract_address = Some("f1owcbryeqlq3vl7kydzax7r75sbtyvgpnny7fswy".to_string());
218+
let ma_address = Some("f11234567890".to_string());
219+
226220
let result = database::allocators::create_or_update_allocator(
227221
owner.clone(),
228222
repo.clone(),
@@ -233,11 +227,11 @@ mod tests {
233227
amount_type,
234228
address,
235229
tooling,
236-
data_types,
237230
required_sps,
238231
required_replicas,
239232
registry_file_path,
240233
client_contract_address,
234+
ma_address,
241235
)
242236
.await;
243237

fplus-database/src/models/allocators.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub struct Model {
1818
pub allocation_amount_type: Option<String>,
1919
pub address: Option<String>,
2020
pub tooling: Option<String>,
21-
pub data_types: Option<Vec<String>>,
21+
pub ma_address: Option<String>,
2222
pub required_sps: Option<String>,
2323
pub required_replicas: Option<String>,
2424
pub registry_file_path: Option<String>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub struct AllocatorModel {
88
pub owner: Option<String>,
99
pub repo: Option<String>,
1010
pub address: Option<String>,
11+
pub ma_address: Option<String>,
1112
pub client_contract_address: Option<String>,
1213
}
1314

@@ -24,7 +25,6 @@ pub struct Application {
2425
pub allocation_bookkeeping: String,
2526
pub allocation_amount: Option<AllocationAmount>,
2627
pub tooling: Vec<String>,
27-
pub data_types: Vec<String>,
2828
pub required_sps: String,
2929
pub required_replicas: String,
3030
pub client_contract_address: Option<String>,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,11 @@ pub async fn create_allocator_from_file(files_changed: Vec<String>) -> Result<()
635635
.and_then(|a| a.amount_type.clone()),
636636
model.address,
637637
tooling,
638-
Some(model.application.data_types),
639638
Some(model.application.required_sps),
640639
Some(model.application.required_replicas),
641640
Some(file_name.to_owned()),
642641
model.application.client_contract_address,
642+
model.ma_address,
643643
)
644644
.await
645645
.map_err(|e| LDNError::New(format!("Create or update allocator failed: {}", e)))?;

manual-migrations/2025-04-22.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE IF EXISTS public.allocators
2+
ADD COLUMN ma_address text;

0 commit comments

Comments
 (0)