Skip to content

Commit a847ab0

Browse files
committed
Prepare backend to assing unallocated
1 parent f98fc0d commit a847ab0

File tree

7 files changed

+149
-70
lines changed

7 files changed

+149
-70
lines changed

fplus-database/src/database/applications.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,23 @@ pub async fn get_applications_by_client_id(
420420
Ok(result)
421421
}
422422

423+
pub async fn get_applications_by_client_contract_address(
424+
client_contract_address: &str,
425+
) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
426+
let conn = get_database_connection().await?;
427+
let applications = Application::find()
428+
.from_raw_sql(Statement::from_sql_and_values(
429+
DbBackend::Postgres,
430+
"SELECT DISTINCT ON (id) * FROM applications
431+
WHERE client_contract_address = $1
432+
ORDER BY id, pr_number DESC",
433+
[client_contract_address.into()],
434+
))
435+
.all(&conn)
436+
.await?;
437+
Ok(applications)
438+
}
439+
423440
pub async fn get_distinct_applications_by_clients_addresses(
424441
clients_addresses: Vec<String>,
425442
) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {

fplus-http-server/src/main.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ async fn main() -> std::io::Result<()> {
9999
.service(router::application::closed_allocator_applications)
100100
.service(router::application::total_dc_reached)
101101
.service(router::application::single)
102+
.service(router::application::get_applications_by_contract_address)
102103
.service(router::application::application_with_allocation_amount_handler)
103104
.service(router::application::validate_application_flow)
104105
.service(router::application::check_for_changes)

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ use fplus_lib::core::{
99
},
1010
ApplicationQueryParams, BranchDeleteInfo, CompleteGovernanceReviewInfo,
1111
CompleteNewApplicationApprovalInfo, CompleteNewApplicationProposalInfo, CreateApplicationInfo,
12-
DcReachedInfo, DecreaseAllowanceApprovalInfo, DecreaseAllowanceProposalInfo, GithubQueryParams,
13-
LDNApplication, MoreInfoNeeded, NotifyRefillInfo, StorageProvidersChangeApprovalInfo,
12+
DcReachedInfo, DecreaseAllowanceApprovalInfo, DecreaseAllowanceProposalInfo,
13+
GetApplicationsByClientContractAddressQueryParams, GithubQueryParams, LDNApplication,
14+
MoreInfoNeeded, NotifyRefillInfo, StorageProvidersChangeApprovalInfo,
1415
StorageProvidersChangeProposalInfo, SubmitKYCInfo, TriggerSSAInfo, ValidationPullRequestData,
1516
VerifierActionsQueryParams,
1617
};
@@ -50,6 +51,20 @@ pub async fn closed_applications() -> actix_web::Result<impl Responder> {
5051
.body(parsed))
5152
}
5253

54+
#[get("/applications/by_contract_address")]
55+
pub async fn get_applications_by_contract_address(
56+
query: web::Query<GetApplicationsByClientContractAddressQueryParams>,
57+
) -> actix_web::Result<impl Responder> {
58+
let applications =
59+
LDNApplication::get_applications_by_client_contract_address(&query.client_contract_address)
60+
.await
61+
.map_err(ErrorNotFound)?;
62+
let parsed = serde_json::to_string_pretty(&applications).map_err(ErrorInternalServerError)?;
63+
Ok(HttpResponse::Ok()
64+
.content_type("application/json")
65+
.body(parsed))
66+
}
67+
5368
#[get("/applications/closed/allocator")]
5469
pub async fn closed_allocator_applications(
5570
query: web::Query<GithubQueryParams>,
@@ -138,6 +153,7 @@ pub async fn propose(
138153
signer,
139154
request_id,
140155
new_allocation_amount,
156+
amount_of_datacap_sent_to_contract,
141157
} = info.into_inner();
142158
let ldn_application =
143159
LDNApplication::load(query.id.clone(), query.owner.clone(), query.repo.clone())
@@ -157,6 +173,7 @@ pub async fn propose(
157173
query.owner.clone(),
158174
query.repo.clone(),
159175
new_allocation_amount,
176+
amount_of_datacap_sent_to_contract,
160177
)
161178
.await
162179
.map_err(ErrorInternalServerError)?;
@@ -315,6 +332,7 @@ pub async fn approve(
315332
query.owner.clone(),
316333
query.repo.clone(),
317334
None,
335+
None,
318336
)
319337
.await
320338
.map_err(ErrorInternalServerError)?;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ impl AllocationRequest {
2626
kind,
2727
allocation_amount,
2828
is_active: true,
29+
amount_of_datacap_sent_to_contract: None,
2930
}
3031
}
3132
}
@@ -40,6 +41,7 @@ impl Allocation {
4041
is_active: true,
4142
amount: request_information.allocation_amount,
4243
signers: Verifiers::default(),
44+
amount_of_datacap_sent_to_contract: None,
4345
}
4446
}
4547

