Skip to content

[FIL-816] Prepare backend to assing unallocated DataCap #289

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions fplus-database/src/database/applications.rs
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,23 @@ pub async fn get_applications_by_client_id(
Ok(result)
}

pub async fn get_applications_by_client_contract_address(
client_contract_address: &str,
) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
let conn = get_database_connection().await?;
let applications = Application::find()
.from_raw_sql(Statement::from_sql_and_values(
DbBackend::Postgres,
"SELECT DISTINCT ON (id) * FROM applications
WHERE client_contract_address = $1
ORDER BY id, pr_number DESC",
[client_contract_address.into()],
))
.all(&conn)
.await?;
Ok(applications)
}

pub async fn get_distinct_applications_by_clients_addresses(
clients_addresses: Vec<String>,
) -> Result<Vec<ApplicationModel>, sea_orm::DbErr> {
Expand Down
1 change: 1 addition & 0 deletions fplus-http-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ async fn main() -> std::io::Result<()> {
.service(router::application::closed_allocator_applications)
.service(router::application::total_dc_reached)
.service(router::application::single)
.service(router::application::get_applications_by_contract_address)
.service(router::application::application_with_allocation_amount_handler)
.service(router::application::validate_application_flow)
.service(router::application::check_for_changes)
Expand Down
22 changes: 20 additions & 2 deletions fplus-http-server/src/router/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ use fplus_lib::core::{
},
ApplicationQueryParams, BranchDeleteInfo, CompleteGovernanceReviewInfo,
CompleteNewApplicationApprovalInfo, CompleteNewApplicationProposalInfo, CreateApplicationInfo,
DcReachedInfo, DecreaseAllowanceApprovalInfo, DecreaseAllowanceProposalInfo, GithubQueryParams,
LDNApplication, MoreInfoNeeded, NotifyRefillInfo, StorageProvidersChangeApprovalInfo,
DcReachedInfo, DecreaseAllowanceApprovalInfo, DecreaseAllowanceProposalInfo,
GetApplicationsByClientContractAddressQueryParams, GithubQueryParams, LDNApplication,
MoreInfoNeeded, NotifyRefillInfo, StorageProvidersChangeApprovalInfo,
StorageProvidersChangeProposalInfo, SubmitKYCInfo, TriggerSSAInfo, ValidationPullRequestData,
VerifierActionsQueryParams,
};
Expand Down Expand Up @@ -50,6 +51,20 @@ pub async fn closed_applications() -> actix_web::Result<impl Responder> {
.body(parsed))
}

#[get("/applications/by_contract_address")]
pub async fn get_applications_by_contract_address(
query: web::Query<GetApplicationsByClientContractAddressQueryParams>,
) -> actix_web::Result<impl Responder> {
let applications =
LDNApplication::get_applications_by_client_contract_address(&query.client_contract_address)
.await
.map_err(ErrorNotFound)?;
let parsed = serde_json::to_string_pretty(&applications).map_err(ErrorInternalServerError)?;
Ok(HttpResponse::Ok()
.content_type("application/json")
.body(parsed))
}

#[get("/applications/closed/allocator")]
pub async fn closed_allocator_applications(
query: web::Query<GithubQueryParams>,
Expand Down Expand Up @@ -138,6 +153,7 @@ pub async fn propose(
signer,
request_id,
new_allocation_amount,
amount_of_datacap_sent_to_contract,
} = info.into_inner();
let ldn_application =
LDNApplication::load(query.id.clone(), query.owner.clone(), query.repo.clone())
Expand All @@ -157,6 +173,7 @@ pub async fn propose(
query.owner.clone(),
query.repo.clone(),
new_allocation_amount,
amount_of_datacap_sent_to_contract,
)
.await
.map_err(ErrorInternalServerError)?;
Expand Down Expand Up @@ -315,6 +332,7 @@ pub async fn approve(
query.owner.clone(),
query.repo.clone(),
None,
None,
)
.await
.map_err(ErrorInternalServerError)?;
Expand Down
13 changes: 13 additions & 0 deletions fplus-lib/src/core/application/allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ impl AllocationRequest {
kind,
allocation_amount,
is_active: true,
amount_of_datacap_sent_to_contract: None,
}
}
}
Expand All @@ -40,6 +41,7 @@ impl Allocation {
is_active: true,
amount: request_information.allocation_amount,
signers: Verifiers::default(),
amount_of_datacap_sent_to_contract: None,
}
}

Expand Down Expand Up @@ -108,6 +110,17 @@ impl Allocations {
Self(res)
}

pub fn set_amount_of_dc_sent_to_contract(&self, request_id: &str, amount: &str) -> Self {
let mut res: Vec<Allocation> = self.0.clone();
for allocation in res.iter_mut() {
if allocation.id == request_id && allocation.is_active {
allocation.amount_of_datacap_sent_to_contract = Some(amount.into());
break;
}
}
Self(res)
}

pub fn remove_signers_in_active_allocation(&mut self) -> Self {
if let Some(alloc) = self.0.iter_mut().find(|alloc| alloc.is_active) {
*alloc = alloc.remove_signers();
Expand Down
14 changes: 10 additions & 4 deletions fplus-lib/src/core/application/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ pub struct Allocation {
pub is_active: bool,
#[serde(rename = "Allocation Amount")]
pub amount: String,
#[serde(
rename = "Amount of Datacap Sent to Contract",
skip_serializing_if = "Option::is_none"
)]
pub amount_of_datacap_sent_to_contract: Option<String>,
#[serde(rename = "Signers")]
pub signers: Verifiers,
}
Expand Down Expand Up @@ -436,7 +441,7 @@ pub struct VerifierInput {
pub github_username: String,
pub signing_address: String,
pub created_at: String,
pub message_cid: String,
pub message_cid: Option<String>,
pub increase_allowance_cid: Option<String>,
}

Expand Down Expand Up @@ -465,7 +470,7 @@ impl From<&DecreaseClientAllowanceVerifier> for Verifier {
github_username: input.github_username.clone(),
signing_address: input.signing_address.clone(),
created_at: Utc::now().to_string(),
message_cid: input.decrease_allowance_cid.clone(),
message_cid: Some(input.decrease_allowance_cid.clone()),
increase_allowance_cid: None,
}
}
Expand All @@ -479,8 +484,8 @@ pub struct Verifier {
pub signing_address: String,
#[serde(rename = "Created At")]
pub created_at: String,
#[serde(rename = "Message CID")]
pub message_cid: String,
#[serde(rename = "Message CID", skip_serializing_if = "Option::is_none")]
pub message_cid: Option<String>,
#[serde(
rename = "Increase allowance CID",
skip_serializing_if = "Option::is_none"
Expand Down Expand Up @@ -518,6 +523,7 @@ pub struct AllocationRequest {
pub kind: AllocationRequestType,
pub is_active: bool,
pub allocation_amount: String,
pub amount_of_datacap_sent_to_contract: Option<String>,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down
11 changes: 11 additions & 0 deletions fplus-lib/src/core/application/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,17 @@ impl file::ApplicationFile {
}
}

pub fn set_amount_of_dc_sent_to_contract(&self, request_id: &str, amount: &str) -> Self {
let allocation_after_sign = self
.allocation
.clone()
.set_amount_of_dc_sent_to_contract(request_id, amount);
Self {
allocation: allocation_after_sign,
..self.clone()
}
}

pub fn move_back_to_ready_to_sign(&self) -> Self {
let updated_allocation = self
.clone()
Expand Down
Loading