Skip to content

Commit 2a1e56a

Browse files
committed
Merged changes from main
1 parent a8f7d84 commit 2a1e56a

File tree

4 files changed

+85
-85
lines changed

4 files changed

+85
-85
lines changed

fplus-http-server/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "fplus-http-server"
33
authors = ["jbesraa", "kokal33", "clriesco"]
4-
version = "1.0.12"
4+
version = "1.0.15"
55
description = "FPlus main http module"
66
license = "MIT OR Apache-2.0"
77
edition = "2021"
@@ -20,7 +20,7 @@ actix-cors = "0.6.4"
2020
reqwest = { version = "0.11.18", features = ["json"] }
2121
futures = "0.3.28"
2222
dotenv = "0.15.0"
23-
fplus-lib = { path = "../fplus-lib", version = "1.0.12" }
23+
fplus-lib = { path = "../fplus-lib", version = "1.0.15" }
2424
anyhow = "1.0.75"
2525
async-trait = "0.1.73"
2626
uuidv4 = "1.0.0"

fplus-lib/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "fplus-lib"
33
authors = ["jbesraa", "kokal33", "clriesco"]
4-
version = "1.0.12"
4+
version = "1.0.15"
55
edition = "2021"
66
description = "FPlus library/helper files"
77
license = "MIT OR Apache-2.0"

fplus-lib/src/core/mod.rs

