-
Notifications
You must be signed in to change notification settings - Fork 1
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
Multiple feats #186
Merged
Merged
Multiple feats #186
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
dea3838
Feats:
AlexMCon cd05c50
checking allowance comparison
AlexMCon 9448568
fix: regex for splitting between unit and number when checking allowance
AlexMCon 0b74edf
feat: accepting more formats for amounts
AlexMCon 8f58e4a
fix: added another layer of processing amounts to correct format
AlexMCon 8d71307
chore: commented old version test
AlexMCon b60ee70
chore: changed Version type to String
AlexMCon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ use crate::{ | |
blockchain::BlockchainData, filecoin::get_multisig_threshold_for_actor, github::{ | ||
github_async_new, CreateMergeRequestData, CreateRefillMergeRequestData, GithubWrapper, | ||
} | ||
}, parsers::ParsedIssue | ||
}, helpers::{compare_allowance_and_allocation, process_amount}, parsers::ParsedIssue | ||
}; | ||
use fplus_database::database::allocation_amounts::get_allocation_quantity_options; | ||
use fplus_database::database::{ | ||
|
@@ -593,12 +593,15 @@ impl LDNApplication { | |
pub async fn new_from_issue(info: CreateApplicationInfo) -> Result<Self, LDNError> { | ||
let issue_number = info.issue_number; | ||
let gh = github_async_new(info.owner.to_string(), info.repo.to_string()).await; | ||
let (parsed_ldn, _) = LDNApplication::parse_application_issue( | ||
let (mut parsed_ldn, _) = LDNApplication::parse_application_issue( | ||
issue_number.clone(), | ||
info.owner.clone(), | ||
info.repo.clone(), | ||
) | ||
.await?; | ||
|
||
parsed_ldn.datacap.total_requested_amount = process_amount(parsed_ldn.datacap.total_requested_amount.clone()); | ||
parsed_ldn.datacap.weekly_allocation = process_amount(parsed_ldn.datacap.weekly_allocation.clone()); | ||
|
||
let application_id = parsed_ldn.id.clone(); | ||
let file_name = LDNPullRequest::application_path(&application_id); | ||
|
@@ -814,13 +817,27 @@ impl LDNApplication { | |
Ok(s) => match s { | ||
AppState::Submitted | AppState::AdditionalInfoRequired | AppState::AdditionalInfoSubmitted => { | ||
let app_file: ApplicationFile = self.file().await?; | ||
|
||
let db_allocator = match get_allocator(&owner, &repo).await { | ||
Ok(allocator) => allocator.unwrap(), | ||
Err(err) => { | ||
return Err(LDNError::New(format!("Database: get_allocator: {}", err))); | ||
} | ||
}; | ||
let db_multisig_address = db_allocator.multisig_address.unwrap(); | ||
Self::check_and_handle_allowance( | ||
&db_multisig_address.clone(), | ||
Some(allocation_amount.clone()), | ||
).await?; | ||
|
||
let uuid = uuidv4::uuid::v4(); | ||
let request = AllocationRequest::new( | ||
actor.clone(), | ||
uuid, | ||
AllocationRequestType::First, | ||
allocation_amount, | ||
); | ||
|
||
let app_file = app_file.complete_governance_review(actor.clone(), request); | ||
let file_content = serde_json::to_string_pretty(&app_file).unwrap(); | ||
let app_path = &self.file_name.clone(); | ||
|
@@ -967,6 +984,11 @@ impl LDNApplication { | |
app_lifecycle, | ||
); | ||
if new_allocation_amount.is_some() && app_file.allocation.0.len() > 1 { | ||
Self::check_and_handle_allowance( | ||
&db_multisig_address.clone(), | ||
new_allocation_amount.clone(), | ||
).await?; | ||
|
||
let _ = app_file.adjust_active_allocation_amount(new_allocation_amount.unwrap().clone()); | ||
} | ||
|
||
|
@@ -1107,7 +1129,16 @@ impl LDNApplication { | |
)); | ||
} | ||
|
||
// Check the allowance for the address | ||
|
||
if new_allocation_amount.is_some() && app_file.allocation.0.len() > 1 { | ||
let db_multisig_address = db_allocator.multisig_address.unwrap(); | ||
|
||
Self::check_and_handle_allowance( | ||
&db_multisig_address.clone(), | ||
new_allocation_amount.clone(), | ||
).await?; | ||
|
||
let _ = app_file.adjust_active_allocation_amount(new_allocation_amount.unwrap().clone()); | ||
} | ||
|
||
|
@@ -2382,7 +2413,7 @@ impl LDNApplication { | |
pub async fn update_from_issue(info: CreateApplicationInfo) -> Result<Self, LDNError> { | ||
// Get the PR number from the issue number. | ||
let issue_number = info.issue_number.clone(); | ||
let (parsed_ldn, _) = LDNApplication::parse_application_issue( | ||
let (mut parsed_ldn, _) = LDNApplication::parse_application_issue( | ||
issue_number.clone(), | ||
info.owner.clone(), | ||
info.repo.clone(), | ||
|
@@ -2412,6 +2443,9 @@ impl LDNApplication { | |
|
||
} | ||
}; | ||
|
||
parsed_ldn.datacap.total_requested_amount = process_amount(parsed_ldn.datacap.total_requested_amount.clone()); | ||
parsed_ldn.datacap.weekly_allocation = process_amount(parsed_ldn.datacap.weekly_allocation.clone()); | ||
|
||
//Application was granted. Create a new PR with the updated application file, as if it was a new application | ||
if application_model.pr_number == 0 { | ||
|
@@ -2521,6 +2555,40 @@ impl LDNApplication { | |
} | ||
} | ||
|
||
async fn check_and_handle_allowance( | ||
db_multisig_address: &str, | ||
new_allocation_amount: Option<String>, | ||
) -> Result<(), LDNError> { | ||
let blockchain = BlockchainData::new(); | ||
match blockchain.get_allowance_for_address("f24siazyti3akorqyvi33rvlq3i73j23rwohdamuy").await { | ||
Ok(allowance) if allowance != "0" => { | ||
log::info!("Allowance found and is not zero. Value is {}", allowance); | ||
match compare_allowance_and_allocation(&allowance, new_allocation_amount) { | ||
Some(result) => { | ||
if result { | ||
println!("Allowance is sufficient."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's remove prints on tagging |
||
Ok(()) | ||
} else { | ||
println!("Allowance is not sufficient."); | ||
Err(LDNError::New("Multisig address has less allowance than the new allocation amount".to_string())) | ||
} | ||
}, | ||
None => { | ||
println!("Error parsing sizes."); | ||
Err(LDNError::New("Error parsing sizes".to_string())) | ||
}, | ||
} | ||
}, | ||
Ok(_) => { | ||
Err(LDNError::New("Multisig address has no remaining allowance".to_string())) | ||
}, | ||
Err(e) => { | ||
log::error!("Failed to retrieve allowance: {:?}", e); | ||
Err(LDNError::New("Failed to retrieve allowance".to_string())) | ||
} | ||
} | ||
} | ||
|
||
pub async fn create_pr_from_issue_modification(parsed_ldn: ParsedIssue, application_model: ApplicationModel) -> Result<Self, LDNError> { | ||
let merged_application = ApplicationFile::from_str(&application_model.application.unwrap()) | ||
.map_err(|e| LDNError::Load(format!("Failed to parse application file from DB: {}", e))).unwrap(); | ||
|
@@ -3483,9 +3551,11 @@ impl LDNPullRequest { | |
)); | ||
})?; | ||
|
||
let issue_link = format!("https://github.com/{}/{}/issues/{}", owner, repo, application_id); | ||
|
||
let (_pr, file_sha) = gh | ||
.create_merge_request(CreateMergeRequestData { | ||
application_id: application_id.clone(), | ||
issue_link, | ||
branch_name: app_branch_name, | ||
file_name, | ||
owner_name, | ||
|
@@ -3526,9 +3596,12 @@ impl LDNPullRequest { | |
application_id, e | ||
)); | ||
})?; | ||
|
||
let issue_link = format!("https://github.com/{}/{}/issues/{}", owner, repo, application_id); | ||
|
||
let pr = match gh | ||
.create_refill_merge_request(CreateRefillMergeRequestData { | ||
application_id: application_id.clone(), | ||
issue_link, | ||
owner_name, | ||
file_name: file_name.clone(), | ||
file_sha: file_sha.clone(), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Leave this as it is just for testing purposes. We need to remove it when tagging into prod