Skip to content
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

[FIL-363] Insert client_contract_address into application JSON file #235

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
15 changes: 14 additions & 1 deletion fplus-database/src/database/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ pub async fn get_applications() -> Result<Vec<ApplicationModel>, sea_orm::DbErr>
a.application,
a.updated_at,
a.sha,
a.path
a.path,
a.client_contract_address
FROM
applications a
ORDER BY
Expand Down Expand Up @@ -74,6 +75,9 @@ pub async fn get_applications() -> Result<Vec<ApplicationModel>, 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)
Expand Down Expand Up @@ -334,6 +338,7 @@ pub async fn merge_application_by_pr_number(
* # Returns
* @return Result<ApplicationModel, sea_orm::DbErr> - The result of the operation
*/
#[allow(clippy::too_many_arguments)]
pub async fn update_application(
id: String,
owner: String,
Expand All @@ -342,6 +347,7 @@ pub async fn update_application(
app_file: String,
path: Option<String>,
sha: Option<String>,
client_contract_address: Option<String>,
) -> Result<ApplicationModel, sea_orm::DbErr> {
let conn = get_database_connection().await?;

Expand All @@ -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)
}
Expand Down
2 changes: 2 additions & 0 deletions fplus-database/src/models/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct Model {
pub sha: Option<String>,
#[sea_orm(nullable)]
pub path: Option<String>,
#[sea_orm(nullable)]
pub client_contract_address: Option<String>,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
6 changes: 5 additions & 1 deletion fplus-http-server/src/router/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
2 changes: 2 additions & 0 deletions fplus-lib/src/core/application/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
#[serde(rename = "Client")]
pub client: Client,
#[serde(rename = "Project")]
Expand Down
12 changes: 11 additions & 1 deletion fplus-lib/src/core/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl file::ApplicationFile {
datacap,
lifecycle,
allocation,
client_contract_address: None,
}
}

Expand All @@ -39,6 +40,7 @@ impl file::ApplicationFile {
datacap: file::Datacap,
allocation: file::Allocations,
lifecycle: file::LifeCycle,
client_contract_address: Option<String>,
) -> Self {
//set lifecycle.edited = true
let lifecycle = LifeCycle {
Expand All @@ -54,6 +56,7 @@ impl file::ApplicationFile {
datacap,
lifecycle,
allocation,
client_contract_address,
}
}

Expand All @@ -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<String>,
) -> Self {
let new_life_cycle = self
.lifecycle
.clone()
Expand All @@ -84,6 +93,7 @@ impl file::ApplicationFile {
Self {
lifecycle: new_life_cycle,
allocation: allocations,
client_contract_address,
..self.clone()
}
}
Expand Down
51 changes: 44 additions & 7 deletions fplus-lib/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ pub struct ApplicationQueryParams {
#[derive(Deserialize)]
pub struct CompleteGovernanceReviewInfo {
pub allocation_amount: String,
pub client_contract_address: Option<String>,
}

#[derive(Deserialize)]
Expand Down Expand Up @@ -847,6 +848,7 @@ impl LDNApplication {
owner: String,
repo: String,
allocation_amount: String,
client_contract_address: Option<String>,
) -> Result<ApplicationFile, LDNError> {
match self.app_state().await {
Ok(s) => match s {
Expand Down Expand Up @@ -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();
Expand All @@ -904,16 +910,23 @@ 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(),
number,
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(),
Expand Down Expand Up @@ -1064,16 +1077,23 @@ 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(),
number,
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(),
Expand Down Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -2364,6 +2387,7 @@ impl LDNApplication {
file_content.clone(),
Some(filename.clone()),
None,
application_file.client_contract_address.clone(),
)
.await
.map_err(|e| {
Expand Down Expand Up @@ -2667,6 +2691,7 @@ impl LDNApplication {
parsed_ldn.datacap,
pr_application.allocation.clone(),
pr_application.lifecycle.clone(),
pr_application.client_contract_address.clone(),
)
.await;

Expand Down Expand Up @@ -2722,16 +2747,23 @@ 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(),
number,
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),
Expand Down Expand Up @@ -2805,6 +2837,7 @@ impl LDNApplication {
parsed_ldn.datacap,
merged_application.allocation.clone(),
merged_application.lifecycle.clone(),
merged_application.client_contract_address.clone(),
)
.await;

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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!");
Expand Down Expand Up @@ -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!");
Expand Down
2 changes: 2 additions & 0 deletions manual-migrations/2024-10-18.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE IF EXISTS public.applications
ADD COLUMN client_contract_address text;