diff --git a/fplus-database/src/database/applications.rs b/fplus-database/src/database/applications.rs index c92a1f2..0c53871 100644 --- a/fplus-database/src/database/applications.rs +++ b/fplus-database/src/database/applications.rs @@ -29,7 +29,8 @@ pub async fn get_applications() -> Result, sea_orm::DbErr> a.application, a.updated_at, a.sha, - a.path + a.path, + a.client_contract_address FROM applications a ORDER BY @@ -74,6 +75,9 @@ pub async fn get_applications() -> Result, sea_orm::DbErr> ), sha: Some(app.get("sha").unwrap().as_str().unwrap().to_string()), path: Some(app.get("path").unwrap().as_str().unwrap().to_string()), + client_contract_address: app + .get("client_contract_address") + .map(|client_contract_address| client_contract_address.to_string()), }); } Ok(applications) @@ -334,6 +338,7 @@ pub async fn merge_application_by_pr_number( * # Returns * @return Result - The result of the operation */ +#[allow(clippy::too_many_arguments)] pub async fn update_application( id: String, owner: String, @@ -342,6 +347,7 @@ pub async fn update_application( app_file: String, path: Option, sha: Option, + client_contract_address: Option, ) -> Result { let conn = get_database_connection().await?; @@ -361,6 +367,13 @@ pub async fn update_application( if let Some(path) = path { active_application.path = Set(Some(path)); }; + + if let Some(client_contract_address) = client_contract_address { + active_application.client_contract_address = Set(Some(client_contract_address)); + } else { + active_application.client_contract_address = Set(None); + } + let updated_application = active_application.update(&conn).await?; Ok(updated_application) } diff --git a/fplus-database/src/models/applications.rs b/fplus-database/src/models/applications.rs index 424d1d3..e257199 100644 --- a/fplus-database/src/models/applications.rs +++ b/fplus-database/src/models/applications.rs @@ -25,6 +25,8 @@ pub struct Model { pub sha: Option, #[sea_orm(nullable)] pub path: Option, + #[sea_orm(nullable)] + pub client_contract_address: Option, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/fplus-http-server/src/router/application.rs b/fplus-http-server/src/router/application.rs index ce02055..24218f6 100644 --- a/fplus-http-server/src/router/application.rs +++ b/fplus-http-server/src/router/application.rs @@ -53,13 +53,17 @@ pub async fn trigger( } }; dbg!(&ldn_application); - let CompleteGovernanceReviewInfo { allocation_amount } = info.into_inner(); + let CompleteGovernanceReviewInfo { + allocation_amount, + client_contract_address, + } = info.into_inner(); match ldn_application .complete_governance_review( query.github_username.clone(), query.owner.clone(), query.repo.clone(), allocation_amount, + client_contract_address, ) .await { diff --git a/fplus-lib/src/core/application/file.rs b/fplus-lib/src/core/application/file.rs index 875133b..7f40a7c 100644 --- a/fplus-lib/src/core/application/file.rs +++ b/fplus-lib/src/core/application/file.rs @@ -48,6 +48,8 @@ pub struct ApplicationFile { pub id: String, #[serde(rename = "Issue Number")] pub issue_number: String, + #[serde(rename = "Client Contract Address")] + pub client_contract_address: Option, #[serde(rename = "Client")] pub client: Client, #[serde(rename = "Project")] diff --git a/fplus-lib/src/core/application/mod.rs b/fplus-lib/src/core/application/mod.rs index e5af7f6..8bb277a 100644 --- a/fplus-lib/src/core/application/mod.rs +++ b/fplus-lib/src/core/application/mod.rs @@ -26,6 +26,7 @@ impl file::ApplicationFile { datacap, lifecycle, allocation, + client_contract_address: None, } } @@ -39,6 +40,7 @@ impl file::ApplicationFile { datacap: file::Datacap, allocation: file::Allocations, lifecycle: file::LifeCycle, + client_contract_address: Option, ) -> Self { //set lifecycle.edited = true let lifecycle = LifeCycle { @@ -54,6 +56,7 @@ impl file::ApplicationFile { datacap, lifecycle, allocation, + client_contract_address, } } @@ -69,13 +72,19 @@ impl file::ApplicationFile { let new_life_cycle = self.lifecycle.clone().move_back_to_governance_review(); // move back to submitted state let allocation = Allocations::default(); // empty allocations Self { + client_contract_address: None, lifecycle: new_life_cycle, allocation, ..self.clone() } } - pub fn complete_governance_review(&self, actor: String, request: AllocationRequest) -> Self { + pub fn complete_governance_review( + &self, + actor: String, + request: AllocationRequest, + client_contract_address: Option, + ) -> Self { let new_life_cycle = self .lifecycle .clone() @@ -84,6 +93,7 @@ impl file::ApplicationFile { Self { lifecycle: new_life_cycle, allocation: allocations, + client_contract_address, ..self.clone() } } diff --git a/fplus-lib/src/core/mod.rs b/fplus-lib/src/core/mod.rs index 08e3958..1abfdd1 100644 --- a/fplus-lib/src/core/mod.rs +++ b/fplus-lib/src/core/mod.rs @@ -194,6 +194,7 @@ pub struct ApplicationQueryParams { #[derive(Deserialize)] pub struct CompleteGovernanceReviewInfo { pub allocation_amount: String, + pub client_contract_address: Option, } #[derive(Deserialize)] @@ -847,6 +848,7 @@ impl LDNApplication { owner: String, repo: String, allocation_amount: String, + client_contract_address: Option, ) -> Result { match self.app_state().await { Ok(s) => match s { @@ -878,7 +880,11 @@ impl LDNApplication { allocation_amount_parsed, ); - let app_file = app_file.complete_governance_review(actor.clone(), request); + let app_file = app_file.complete_governance_review( + actor.clone(), + request, + client_contract_address.clone(), + ); let file_content = serde_json::to_string_pretty(&app_file).unwrap(); let app_path = &self.file_name.clone(); let app_branch = self.branch_name.clone(); @@ -904,7 +910,7 @@ impl LDNApplication { Ok(prs) => { if let Some(pr) = prs.first() { let number = pr.number; - let _ = database::applications::update_application( + database::applications::update_application( app_file.id.clone(), owner.clone(), repo.clone(), @@ -912,8 +918,15 @@ impl LDNApplication { serde_json::to_string_pretty(&app_file).unwrap(), Some(app_path.clone()), None, + client_contract_address, ) - .await; + .await + .map_err(|e| { + LDNError::Load(format!( + "Failed to update application: {} /// {}", + app_file.id, e + )) + })?; Self::issue_datacap_allocation_requested( app_file.clone(), @@ -1064,7 +1077,7 @@ impl LDNApplication { Ok(prs) => { if let Some(pr) = prs.first() { let number = pr.number; - let _ = database::applications::update_application( + database::applications::update_application( app_file.id.clone(), owner.clone(), repo.clone(), @@ -1072,8 +1085,15 @@ impl LDNApplication { serde_json::to_string_pretty(&app_file).unwrap(), Some(self.file_name.clone()), None, + app_file.client_contract_address.clone(), ) - .await; + .await + .map_err(|e| { + LDNError::Load(format!( + "Failed to update application: {} /// {}", + app_file.id, e + )) + })?; Self::issue_start_sign_dc( app_file.issue_number.clone(), owner.clone(), @@ -1223,6 +1243,7 @@ impl LDNApplication { serde_json::to_string_pretty(&app_file).unwrap(), Some(self.file_name.clone()), None, + app_file.client_contract_address.clone(), ) .await { @@ -1994,6 +2015,7 @@ impl LDNApplication { serde_json::to_string_pretty(&app_file).unwrap(), Some(ldn_application.file_name.clone()), None, + app_file.client_contract_address, ) .await; } @@ -2066,6 +2088,7 @@ impl LDNApplication { serde_json::to_string_pretty(&db_application_file).unwrap(), Some(filename.clone()), None, + db_application_file.client_contract_address.clone(), ) .await; @@ -2364,6 +2387,7 @@ impl LDNApplication { file_content.clone(), Some(filename.clone()), None, + application_file.client_contract_address.clone(), ) .await .map_err(|e| { @@ -2667,6 +2691,7 @@ impl LDNApplication { parsed_ldn.datacap, pr_application.allocation.clone(), pr_application.lifecycle.clone(), + pr_application.client_contract_address.clone(), ) .await; @@ -2722,7 +2747,7 @@ impl LDNApplication { if let Some(pr) = prs.first() { let number = pr.number; - let _ = database::applications::update_application( + database::applications::update_application( app_file.id.clone(), application_model.owner.clone(), application_model.repo.clone(), @@ -2730,8 +2755,15 @@ impl LDNApplication { serde_json::to_string_pretty(&app_file).unwrap(), Some(application_model.path.clone().unwrap()), None, + app_file.client_contract_address, ) - .await; + .await + .map_err(|e| { + LDNError::Load(format!( + "Failed to update application: {} /// {}", + app_file.id, e + )) + })?; } } Err(e) => log::warn!("Failed to get pull request by head: {}", e), @@ -2805,6 +2837,7 @@ impl LDNApplication { parsed_ldn.datacap, merged_application.allocation.clone(), merged_application.lifecycle.clone(), + merged_application.client_contract_address.clone(), ) .await; @@ -3482,6 +3515,7 @@ _The initial issue can be edited in order to solve the request of the verifier. serde_json::to_string_pretty(&gh_app.application_file).unwrap(), None, Some(gh_app.sha.clone()), + gh_app.application_file.client_contract_address.clone(), ) .await .unwrap(); @@ -3564,6 +3598,7 @@ _The initial issue can be edited in order to solve the request of the verifier. serde_json::to_string_pretty(&gh_app.application_file).unwrap(), Some(gh_app.path.clone()), Some(gh_app.sha.clone()), + gh_app.application_file.client_contract_address.clone(), ) .await .unwrap(); @@ -3787,6 +3822,7 @@ _The initial issue can be edited in order to solve the request of the verifier. serde_json::to_string_pretty(&application_file).unwrap(), app_model.path.clone(), None, + application_file.client_contract_address.clone(), ) .await .expect("Failed to update_application in DB!"); @@ -3933,6 +3969,7 @@ _The initial issue can be edited in order to solve the request of the verifier. serde_json::to_string_pretty(&application_file).unwrap(), app_model.path.clone(), None, + application_file.client_contract_address.clone(), ) .await .expect("Failed to update_application in DB!"); diff --git a/manual-migrations/2024-10-18.sql b/manual-migrations/2024-10-18.sql new file mode 100644 index 0000000..bf09c25 --- /dev/null +++ b/manual-migrations/2024-10-18.sql @@ -0,0 +1,2 @@ +ALTER TABLE IF EXISTS public.applications + ADD COLUMN client_contract_address text; \ No newline at end of file