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-1931] Add dispatch with require signature #79

Merged
merged 2 commits into from
Dec 16, 2024
Merged

Conversation

leonardocustodio
Copy link
Contributor

@leonardocustodio leonardocustodio commented Dec 15, 2024

PR Type

Enhancement, Bug fix


Description

  • Introduced DispatchSettingsInputType to encapsulate dispatch settings, including paysRemainingFee and signature.
  • Enhanced DispatchMutation to support new dispatch settings and added validation rules for dispatch.settings.signature.
  • Updated RequireSignatureParams to use SS58Address::getPublicKey for encoding.
  • Renamed RequireSignatureInputType to ExpirableSignatureInputType and added an expiryBlock field.
  • Updated descriptions and field types in language files and GraphQL input types.
  • Fixed handling of requireSignature in Substrate implementation.

Changes walkthrough 📝

Relevant files
Documentation
2 files
deprecated.php
Add deprecation message for dispatch argument                       

lang/en/deprecated.php

  • Added a new deprecation message for dispatch.args.paysRemainingFee.
  • +1/-0     
    input_type.php
    Update input type descriptions for dispatch and signature

    lang/en/input_type.php

  • Updated descriptions for require_signature fields.
  • Added new descriptions for dispatch_settings and expirable_signature
    fields.
  • +8/-2     
    Enhancement
    6 files
    DispatchMutation.php
    Enhance DispatchMutation with dispatch settings and validation

    src/GraphQL/Mutations/DispatchMutation.php

  • Added support for dispatch.settings.paysRemainingFee and
    dispatch.settings.signature.
  • Added validation rules for dispatch.settings.signature.
  • Updated encoding logic to include dispatch.settings.
  • +20/-4   
    HasFuelTankValidationRules.php
    Add validation for requireSignature in fuel tank rules     

    src/GraphQL/Traits/HasFuelTankValidationRules.php

    • Added validation for requireSignature in common rules.
    +2/-0     
    DispatchInputType.php
    Add settings field to DispatchInputType                                   

    src/GraphQL/Types/Input/DispatchInputType.php

    • Added settings field to DispatchInputType.
    +4/-0     
    DispatchRuleInputType.php
    Update requireSignature field type in DispatchRuleInputType

    src/GraphQL/Types/Input/DispatchRuleInputType.php

    • Changed requireSignature field type to String.
    +1/-1     
    DispatchSettingsInputType.php
    Add DispatchSettingsInputType for dispatch settings           

    src/GraphQL/Types/Input/DispatchSettingsInputType.php

  • Added a new input type for DispatchSettings with paysRemainingFee and
    signature fields.
  • +36/-0   
    ExpirableSignatureInputType.php
    Rename and extend ExpirableSignatureInputType                       

    src/GraphQL/Types/Input/ExpirableSignatureInputType.php

  • Renamed RequireSignatureInputType to ExpirableSignatureInputType.
  • Added expiryBlock field to the input type.
  • +8/-6     
    Bug fix
    2 files
    RequireSignatureParams.php
    Update RequireSignatureParams encoding logic                         

    src/Models/Substrate/RequireSignatureParams.php

    • Updated toEncodable method to use SS58Address::getPublicKey.
    +2/-1     
    Substrate.php
    Fix handling of requireSignature in Substrate implementation

    src/Services/Blockchain/Implemetations/Substrate.php

  • Updated logic to handle requireSignature directly instead of its
    signature field.
  • +1/-1     

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

    @leonardocustodio leonardocustodio self-assigned this Dec 15, 2024
    Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

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

    Code Smell
    The addition of dispatch.settings.signature.signature and dispatch.settings.signature.expiryBlock validation rules introduces redundancy. Consider consolidating these rules to improve maintainability.

    Possible Bug
    The logic for encoding the signature and expiryBlock in getFuelTankCall may fail if dispatch.settings.signature is not properly structured. Ensure robust error handling for missing or malformed data.

    Code Smell
    The use of SS58Address::getPublicKey in toEncodable assumes that the signature is always valid. Add validation or error handling to prevent potential issues with invalid signatures.

    Code Smell
    The DispatchSettingsInputType class introduces a new input type but lacks any validation rules for its fields. Consider adding validation to ensure data integrity.

    Possible Bug
    The logic for handling requireSignature in getDispatchRulesParams may lead to incorrect behavior if the input data is not properly validated or structured.

    Copy link

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Add a check to handle empty signature values before processing them

    Ensure that the signature field is properly validated for null or empty values
    before attempting to convert it using HexConverter::hexToBytes.

    src/GraphQL/Mutations/DispatchMutation.php [149-151]

    -'signature' => $signature === null ? null : [
    +'signature' => empty($signature) ? null : [
         'signature' => HexConverter::hexToBytes($signature),
         'expiryBlock' => Arr::get($args, 'dispatch.settings.signature.expiryBlock'),
     ],
    Suggestion importance[1-10]: 9

    Why: The suggestion adds a crucial validation step to ensure that empty signature values are handled gracefully, preventing potential errors during the conversion process. This improves the robustness of the code.

    9
    Add validation for the signature property to ensure it is a valid SS58 address

    Validate that the signature property is a valid SS58 address before attempting to
    convert it using SS58Address::getPublicKey.

    src/Models/Substrate/RequireSignatureParams.php [32]

    -return ['RequireSignature' => SS58Address::getPublicKey($this->signature)];
    +return ['RequireSignature' => $this->signature && SS58Address::isValid($this->signature) ? SS58Address::getPublicKey($this->signature) : null];
    Suggestion importance[1-10]: 8

    Why: The suggestion ensures that the signature property is validated as a valid SS58 address before conversion, which is essential for maintaining data integrity and avoiding runtime errors.

    8
    General
    Add validation to ensure requireSignature is not null or empty before instantiating RequireSignatureParams

    Ensure that requireSignature is validated for null or invalid values before creating
    a RequireSignatureParams instance.

    src/Services/Blockchain/Implemetations/Substrate.php [80-82]

    -($requireSignature = Arr::get($args, 'requireSignature'))
    +($requireSignature = Arr::get($args, 'requireSignature')) && !empty($requireSignature)
         ? new RequireSignatureParams($requireSignature)
         : null,
    Suggestion importance[1-10]: 7

    Why: The suggestion improves the code by adding a check to ensure requireSignature is not null or empty, which helps prevent unnecessary instantiation of RequireSignatureParams with invalid data.

    7
    Add a validation rule to ensure requireSignature is not empty before applying address validation

    Ensure that the requireSignature field is validated for proper format and non-null
    values before applying the ValidSubstrateAddress rule.

    src/GraphQL/Traits/HasFuelTankValidationRules.php [40]

    -"{$attribute}.requireSignature" => ['nullable', new ValidSubstrateAddress()],
    +"{$attribute}.requireSignature" => ['nullable', 'filled', new ValidSubstrateAddress()],
    Suggestion importance[1-10]: 6

    Why: The suggestion enhances the validation logic by ensuring that the requireSignature field is not empty before applying the ValidSubstrateAddress rule, improving the reliability of the validation process.

    6

    Copy link
    Contributor

    @v16Studios v16Studios left a comment

    Choose a reason for hiding this comment

    The reason will be displayed to describe this comment to others. Learn more.

    Do we need to update/add any tests for this?

    @leonardocustodio
    Copy link
    Contributor Author

    done

    @leonardocustodio leonardocustodio merged commit 2d1a4cc into master Dec 16, 2024
    5 of 7 checks passed
    @leonardocustodio leonardocustodio deleted the PLA-1931 branch December 16, 2024 14:23
    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