Skip to content
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

[PLA-2021] MinInfusion dispatch rule #81

Merged
merged 1 commit into from
Dec 20, 2024
Merged

[PLA-2021] MinInfusion dispatch rule #81

merged 1 commit into from
Dec 20, 2024

Conversation

leonardocustodio
Copy link
Contributor

@leonardocustodio leonardocustodio commented Dec 20, 2024

PR Type

Enhancement


Description

  • Added a new MinimumInfusion case to the DispatchRule enum, enabling support for minimum infusion logic.
  • Introduced the MinimumInfusionParams class with methods for encoding, array conversion, and validation.
  • Updated DispatchRulesParams to include minimumInfusion as a parameter and handle it in relevant methods.

Changes walkthrough 📝

Relevant files
Enhancement
DispatchRule.php
Added `MinimumInfusion` case to `DispatchRule` enum.         

src/Enums/DispatchRule.php

  • Added a new MinimumInfusion case to the DispatchRule enum.
  • Included MinimumInfusionParams in the toKind method.
  • Imported MinimumInfusionParams class.
  • +3/-0     
    DispatchRulesParams.php
    Integrated `minimumInfusion` parameter in `DispatchRulesParams`.

    src/Models/Substrate/DispatchRulesParams.php

  • Added minimumInfusion as a new parameter in the constructor.
  • Updated toEncodable and toArray methods to handle minimumInfusion.
  • +9/-0     
    MinimumInfusionParams.php
    Created MinimumInfusionParams class for handling minimum infusion
    logic.

    src/Models/Substrate/MinimumInfusionParams.php

  • Introduced a new MinimumInfusionParams class.
  • Implemented methods for encoding, array conversion, and validation.
  • +45/-0   

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Validation Logic Missing

    The validate method in the MinimumInfusionParams class always returns true, which might not be sufficient for ensuring the correctness of the min parameter. Consider implementing proper validation logic.

        public function validate(string $value): bool
        {
            return true;
    Encoding and Array Conversion

    Ensure that the minimumInfusion parameter is correctly handled in both toEncodable and toArray methods, as these are critical for data serialization and deserialization.

            if ($this->minimumInfusion) {
                $params[] = $this->minimumInfusion->toEncodable();
            }
    
    
            return $params;
        }
    
        public function toArray(): array
        {
            $params = [];
    
            if ($this->whitelistedCallers) {
                $params[] = $this->whitelistedCallers->toArray();
            }
    
            if ($this->requireToken) {
                $params[] = $this->requireToken->toArray();
            }
    
            if ($this->whitelistedCollections) {
                $params[] = $this->whitelistedCollections->toArray();
            }
    
            if ($this->maxFuelBurnPerTransaction) {
                $params[] = $this->maxFuelBurnPerTransaction->toArray();
            }
    
            if ($this->userFuelBudget) {
                $params[] = $this->userFuelBudget->toArray();
            }
    
            if ($this->tankFuelBudget) {
                $params[] = $this->tankFuelBudget->toArray();
            }
    
            if ($this->whitelistedPallets) {
                $params[] = $this->whitelistedPallets->toArray();
            }
    
            if ($this->permittedCalls) {
                $params[] = $this->permittedCalls->toArray();
            }
    
            if ($this->permittedExtrinsics) {
                $params[] = $this->permittedExtrinsics->toArray();
            }
    
            if ($this->requireSignature) {
                $params[] = $this->requireSignature->toArray();
            }
    
            if ($this->minimumInfusion) {
                $params[] = $this->minimumInfusion->toArray();
            }

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add meaningful validation logic to the validate method to ensure input values meet expected criteria

    Ensure the validate method performs actual validation logic for the value parameter,
    such as checking if it meets specific format or range requirements, instead of
    always returning true.

    src/Models/Substrate/MinimumInfusionParams.php [41-44]

     public function validate(string $value): bool
     {
    -    return true;
    +    // Example validation logic: check if value is a positive integer
    +    return is_numeric($value) && $value > 0;
     }
    Suggestion importance[1-10]: 9

    Why: The suggestion addresses a critical issue where the validate method currently lacks any meaningful validation logic, which could lead to incorrect or invalid data being processed. Implementing proper validation ensures robustness and reliability of the code, making this a high-impact improvement.

    9

    @leonardocustodio leonardocustodio merged commit 6fbb1a9 into master Dec 20, 2024
    5 of 7 checks passed
    @leonardocustodio leonardocustodio deleted the PLA-2120 branch December 20, 2024 15:20
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Development

    Successfully merging this pull request may close these issues.

    2 participants