@@ -108,6 +110,17 @@ impl Allocations {
108110
Self(res)
109111
}
110112

113+
pub fn set_amount_of_dc_sent_to_contract(&self, request_id: &str, amount: &str) -> Self {
114+
let mut res: Vec<Allocation> = self.0.clone();
115+
for allocation in res.iter_mut() {
116+
if allocation.id == request_id && allocation.is_active {
117+
allocation.amount_of_datacap_sent_to_contract = Some(amount.into());
118+
break;
119+
}
120+
}
121+
Self(res)
122+
}
123+
111124
pub fn remove_signers_in_active_allocation(&mut self) -> Self {
112125
if let Some(alloc) = self.0.iter_mut().find(|alloc| alloc.is_active) {
113126
*alloc = alloc.remove_signers();

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,11 @@ pub struct Allocation {
339339
pub is_active: bool,
340340
#[serde(rename = "Allocation Amount")]
341341
pub amount: String,
342+
#[serde(
343+
rename = "Amount of Datacap Sent to Contract",
344+
skip_serializing_if = "Option::is_none"
345+
)]
346+
pub amount_of_datacap_sent_to_contract: Option<String>,
342347
#[serde(rename = "Signers")]
343348
pub signers: Verifiers,
344349
}
@@ -436,7 +441,7 @@ pub struct VerifierInput {
436441
pub github_username: String,
437442
pub signing_address: String,
438443
pub created_at: String,
439-
pub message_cid: String,
444+
pub message_cid: Option<String>,
440445
pub increase_allowance_cid: Option<String>,
441446
}
442447

@@ -465,7 +470,7 @@ impl From<&DecreaseClientAllowanceVerifier> for Verifier {
465470
github_username: input.github_username.clone(),
466471
signing_address: input.signing_address.clone(),
467472
created_at: Utc::now().to_string(),
468-
message_cid: input.decrease_allowance_cid.clone(),
473+
message_cid: Some(input.decrease_allowance_cid.clone()),
469474
increase_allowance_cid: None,
470475
}
471476
}
@@ -479,8 +484,8 @@ pub struct Verifier {
479484
pub signing_address: String,
480485
#[serde(rename = "Created At")]
481486
pub created_at: String,
482-
#[serde(rename = "Message CID")]
483-
pub message_cid: String,
487+
#[serde(rename = "Message CID", skip_serializing_if = "Option::is_none")]
488+
pub message_cid: Option<String>,
484489
#[serde(
485490
rename = "Increase allowance CID",
486491
skip_serializing_if = "Option::is_none"
@@ -518,6 +523,7 @@ pub struct AllocationRequest {
518523
pub kind: AllocationRequestType,
519524
pub is_active: bool,
520525
pub allocation_amount: String,
526+
pub amount_of_datacap_sent_to_contract: Option<String>,
521527
}
522528

523529
#[derive(Serialize, Deserialize, Debug, Clone)]

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,17 @@ impl file::ApplicationFile {
213213
}
214214
}
215215

216+
pub fn set_amount_of_dc_sent_to_contract(&self, request_id: &str, amount: &str) -> Self {
217+
let allocation_after_sign = self
218+
.allocation
219+
.clone()
220+
.set_amount_of_dc_sent_to_contract(request_id, amount);
221+
Self {
222+
allocation: allocation_after_sign,
223+
..self.clone()
224+
}
225+
}
226+
216227
pub fn move_back_to_ready_to_sign(&self) -> Self {
217228
let updated_allocation = self
218229
.clone()

0 commit comments

Comments
 (0)