request_funds Function for Improved Efficiency and Maintainability #58
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.
Pull Request: Enhance
request_fundsFunction for Improved Efficiency and MaintainabilityIssue: #48
Description:
This pull request enhances the
request_fundsfunction by consolidating validation logic and streamlining storage updates, leading to improved gas efficiency and overall maintainability of the contract. This update reduces redundant checks and ensures consistent storage operations during fund request creation.Key Changes:
request_fundsfunction, removing external calls tocheck_owner,check_milestone, andfunds_released:project_idexists in theprojectsstorage. ThrowsERROR_INVALID_PROJECT_IDif not.ERROR_UNAUTHORIZED_REQUESTERif not.milestone_idcorresponds to a valid milestone for the project. ThrowsERROR_INVALID_MILESTONEif invalid.ERROR_MILESTONE_NOT_COMPLETEDotherwise.ERROR_FUNDS_ALREADY_RELEASEDif they have.request_fundsfunction:request_idby incrementing_fund_request_counter.FundRequeststruct populated withproject_id,milestone_id,amount(derived from the milestone'smilestone_amountand safely converted tou128),requester, andStatusset toPending.FundRequesttofund_requests(Map<(u64, u64), FundRequest>).fund_requests_countfor the project with the latest request ID.fund_request(Map<u64, (u64, u64, ContractAddress)>).milestone_funds_released(LegacyMap<(u64, u64), bool>), setting it totrue._fund_request_countercorrectly after processing the request.FundsRequestedevent containing theproject_id,request_id, andmilestone_id.check_owner,check_milestone, andfunds_released.Key Improvements:
request_fundsfunction simplifies code maintenance and reduces the risk of inconsistencies.Acceptance Criteria:
request_fundsfunction:project_idtriggersERROR_INVALID_PROJECT_ID.ERROR_UNAUTHORIZED_REQUESTER.milestonetriggersERROR_INVALID_MILESTONE.milestonetriggersERROR_MILESTONE_NOT_COMPLETED.ERROR_FUNDS_ALREADY_RELEASED.FundRequestand updates:fund_requestswith the new entry.fund_requests_countfor the given project.fund_requestmapping with the request details._fund_request_counteris incremented.milestone_funds_releasedis markedtrue.FundsRequestedevent is emitted with correct details.Technical Considerations:
milestone_amounttou128is performed safely.create_fund_requestto prevent duplicate logic and ensure consistency across the contract.