Lines changed: 60 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -950,47 +950,43 @@ impl LDNApplication {
950950
let app_state: AppState = application_file.lifecycle.get_state();
951951
log::info!("- App state is {:?}", app_state.as_str());
952952
if app_state < AppState::Granted {
953-
log::warn!("- State is less than StartSignDatacap");
953+
log::warn!("- State is less than Granted");
954954
return Ok(false);
955-
}
956-
match app_state {
957-
AppState::Granted => {
958-
dbg!("State is StartSignDatacap");
959-
let active_request_id = match application_file.clone().lifecycle.get_active_allocation_id() {
960-
Some(id) => id,
961-
None => {
962-
log::warn!("- No active request");
963-
return Ok(false);
964-
}
965-
};
966-
let active_request = match application_file.allocation.find_one(active_request_id) {
967-
Some(request) => request,
968-
None => {
969-
log::warn!("- No active request");
970-
return Ok(false);
971-
}
972-
};
973-
let signers: application::file::Notaries = active_request.signers.clone();
974-
if signers.0.len() != 2 {
975-
log::warn!("- Not enough signers");
955+
} else if app_state == AppState::Granted {
956+
let active_request_id = match application_file.clone().lifecycle.get_active_allocation_id() {
957+
Some(id) => id,
958+
None => {
959+
log::warn!("- No active request");
976960
return Ok(false);
977961
}
978-
let signer = signers.0.get(1).unwrap();
979-
let signer_address = signer.signing_address.clone();
980-
let valid_notaries = Self::fetch_notaries().await?;
981-
if valid_notaries.is_valid(&signer_address) {
982-
log::info!("- Validated!");
983-
984-
Self::issue_datacap_request_signature(application_file.clone(), "approved".to_string()).await?;
985-
Self::update_issue_labels(application_file.issue_number.clone(), &[AppState::Granted.as_str()]).await?;
986-
Self::issue_granted(application_file.issue_number.clone()).await?;
987-
988-
return Ok(true);
962+
};
963+
let active_request = match application_file.allocation.find_one(active_request_id) {
964+
Some(request) => request,
965+
None => {
966+
log::warn!("- No active request");
967+
return Ok(false);
989968
}
990-
log::warn!("- Not validated!");
991-
Ok(false)
969+
};
970+
let signers: application::file::Notaries = active_request.signers.clone();
971+
if signers.0.len() != 2 {
972+
log::warn!("- Not enough signers");
973+
return Ok(false);
992974
}
993-
_ => Ok(true),
975+
let signer = signers.0.get(1).unwrap();
976+
let signer_address = signer.signing_address.clone();
977+
let valid_notaries = Self::fetch_notaries().await?;
978+
if valid_notaries.is_valid(&signer_address) {
979+
log::info!("- Validated!");
980+
Self::issue_datacap_request_signature(application_file.clone(), "approved".to_string()).await?;
981+
Self::update_issue_labels(application_file.issue_number.clone(), &[AppState::Granted.as_str()]).await?;
982+
Self::issue_granted(application_file.issue_number.clone()).await?;
983+
return Ok(true);
984+
}
985+
log::warn!("- Not validated!");
986+
Ok(false)
987+
} else {
988+
log::info!("- State is greater than Granted");
989+
Ok(true)
994990
}
995991
}
996992
Err(e) => Err(LDNError::Load(format!(
@@ -1008,38 +1004,35 @@ impl LDNApplication {
10081004
let app_state: AppState = application_file.lifecycle.get_state();
10091005
log::info!("- App state is {:?}", app_state.as_str());
10101006
if app_state < AppState::StartSignDatacap {
1011-
log::warn!("- State is less than ReadyToSign");
1007+
log::warn!("- State is less than StartSignDatacap");
10121008
return Ok(false);
1013-
}
1014-
match app_state {
1015-
AppState::StartSignDatacap => {
1016-
let active_request = application_file.allocation.active();
1017-
if active_request.is_none() {
1018-
log::warn!("- No active request");
1019-
return Ok(false);
1020-
}
1021-
let active_request = active_request.unwrap();
1022-
let signers = active_request.signers.clone();
1023-
if signers.0.len() != 1 {
1024-
log::warn!("- Not enough signers");
1025-
return Ok(false);
1026-
}
1027-
let signer = signers.0.get(0).unwrap();
1028-
let signer_address = signer.signing_address.clone();
1029-
let valid_notaries = Self::fetch_notaries().await?;
1030-
if valid_notaries.is_valid(&signer_address) {
1031-
log::info!("- Validated!");
1032-
1033-
Self::issue_start_sign_dc(application_file.issue_number.clone()).await?;
1034-
Self::issue_datacap_request_signature(application_file.clone(), "proposed".to_string()).await?;
1035-
Self::update_issue_labels(application_file.issue_number.clone(), &[AppState::StartSignDatacap.as_str()]).await?;
1036-
1037-
return Ok(true);
1038-
}
1039-
log::warn!("- Not validated!");
1040-
Ok(false)
1009+
} else if app_state == AppState::StartSignDatacap {
1010+
let active_request = application_file.allocation.active();
1011+
if active_request.is_none() {
1012+
log::warn!("- No active request");
1013+
return Ok(false);
10411014
}
1042-
_ => Ok(true),
1015+
let active_request = active_request.unwrap();
1016+
let signers = active_request.signers.clone();
1017+
if signers.0.len() != 1 {
1018+
log::warn!("- Not enough signers");
1019+
return Ok(false);
1020+
}
1021+
let signer = signers.0.get(0).unwrap();
1022+
let signer_address = signer.signing_address.clone();
1023+
let valid_notaries = Self::fetch_notaries().await?;
1024+
if valid_notaries.is_valid(&signer_address) {
1025+
Self::issue_start_sign_dc(application_file.issue_number.clone()).await?;
1026+
Self::issue_datacap_request_signature(application_file.clone(), "proposed".to_string()).await?;
1027+
Self::update_issue_labels(application_file.issue_number.clone(), &[AppState::StartSignDatacap.as_str()]).await?;
1028+
log::info!("- Validated!");
1029+
return Ok(true);
1030+
}
1031+
log::warn!("- Not validated!");
1032+
Ok(false)
1033+
} else {
1034+
log::info!("- State is greater than StartSignDatacap");
1035+
Ok(true)
10431036
}
10441037
}
10451038
Err(e) => Err(LDNError::Load(format!(
@@ -1236,6 +1229,7 @@ Your Datacap Allocation Request has been {} by the Notary
12361229
.unwrap();
12371230
Ok(true)
12381231
}
1232+
12391233
async fn issue_start_sign_dc(issue_number: String) -> Result<bool, LDNError> {
12401234
let gh = GithubWrapper::new();
12411235
gh.add_comment_to_issue(

fplus-lib/src/parsers.rs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::str::FromStr;
22

3+
use log::info;
34
use markdown::{mdast::Node, to_mdast, ParseOptions};
45
use serde::{Deserialize, Serialize};
56

6-
use crate::core::application::file::{Client, DataType, Datacap, DatacapGroup, Project};
7+
use crate::{core::application::file::{Client, DataType, Datacap, DatacapGroup, Project}, error};
78

89
#[derive(Serialize, Deserialize, Debug)]
910
pub enum ParsedApplicationDataFields {
@@ -290,23 +291,25 @@ impl From<IssueValidData> for Datacap {
290291
format!("{}{}", datacap.total_requested_amount, value.0);
291292
}
292293
ParsedApplicationDataFields::TotalRequestedAmount => {
293-
if datacap.total_requested_amount.is_empty() {
294-
datacap.total_requested_amount = value.0.clone();
295-
} else {
296-
datacap.total_requested_amount =
297-
format!("{}{}", value.0, datacap.total_requested_amount);
294+
match value.0.parse::<f64>() {
295+
Ok(num) => datacap.total_requested_amount = format!("{}{}", num, datacap.total_requested_amount),
296+
Err(_) => {
297+
log::debug!("Failed to parse TotalRequestedAmount: {}", value.0);
298+
datacap.total_requested_amount = "0".to_string();
299+
}
298300
}
299301
}
300302
ParsedApplicationDataFields::UnitSingleSizeDataset => {
301303
datacap.single_size_dataset =
302304
format!("{}{}", datacap.single_size_dataset, value.0);
303305
}
304306
ParsedApplicationDataFields::SingleSizeDataset => {
305-
if datacap.single_size_dataset.is_empty() {
306-
datacap.single_size_dataset = value.0.clone();
307-
} else {
308-
datacap.single_size_dataset =
309-
format!("{}{}", value.0, datacap.single_size_dataset);
307+
match value.0.parse::<f64>() {
308+
Ok(num) => datacap.single_size_dataset = num.to_string(),
309+
Err(_) => {
310+
log::debug!("Failed to parse SingleSizeDataset: {}", value.0);
311+
datacap.single_size_dataset = "0".to_string();
312+
}
310313
}
311314
}
312315
ParsedApplicationDataFields::Replicas => {
@@ -316,11 +319,12 @@ impl From<IssueValidData> for Datacap {
316319
datacap.weekly_allocation = format!("{}{}", datacap.weekly_allocation, value.0);
317320
}
318321
ParsedApplicationDataFields::WeeklyAllocation => {
319-
if datacap.weekly_allocation.is_empty() {
320-
datacap.weekly_allocation = value.0.clone();
321-
} else {
322-
datacap.weekly_allocation =
323-
format!("{}{}", value.0, datacap.weekly_allocation);
322+
match value.0.parse::<f64>() {
323+
Ok(num) => datacap.weekly_allocation = num.to_string(),
324+
Err(_) => {
325+
log::debug!("Failed to parse WeeklyAllocation: {}", value.0);
326+
datacap.weekly_allocation = "0".to_string();
327+
}
324328
}
325329
}
326330
ParsedApplicationDataFields::CustomMultisig => {
@@ -332,6 +336,8 @@ impl From<IssueValidData> for Datacap {
332336
_ => {}
333337
}
334338
}
339+
log::info!("Datacap: {:?}", datacap);
340+
335341
datacap
336342
}
337343
}

0 commit comments

Comments
 (0)