Skip to content

Commit 6d2a8f9

Browse files
Filip-Lfilip-neti
andauthored
Insert client_contract_address into application JSON file (#235)
Co-authored-by: Filip Lelek <[email protected]>
1 parent e279caf commit 6d2a8f9

File tree

7 files changed

+80
-10
lines changed

7 files changed

+80
-10
lines changed

fplus-database/src/database/applications.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ pub async fn get_applications() -> Result<Vec<ApplicationModel>, sea_orm::DbErr>
2929
a.application,
3030
a.updated_at,
3131
a.sha,
32-
a.path
32+
a.path,
33+
a.client_contract_address
3334
FROM
3435
applications a
3536
ORDER BY
@@ -74,6 +75,9 @@ pub async fn get_applications() -> Result<Vec<ApplicationModel>, sea_orm::DbErr>
7475
),
7576
sha: Some(app.get("sha").unwrap().as_str().unwrap().to_string()),
7677
path: Some(app.get("path").unwrap().as_str().unwrap().to_string()),
78+
client_contract_address: app
79+
.get("client_contract_address")
80+
.map(|client_contract_address| client_contract_address.to_string()),
7781
});
7882
}
7983
Ok(applications)
@@ -334,6 +338,7 @@ pub async fn merge_application_by_pr_number(
334338
* # Returns
335339
* @return Result<ApplicationModel, sea_orm::DbErr> - The result of the operation
336340
*/
341+
#[allow(clippy::too_many_arguments)]
337342
pub async fn update_application(
338343
id: String,
339344
owner: String,
@@ -342,6 +347,7 @@ pub async fn update_application(
342347
app_file: String,
343348
path: Option<String>,
344349
sha: Option<String>,
350+
client_contract_address: Option<String>,
345351
) -> Result<ApplicationModel, sea_orm::DbErr> {
346352
let conn = get_database_connection().await?;
347353

@@ -361,6 +367,13 @@ pub async fn update_application(
361367
if let Some(path) = path {
362368
active_application.path = Set(Some(path));
363369
};
370+
371+
if let Some(client_contract_address) = client_contract_address {
372+
active_application.client_contract_address = Set(Some(client_contract_address));
373+
} else {
374+
active_application.client_contract_address = Set(None);
375+
}
376+
364377
let updated_application = active_application.update(&conn).await?;
365378
Ok(updated_application)
366379
}

fplus-database/src/models/applications.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ pub struct Model {
2525
pub sha: Option<String>,
2626
#[sea_orm(nullable)]
2727
pub path: Option<String>,
28+
#[sea_orm(nullable)]
29+
pub client_contract_address: Option<String>,
2830
}
2931

3032
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,17 @@ pub async fn trigger(
5353
}
5454
};
5555
dbg!(&ldn_application);
56-
let CompleteGovernanceReviewInfo { allocation_amount } = info.into_inner();
56+
let CompleteGovernanceReviewInfo {
57+
allocation_amount,
58+
client_contract_address,
59+
} = info.into_inner();
5760
match ldn_application
5861
.complete_governance_review(
5962
query.github_username.clone(),
6063
query.owner.clone(),
6164
query.repo.clone(),
6265
allocation_amount,
66+
client_contract_address,
6367
)
6468
.await
6569
{

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

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ pub struct ApplicationFile {
4848
pub id: String,
4949
#[serde(rename = "Issue Number")]
5050
pub issue_number: String,
51+
#[serde(rename = "Client Contract Address")]
52+
pub client_contract_address: Option<String>,
5153
#[serde(rename = "Client")]
5254
pub client: Client,
5355
#[serde(rename = "Project")]

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

+11-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl file::ApplicationFile {
2626
datacap,
2727
lifecycle,
2828
allocation,
29+
client_contract_address: None,
2930
}
3031
}
3132

@@ -39,6 +40,7 @@ impl file::ApplicationFile {
3940
datacap: file::Datacap,
4041
allocation: file::Allocations,
4142
lifecycle: file::LifeCycle,
43+
client_contract_address: Option<String>,
4244
) -> Self {
4345
//set lifecycle.edited = true
4446
let lifecycle = LifeCycle {
@@ -54,6 +56,7 @@ impl file::ApplicationFile {
5456
datacap,
5557
lifecycle,
5658
allocation,
59+
client_contract_address,
5760
}
5861
}
5962

@@ -69,13 +72,19 @@ impl file::ApplicationFile {
6972
let new_life_cycle = self.lifecycle.clone().move_back_to_governance_review(); // move back to submitted state
7073
let allocation = Allocations::default(); // empty allocations
7174
Self {
75+
client_contract_address: None,
7276
lifecycle: new_life_cycle,
7377
allocation,
7478
..self.clone()
7579
}
7680
}
7781

78-
pub fn complete_governance_review(&self, actor: String, request: AllocationRequest) -> Self {
82+
pub fn complete_governance_review(
83+
&self,
84+
actor: String,
85+
request: AllocationRequest,
86+
client_contract_address: Option<String>,
87+
) -> Self {
7988
let new_life_cycle = self
8089
.lifecycle
8190
.clone()
@@ -84,6 +93,7 @@ impl file::ApplicationFile {
8493
Self {
8594
lifecycle: new_life_cycle,
8695
allocation: allocations,
96+
client_contract_address,
8797
..self.clone()
8898
}
8999
}

fplus-lib/src/core/mod.rs

+44-7
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ pub struct ApplicationQueryParams {
194194
#[derive(Deserialize)]
195195
pub struct CompleteGovernanceReviewInfo {
196196
pub allocation_amount: String,
197+
pub client_contract_address: Option<String>,
197198
}
198199

199200
#[derive(Deserialize)]
@@ -847,6 +848,7 @@ impl LDNApplication {
847848
owner: String,
848849
repo: String,
849850
allocation_amount: String,
851+
client_contract_address: Option<String>,
850852
) -> Result<ApplicationFile, LDNError> {
851853
match self.app_state().await {
852854
Ok(s) => match s {
@@ -878,7 +880,11 @@ impl LDNApplication {
878880
allocation_amount_parsed,
879881
);
880882

881-
let app_file = app_file.complete_governance_review(actor.clone(), request);
883+
let app_file = app_file.complete_governance_review(
884+
actor.clone(),
885+
request,
886+
client_contract_address.clone(),
887+
);
882888
let file_content = serde_json::to_string_pretty(&app_file).unwrap();
883889
let app_path = &self.file_name.clone();
884890
let app_branch = self.branch_name.clone();
@@ -904,16 +910,23 @@ impl LDNApplication {
904910
Ok(prs) => {
905911
if let Some(pr) = prs.first() {
906912
let number = pr.number;
907-
let _ = database::applications::update_application(
913+
database::applications::update_application(
908914
app_file.id.clone(),
909915
owner.clone(),
910916
repo.clone(),
911917
number,
912918
serde_json::to_string_pretty(&app_file).unwrap(),
913919
Some(app_path.clone()),
914920
None,
921+
client_contract_address,
915922
)
916-
.await;
923+
.await
924+
.map_err(|e| {
925+
LDNError::Load(format!(
926+
"Failed to update application: {} /// {}",
927+
app_file.id, e
928+
))
929+
})?;
917930

918931
Self::issue_datacap_allocation_requested(
919932
app_file.clone(),
@@ -1064,16 +1077,23 @@ impl LDNApplication {
10641077
Ok(prs) => {
10651078
if let Some(pr) = prs.first() {
10661079
let number = pr.number;
1067-
let _ = database::applications::update_application(
1080+
database::applications::update_application(
10681081
app_file.id.clone(),
10691082
owner.clone(),
10701083
repo.clone(),
10711084
number,
10721085
serde_json::to_string_pretty(&app_file).unwrap(),
10731086
Some(self.file_name.clone()),
10741087
None,
1088+
app_file.client_contract_address.clone(),
10751089
)
1076-
.await;
1090+
.await
1091+
.map_err(|e| {
1092+
LDNError::Load(format!(
1093+
"Failed to update application: {} /// {}",
1094+
app_file.id, e
1095+
))
1096+
})?;
10771097
Self::issue_start_sign_dc(
10781098
app_file.issue_number.clone(),
10791099
owner.clone(),
@@ -1223,6 +1243,7 @@ impl LDNApplication {
12231243
serde_json::to_string_pretty(&app_file).unwrap(),
12241244
Some(self.file_name.clone()),
12251245
None,
1246+
app_file.client_contract_address.clone(),
12261247
)
12271248
.await
12281249
{
@@ -1994,6 +2015,7 @@ impl LDNApplication {
19942015
serde_json::to_string_pretty(&app_file).unwrap(),
19952016
Some(ldn_application.file_name.clone()),
19962017
None,
2018+
app_file.client_contract_address,
19972019
)
19982020
.await;
19992021
}
@@ -2066,6 +2088,7 @@ impl LDNApplication {
20662088
serde_json::to_string_pretty(&db_application_file).unwrap(),
20672089
Some(filename.clone()),
20682090
None,
2091+
db_application_file.client_contract_address.clone(),
20692092
)
20702093
.await;
20712094

@@ -2364,6 +2387,7 @@ impl LDNApplication {
23642387
file_content.clone(),
23652388
Some(filename.clone()),
23662389
None,
2390+
application_file.client_contract_address.clone(),
23672391
)
23682392
.await
23692393
.map_err(|e| {
@@ -2667,6 +2691,7 @@ impl LDNApplication {
26672691
parsed_ldn.datacap,
26682692
pr_application.allocation.clone(),
26692693
pr_application.lifecycle.clone(),
2694+
pr_application.client_contract_address.clone(),
26702695
)
26712696
.await;
26722697

@@ -2722,16 +2747,23 @@ impl LDNApplication {
27222747
if let Some(pr) = prs.first() {
27232748
let number = pr.number;
27242749

2725-
let _ = database::applications::update_application(
2750+
database::applications::update_application(
27262751
app_file.id.clone(),
27272752
application_model.owner.clone(),
27282753
application_model.repo.clone(),
27292754
number,
27302755
serde_json::to_string_pretty(&app_file).unwrap(),
27312756
Some(application_model.path.clone().unwrap()),
27322757
None,
2758+
app_file.client_contract_address,
27332759
)
2734-
.await;
2760+
.await
2761+
.map_err(|e| {
2762+
LDNError::Load(format!(
2763+
"Failed to update application: {} /// {}",
2764+
app_file.id, e
2765+
))
2766+
})?;
27352767
}
27362768
}
27372769
Err(e) => log::warn!("Failed to get pull request by head: {}", e),
@@ -2805,6 +2837,7 @@ impl LDNApplication {
28052837
parsed_ldn.datacap,
28062838
merged_application.allocation.clone(),
28072839
merged_application.lifecycle.clone(),
2840+
merged_application.client_contract_address.clone(),
28082841
)
28092842
.await;
28102843

@@ -3482,6 +3515,7 @@ _The initial issue can be edited in order to solve the request of the verifier.
34823515
serde_json::to_string_pretty(&gh_app.application_file).unwrap(),
34833516
None,
34843517
Some(gh_app.sha.clone()),
3518+
gh_app.application_file.client_contract_address.clone(),
34853519
)
34863520
.await
34873521
.unwrap();
@@ -3564,6 +3598,7 @@ _The initial issue can be edited in order to solve the request of the verifier.
35643598
serde_json::to_string_pretty(&gh_app.application_file).unwrap(),
35653599
Some(gh_app.path.clone()),
35663600
Some(gh_app.sha.clone()),
3601+
gh_app.application_file.client_contract_address.clone(),
35673602
)
35683603
.await
35693604
.unwrap();
@@ -3787,6 +3822,7 @@ _The initial issue can be edited in order to solve the request of the verifier.
37873822
serde_json::to_string_pretty(&application_file).unwrap(),
37883823
app_model.path.clone(),
37893824
None,
3825+
application_file.client_contract_address.clone(),
37903826
)
37913827
.await
37923828
.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.
39333969
serde_json::to_string_pretty(&application_file).unwrap(),
39343970
app_model.path.clone(),
39353971
None,
3972+
application_file.client_contract_address.clone(),
39363973
)
39373974
.await
39383975
.expect("Failed to update_application in DB!");

manual-migrations/2024-10-18.sql

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
ALTER TABLE IF EXISTS public.applications
2+
ADD COLUMN client_contract_address text;

0 commit comments

Comments
 (0)